Update submit metrics script so we use global and non-unique metric
names (aka don't include hostname and pid in the metric name).
@@ -157,7 +157,7 @@ def get_metrics_for_process(pid, cpu_poll_interval=0.1):
return data
-def submit_metrics_to_statsd(cpu_poll_interval=0.1):
+def submit_metrics_to_statsd(prefix=None, cpu_poll_interval=0.1):
service_pids = get_stackstorm_services_pids()
hostname = socket.gethostname()
@@ -166,7 +166,7 @@ def submit_metrics_to_statsd(cpu_poll_interval=0.1):
for service_pid in service_pids:
metrics = get_metrics_for_process(service_pid, cpu_poll_interval=cpu_poll_interval)
- LOG.debug('\nSubmitting metrics for process %s@%s\n' % (metrics['name'], hostname))
+ LOG.debug('\n\nSubmitting metrics for process %s@%s\n' % (metrics['name'], hostname))
for key in ['cpu', 'memory', 'io']:
items = metrics[key]
@@ -178,9 +178,18 @@ def submit_metrics_to_statsd(cpu_poll_interval=0.1):
# E.g. st2.st2api.1110.cpu.percentage
name = metrics['name']
- pid = metrics['pid']
- metric_key = '%s.%s.%s.%s.%s' % (name, hostname, pid, key,
- item_name)
+
+ # For example:
+ # - st2.st2api.cpu.percentage
+ # - st2.st2workflowengine.memory.rss
+ # - st2.st2workflowengine.memory.vss
+
+ # NOTE: We don't include pid in the metric name since this would
+ # result in too many unique metric names
+ if prefix:
+ metric_key = 'st2.svc.%s.%s.%s.%s' % (prefix, name, key, item_name)
+ else:
+ metric_key = 'st2.svc.%s.%s.%s' % (name, key, item_name)
gauge = statsd.Gauge(metric_key)
gauge.send(None, item_value)
@@ -193,6 +202,8 @@ def main():
help='Statsd hostname')
parser.add_argument('--statsd-port', type=int, default=8125,
help='Statsd port')
+ parser.add_argument('--prefix', type=str, default=None,
+ help='Prefix for metrics names (optional).')
parser.add_argument('--cpu-poll-interval', type=float, default=0.2,
help='Poll interval for p.cpu_percent() function. Lower means faster '
'completion but lower accuracy')
@@ -206,7 +217,7 @@ def main():
setup_logging()
# Submit metrics to statsd
- submit_metrics_to_statsd(cpu_poll_interval=args.cpu_poll_interval)
+ submit_metrics_to_statsd(prefix=args.prefix, cpu_poll_interval=args.cpu_poll_interval)
if __name__ == '__main__':
