From 12c9668c67ce3927708f555ff9e443ac5307fc4e Mon Sep 17 00:00:00 2001 From: gordon chung Date: Thu, 27 Aug 2015 16:41:12 -0400 Subject: [PATCH] fix metadata for compute cpu notifications currently,the cpu notifications has extremely verbose metadata which is list of all metrics in message. ie, each meter has metadata like: u'metrics': [ {'timestamp': u'2013-07-29T06:51:34.472416', 'name': 'cpu.frequency', 'value': 1600, 'source': 'libvirt.LibvirtDriver'}, ... {'timestamp': u'2013-07-29T06:51:34.472416', 'name': 'cpu.user.time', 'value': 17421440000000, 'source': 'libvirt.LibvirtDriver'}], ... } the original metadata pre-declarative notifications is: {'timestamp': u'2013-07-29T06:51:34.472416', 'name': 'cpu.frequency', 'value': 1600, 'source': 'libvirt.LibvirtDriver', 'event_type': 'compute.metrics.update', 'host': } the proposed metadata removes all data already included in meter: {'source': 'libvirt.LibvirtDriver', 'event_type': 'compute.metrics.update', 'host': } Change-Id: I2c8d4ba7768cba378b931acbfe84a29549da7f8b --- ceilometer/meter/data/meters.yaml | 50 +++++++++++++++++++ .../tests/unit/meter/test_notifications.py | 19 +++++++ 2 files changed, 69 insertions(+) diff --git a/ceilometer/meter/data/meters.yaml b/ceilometer/meter/data/meters.yaml index cd6e97cc..16f3bcb2 100644 --- a/ceilometer/meter/data/meters.yaml +++ b/ceilometer/meter/data/meters.yaml @@ -139,6 +139,11 @@ metric: unit: 'MHz' volume: $.payload.metrics[?(@.name='cpu.frequency')].value resource_id: $.payload.host + "_" + $.payload.nodename + timestamp: $.payload.metrics[?(@.name='cpu.frequency')].timestamp + metadata: + event_type: $.event_type + host: $.publisher_id + source: $.payload.metrics[?(@.name='cpu.frequency')].source - name: 'compute.node.cpu.user.time' event_type: 'compute.metrics.update' @@ -146,6 +151,11 @@ metric: unit: 'ns' volume: $.payload.metrics[?(@.name='cpu.user.time')].value resource_id: $.payload.host + "_" + $.payload.nodename + timestamp: $.payload.metrics[?(@.name='cpu.user.time')].timestamp + metadata: + event_type: $.event_type + host: $.publisher_id + source: $.payload.metrics[?(@.name='cpu.user.time')].source - name: 'compute.node.cpu.kernel.time' event_type: 'compute.metrics.update' @@ -153,6 +163,11 @@ metric: unit: 'ns' volume: $.payload.metrics[?(@.name='cpu.kernel.time')].value resource_id: $.payload.host + "_" + $.payload.nodename + timestamp: $.payload.metrics[?(@.name='cpu.kernel.time')].timestamp + metadata: + event_type: $.event_type + host: $.publisher_id + source: $.payload.metrics[?(@.name='cpu.kernel.time')].source - name: 'compute.node.cpu.idle.time' event_type: 'compute.metrics.update' @@ -160,6 +175,11 @@ metric: unit: 'ns' volume: $.payload.metrics[?(@.name='cpu.idle.time')].value resource_id: $.payload.host + "_" + $.payload.nodename + timestamp: $.payload.metrics[?(@.name='cpu.idle.time')].timestamp + metadata: + event_type: $.event_type + host: $.publisher_id + source: $.payload.metrics[?(@.name='cpu.idle.time')].source - name: 'compute.node.cpu.iowait.time' event_type: 'compute.metrics.update' @@ -167,6 +187,11 @@ metric: unit: 'ns' volume: $.payload.metrics[?(@.name='cpu.iowait.time')].value resource_id: $.payload.host + "_" + $.payload.nodename + timestamp: $.payload.metrics[?(@.name='cpu.iowait.time')].timestamp + metadata: + event_type: $.event_type + host: $.publisher_id + source: $.payload.metrics[?(@.name='cpu.iowait.time')].source - name: 'compute.node.cpu.kernel.percent' event_type: 'compute.metrics.update' @@ -174,6 +199,11 @@ metric: unit: 'percent' volume: $.payload.metrics[?(@.name='cpu.kernel.percent')].value * 100 resource_id: $.payload.host + "_" + $.payload.nodename + timestamp: $.payload.metrics[?(@.name='cpu.kernel.percent')].timestamp + metadata: + event_type: $.event_type + host: $.publisher_id + source: $.payload.metrics[?(@.name='cpu.kernel.percent')].source - name: 'compute.node.cpu.idle.percent' event_type: 'compute.metrics.update' @@ -181,6 +211,11 @@ metric: unit: 'percent' volume: $.payload.metrics[?(@.name='cpu.idle.percent')].value * 100 resource_id: $.payload.host + "_" + $.payload.nodename + timestamp: $.payload.metrics[?(@.name='cpu.idle.percent')].timestamp + metadata: + event_type: $.event_type + host: $.publisher_id + source: $.payload.metrics[?(@.name='cpu.idle.percent')].source - name: 'compute.node.cpu.user.percent' event_type: 'compute.metrics.update' @@ -188,6 +223,11 @@ metric: unit: 'percent' volume: $.payload.metrics[?(@.name='cpu.user.percent')].value * 100 resource_id: $.payload.host + "_" + $.payload.nodename + timestamp: $.payload.metrics[?(@.name='cpu.user.percent')].timestamp + metadata: + event_type: $.event_type + host: $.publisher_id + source: $.payload.metrics[?(@.name='cpu.user.percent')].source - name: 'compute.node.cpu.iowait.percent' event_type: 'compute.metrics.update' @@ -195,6 +235,11 @@ metric: unit: 'percent' volume: $.payload.metrics[?(@.name='cpu.iowait.percent')].value * 100 resource_id: $.payload.host + "_" + $.payload.nodename + timestamp: $.payload.metrics[?(@.name='cpu.iowait.percent')].timestamp + metadata: + event_type: $.event_type + host: $.publisher_id + source: $.payload.metrics[?(@.name='cpu.iowait.percent')].source - name: 'compute.node.cpu.percent' event_type: 'compute.metrics.update' @@ -202,6 +247,11 @@ metric: unit: 'percent' volume: $.payload.metrics[?(@.name='cpu.percent')].value * 100 resource_id: $.payload.host + "_" + $.payload.nodename + timestamp: $.payload.metrics[?(@.name='cpu.percent')].timestamp + metadata: + event_type: $.event_type + host: $.publisher_id + source: $.payload.metrics[?(@.name='cpu.percent')].source # NOTE: non-metric meters are generally events/existence meters diff --git a/ceilometer/tests/unit/meter/test_notifications.py b/ceilometer/tests/unit/meter/test_notifications.py index 52a74a3c..0ba6c644 100644 --- a/ceilometer/tests/unit/meter/test_notifications.py +++ b/ceilometer/tests/unit/meter/test_notifications.py @@ -385,6 +385,25 @@ class TestMeterProcessing(test.BaseTestCase): self.assertEqual(MIDDLEWARE_EVENT['payload']['eventTime'], s1['timestamp']) + def test_custom_timestamp_expr_meter(self): + cfg = yaml.dump( + {'metric': [dict(name='compute.node.cpu.frequency', + event_type="compute.metrics.update", + type='gauge', + unit="ns", + volume="$.payload.metrics[?(@.name='cpu.frequency')]" + ".value", + resource_id="'prefix-' + $.payload.nodename", + timestamp="$.payload.metrics" + "[?(@.name='cpu.frequency')].timestamp")]}) + self.handler.definitions = notifications.load_definitions( + self.__setup_meter_def_file(cfg)) + c = list(self.handler.process_notification(METRICS_UPDATE)) + self.assertEqual(1, len(c)) + s1 = c[0].as_dict() + self.assertEqual('compute.node.cpu.frequency', s1['name']) + self.assertEqual("2013-07-29T06:51:34.472416", s1['timestamp']) + def test_default_metadata(self): cfg = yaml.dump( {'metric': [dict(name="test1",