From 37e8c8cc9c36428a2290b600dde4bd5d8c10acf8 Mon Sep 17 00:00:00 2001 From: Doug Szumski Date: Tue, 31 Oct 2017 11:57:03 +0000 Subject: [PATCH 1/4] Send flavor resources as value metadata This addresses an issue where the resources dimension could contain a string with prohibited characters, for example: "VCPU:64, MEMORY_MB:393216, DISK_GB:110, None". This change moves the flavor resource string to the value_meta field which has fewer restrictions over the content. If we later want to index resources as a function of the flavor resource fields, for example CPU count, we could add those as separate dimensions on the metric. --- os_capacity/commands/commands.py | 9 ++++++--- os_capacity/data/metrics.py | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/os_capacity/commands/commands.py b/os_capacity/commands/commands.py index 314d0e5..5f04d6a 100644 --- a/os_capacity/commands/commands.py +++ b/os_capacity/commands/commands.py @@ -59,13 +59,16 @@ def take_action(self, parsed_args): free = group[3] metrics_to_send.append(metrics.Metric( name="resources.total", value=total, - dimensions={"flavor": flavors, "resources": resources})) + value_meta={"flavor_resources": resources}, + dimensions={"flavor": flavors})) metrics_to_send.append(metrics.Metric( name="resources.used", value=used, - dimensions={"flavor": flavors, "resources": resources})) + value_meta={"flavor_resources": resources}, + dimensions={"flavor": flavors})) metrics_to_send.append(metrics.Metric( name="resources.free", value=free, - dimensions={"flavor": flavors, "resources": resources})) + value_meta={"flavor_resources": resources}, + dimensions={"flavor": flavors})) metrics.send_metrics(self.app.monitoring_client, metrics_to_send) return ( diff --git a/os_capacity/data/metrics.py b/os_capacity/data/metrics.py index 21f07a5..487ef1f 100644 --- a/os_capacity/data/metrics.py +++ b/os_capacity/data/metrics.py @@ -17,7 +17,7 @@ import time Metric = collections.namedtuple( - "Metric", ("name", "value", "dimensions")) + "Metric", ("name", "value", "value_meta", "dimensions")) SEND_METRICS = 'OS_CAPACITY_SEND_METRICS' in os.environ @@ -33,7 +33,7 @@ def send_metrics(monitoring_client, metrics): "name": "os_capacity.%s" % metric.name, "value": float(metric.value), "timestamp": timestamp, - "value_meta": None, + "value_meta": metric.value_meta, "dimensions": metric.dimensions, }) response = monitoring_client.post("/metrics", json=formatted_metrics) From 0cb3fafd0475d9cd06ce53595e41d89c5e04fed2 Mon Sep 17 00:00:00 2001 From: Doug Szumski Date: Tue, 31 Oct 2017 13:49:40 +0000 Subject: [PATCH 2/4] rebase: Specify value_meta for usage summary Move the usage summary from a dimension to the value_meta for the same reasons as the flavor resources. --- cron/example.sh | 0 os_capacity/utils.py | 4 +++- 2 files changed, 3 insertions(+), 1 deletion(-) mode change 100644 => 100755 cron/example.sh diff --git a/cron/example.sh b/cron/example.sh old mode 100644 new mode 100755 diff --git a/os_capacity/utils.py b/os_capacity/utils.py index b2d2fcb..f36e329 100644 --- a/os_capacity/utils.py +++ b/os_capacity/utils.py @@ -241,16 +241,18 @@ def get_key(allocation): if key_name: dimensions[name_key] = key_name - dimensions['usage_summary'] = usage + value_meta = {'usage_summary': usage} dimensions['version'] = 2.0 metrics_to_send.append(metrics.Metric( name="usage.%s.count" % group_by, value=grouped_usage['Count'], + value_meta=value_meta, dimensions=dimensions)) metrics_to_send.append(metrics.Metric( name="usage.%s.days.count" % group_by, value=grouped_usage_days['Count'], + value_meta=value_meta, dimensions=dimensions)) # Sort my largest current usage first From b3b11f941ceb2767605c8386ba855279eb673d21 Mon Sep 17 00:00:00 2001 From: Doug Szumski Date: Tue, 31 Oct 2017 14:15:35 +0000 Subject: [PATCH 3/4] Fix bug where dimension value is not a string This caused the Monasca API to reject the metric. --- os_capacity/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/os_capacity/utils.py b/os_capacity/utils.py index f36e329..216f3f7 100644 --- a/os_capacity/utils.py +++ b/os_capacity/utils.py @@ -242,7 +242,7 @@ def get_key(allocation): if key_name: dimensions[name_key] = key_name value_meta = {'usage_summary': usage} - dimensions['version'] = 2.0 + dimensions['version'] = '2.0' metrics_to_send.append(metrics.Metric( name="usage.%s.count" % group_by, From b468e928701134a77303061d7c789d6d0a5d5b0a Mon Sep 17 00:00:00 2001 From: Doug Szumski Date: Wed, 1 Nov 2017 09:38:42 +0000 Subject: [PATCH 4/4] Update metric name in grafana dashboard This should fix the servers per user and number of servers days per user graphs so that they work out of the box. --- cron/grafana_dashboard.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cron/grafana_dashboard.json b/cron/grafana_dashboard.json index d47d95a..75fd35a 100644 --- a/cron/grafana_dashboard.json +++ b/cron/grafana_dashboard.json @@ -407,7 +407,7 @@ "error": "", "group": true, "hide": false, - "metric": "os_capacity.usage.count", + "metric": "os_capacity.usage.user.count", "period": "300", "refId": "A" } @@ -502,7 +502,7 @@ ], "error": "", "group": true, - "metric": "os_capacity.usage.days.count", + "metric": "os_capacity.usage.user.days.count", "period": "300", "refId": "A" }