diff options
-rw-r--r-- | ceilometer/compute/notifications/cpu.py | 136 | ||||
-rw-r--r-- | ceilometer/meter/data/meters.yaml | 71 | ||||
-rw-r--r-- | ceilometer/tests/unit/compute/notifications/test_cpu.py | 157 | ||||
-rw-r--r-- | setup.cfg | 10 |
4 files changed, 71 insertions, 303 deletions
diff --git a/ceilometer/compute/notifications/cpu.py b/ceilometer/compute/notifications/cpu.py deleted file mode 100644 index 7932d2dd..00000000 --- a/ceilometer/compute/notifications/cpu.py +++ /dev/null @@ -1,136 +0,0 @@ -# -# Copyright 2013 Intel -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -"""Converters for producing compute CPU sample messages from notification -events. -""" - -from oslo_log import log -from oslo_utils import timeutils - -from ceilometer.compute import notifications -from ceilometer.i18n import _ -from ceilometer import sample - -LOG = log.getLogger(__name__) - - -class ComputeMetricsNotificationBase(notifications.ComputeNotificationBase): - """Convert compute.metrics.update notifications into Samples.""" - event_types = ['compute.metrics.update'] - metric = None - sample_type = None - unit = None - - @staticmethod - def _get_sample(message, name): - try: - for metric in message['payload']['metrics']: - if name == metric['name']: - info = {'payload': metric, - 'event_type': message['event_type'], - 'publisher_id': message['publisher_id'], - 'resource_id': '%s_%s' % ( - message['payload']['host'], - message['payload']['nodename']), - 'timestamp': str(timeutils.parse_strtime( - metric['timestamp']))} - return info - except Exception as err: - LOG.warning(_('An error occurred while building %(m)s ' - 'sample: %(e)s') % {'m': name, 'e': err}) - - def process_notification(self, message): - info = self._get_sample(message, self.metric) - if info: - yield sample.Sample.from_notification( - name='compute.node.%s' % self.metric, - type=self.sample_type, - unit=self.unit, - volume=(info['payload']['value'] * 100 if self.unit == '%' - else info['payload']['value']), - user_id=None, - project_id=None, - resource_id=info['resource_id'], - message=info) - - -class CpuFrequency(ComputeMetricsNotificationBase): - """Handle CPU current frequency message.""" - metric = 'cpu.frequency' - sample_type = sample.TYPE_GAUGE - unit = 'MHz' - - -class CpuUserTime(ComputeMetricsNotificationBase): - """Handle CPU user mode time message.""" - metric = 'cpu.user.time' - sample_type = sample.TYPE_CUMULATIVE - unit = 'ns' - - -class CpuKernelTime(ComputeMetricsNotificationBase): - """Handle CPU kernel time message.""" - metric = 'cpu.kernel.time' - unit = 'ns' - sample_type = sample.TYPE_CUMULATIVE - - -class CpuIdleTime(ComputeMetricsNotificationBase): - """Handle CPU idle time message.""" - metric = 'cpu.idle.time' - unit = 'ns' - sample_type = sample.TYPE_CUMULATIVE - - -class CpuIowaitTime(ComputeMetricsNotificationBase): - """Handle CPU I/O wait time message.""" - metric = 'cpu.iowait.time' - unit = 'ns' - sample_type = sample.TYPE_CUMULATIVE - - -class CpuKernelPercent(ComputeMetricsNotificationBase): - """Handle CPU kernel percentage message.""" - metric = 'cpu.kernel.percent' - unit = '%' - sample_type = sample.TYPE_GAUGE - - -class CpuIdlePercent(ComputeMetricsNotificationBase): - """Handle CPU idle percentage message.""" - metric = 'cpu.idle.percent' - unit = '%' - sample_type = sample.TYPE_GAUGE - - -class CpuUserPercent(ComputeMetricsNotificationBase): - """Handle CPU user mode percentage message.""" - metric = 'cpu.user.percent' - unit = '%' - sample_type = sample.TYPE_GAUGE - - -class CpuIowaitPercent(ComputeMetricsNotificationBase): - """Handle CPU I/O wait percentage message.""" - metric = 'cpu.iowait.percent' - unit = '%' - sample_type = sample.TYPE_GAUGE - - -class CpuPercent(ComputeMetricsNotificationBase): - """Handle generic CPU utilization message.""" - metric = 'cpu.percent' - unit = '%' - sample_type = sample.TYPE_GAUGE diff --git a/ceilometer/meter/data/meters.yaml b/ceilometer/meter/data/meters.yaml index 82f4aa21..a90645dd 100644 --- a/ceilometer/meter/data/meters.yaml +++ b/ceilometer/meter/data/meters.yaml @@ -133,6 +133,77 @@ metric: project_id: payload.tenant_id resource_id: payload.label_id + - name: 'compute.node.cpu.frequency' + event_type: 'compute.metrics.update' + type: 'gauge' + unit: 'MHz' + volume: payload.metrics[?(@.name='cpu.frequency')].value + resource_id: $.payload.host + "_" + $.payload.nodename + + - name: 'compute.node.cpu.user.time' + event_type: 'compute.metrics.update' + type: 'cumulative' + unit: 'ns' + volume: payload.metrics[?(@.name='cpu.user.time')].value + resource_id: $.payload.host + "_" + $.payload.nodename + + - name: 'compute.node.cpu.kernel.time' + event_type: 'compute.metrics.update' + type: 'cumulative' + unit: 'ns' + volume: payload.metrics[?(@.name='cpu.kernel.time')].value + resource_id: $.payload.host + "_" + $.payload.nodename + + - name: 'compute.node.cpu.idle.time' + event_type: 'compute.metrics.update' + type: 'cumulative' + unit: 'ns' + volume: payload.metrics[?(@.name='cpu.idle.time')].value + resource_id: $.payload.host + "_" + $.payload.nodename + + - name: 'compute.node.cpu.iowait.time' + event_type: 'compute.metrics.update' + type: 'cumulative' + unit: 'ns' + volume: payload.metrics[?(@.name='cpu.iowait.time')].value + resource_id: $.payload.host + "_" + $.payload.nodename + + - name: 'compute.node.cpu.kernel.percent' + event_type: 'compute.metrics.update' + type: 'gauge' + unit: 'percent' + volume: payload.metrics[?(@.name='cpu.kernel.percent')].value * 100 + resource_id: $.payload.host + "_" + $.payload.nodename + + - name: 'compute.node.cpu.idle.percent' + event_type: 'compute.metrics.update' + type: 'gauge' + unit: 'percent' + volume: payload.metrics[?(@.name='cpu.idle.percent')].value * 100 + resource_id: $.payload.host + "_" + $.payload.nodename + + - name: 'compute.node.cpu.user.percent' + event_type: 'compute.metrics.update' + type: 'gauge' + unit: 'percent' + volume: payload.metrics[?(@.name='cpu.user.percent')].value * 100 + resource_id: $.payload.host + "_" + $.payload.nodename + + - name: 'compute.node.cpu.iowait.percent' + event_type: 'compute.metrics.update' + type: 'gauge' + unit: 'percent' + volume: payload.metrics[?(@.name='cpu.iowait.percent')].value * 100 + resource_id: $.payload.host + "_" + $.payload.nodename + + - name: 'compute.node.cpu.percent' + event_type: 'compute.metrics.update' + type: 'gauge' + unit: 'percent' + volume: payload.metrics[?(@.name='cpu.percent')].value * 100 + resource_id: $.payload.host + "_" + $.payload.nodename + + # NOTE: non-metric meters are generally events/existence meters # These are expected to be DEPRECATED in future releases # diff --git a/ceilometer/tests/unit/compute/notifications/test_cpu.py b/ceilometer/tests/unit/compute/notifications/test_cpu.py deleted file mode 100644 index 6e3b9b67..00000000 --- a/ceilometer/tests/unit/compute/notifications/test_cpu.py +++ /dev/null @@ -1,157 +0,0 @@ -# -# Copyright 2013 Intel -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -"""Tests for converters for producing compute counter messages from -notification events. -""" - -import copy - -from oslotest import base - -from ceilometer.compute.notifications import cpu - - -METRICS_UPDATE = { - u'_context_request_id': u'req-a8bfa89b-d28b-4b95-9e4b-7d7875275650', - u'_context_quota_class': None, - u'event_type': u'compute.metrics.update', - u'_context_service_catalog': [], - u'_context_auth_token': None, - u'_context_user_id': None, - u'payload': { - 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'}, - {'timestamp': u'2013-07-29T06:51:34.472416', - 'name': 'cpu.kernel.time', 'value': 7852600000000, - 'source': 'libvirt.LibvirtDriver'}, - {'timestamp': u'2013-07-29T06:51:34.472416', - 'name': 'cpu.idle.time', 'value': 1307374400000000, - 'source': 'libvirt.LibvirtDriver'}, - {'timestamp': u'2013-07-29T06:51:34.472416', - 'name': 'cpu.iowait.time', 'value': 11697470000000, - 'source': 'libvirt.LibvirtDriver'}, - {'timestamp': u'2013-07-29T06:51:34.472416', - 'name': 'cpu.user.percent', 'value': 0.012959045637294348, - 'source': 'libvirt.LibvirtDriver'}, - {'timestamp': u'2013-07-29T06:51:34.472416', - 'name': 'cpu.kernel.percent', 'value': 0.005841204961898534, - 'source': 'libvirt.LibvirtDriver'}, - {'timestamp': u'2013-07-29T06:51:34.472416', - 'name': 'cpu.idle.percent', 'value': 0.9724985141658965, - 'source': 'libvirt.LibvirtDriver'}, - {'timestamp': u'2013-07-29T06:51:34.472416', - 'name': 'cpu.iowait.percent', 'value': 0.008701235234910634, - 'source': 'libvirt.LibvirtDriver'}, - {'timestamp': u'2013-07-29T06:51:34.472416', - 'name': 'cpu.percent', 'value': 0.027501485834103515, - 'source': 'libvirt.LibvirtDriver'}], - u'nodename': u'tianst.sh.intel.com', - u'host': u'tianst', - u'host_id': u'10.0.1.1'}, - u'priority': u'INFO', - u'_context_is_admin': True, - u'_context_user': None, - u'publisher_id': u'compute.tianst.sh.intel.com', - u'message_id': u'6eccedba-120e-4db8-9735-2ad5f061e5ee', - u'_context_remote_address': None, - u'_context_roles': [], - u'timestamp': u'2013-07-29 06:51:34.474815', - u'_context_timestamp': u'2013-07-29T06:51:34.348091', - u'_unique_id': u'0ee26117077648e18d88ac76e28a72e2', - u'_context_project_name': None, - u'_context_read_deleted': u'no', - u'_context_tenant': None, - u'_context_instance_lock_checked': False, - u'_context_project_id': None, - u'_context_user_name': None -} - -RES_ID = '%s_%s' % (METRICS_UPDATE['payload']['host'], - METRICS_UPDATE['payload']['nodename']) - - -class TestMetricsNotifications(base.BaseTestCase): - def _process_notification(self, ic): - self.assertIn(METRICS_UPDATE['event_type'], - ic.event_types) - samples = list(ic.process_notification(METRICS_UPDATE)) - self.assertEqual(RES_ID, samples[0].resource_id) - return samples[0] - - def test_compute_metrics(self): - ERROR_METRICS = copy.copy(METRICS_UPDATE) - ERROR_METRICS['payload'] = {"metric_err": []} - ic = cpu.CpuFrequency(None) - info = ic._get_sample(METRICS_UPDATE, 'cpu.frequency') - info_none = ic._get_sample(METRICS_UPDATE, 'abc.efg') - info_error = ic._get_sample(ERROR_METRICS, 'cpu.frequency') - self.assertEqual('cpu.frequency', info['payload']['name']) - self.assertIsNone(info_none) - self.assertIsNone(info_error) - - def test_compute_cpu_frequency(self): - c = self._process_notification(cpu.CpuFrequency(None)) - self.assertEqual('compute.node.cpu.frequency', c.name) - self.assertEqual(1600, c.volume) - - def test_compute_cpu_user_time(self): - c = self._process_notification(cpu.CpuUserTime(None)) - self.assertEqual('compute.node.cpu.user.time', c.name) - self.assertEqual(17421440000000, c.volume) - - def test_compute_cpu_kernel_time(self): - c = self._process_notification(cpu.CpuKernelTime(None)) - self.assertEqual('compute.node.cpu.kernel.time', c.name) - self.assertEqual(7852600000000, c.volume) - - def test_compute_cpu_idle_time(self): - c = self._process_notification(cpu.CpuIdleTime(None)) - self.assertEqual('compute.node.cpu.idle.time', c.name) - self.assertEqual(1307374400000000, c.volume) - - def test_compute_cpu_iowait_time(self): - c = self._process_notification(cpu.CpuIowaitTime(None)) - self.assertEqual('compute.node.cpu.iowait.time', c.name) - self.assertEqual(11697470000000, c.volume) - - def test_compute_cpu_kernel_percent(self): - c = self._process_notification(cpu.CpuKernelPercent(None)) - self.assertEqual('compute.node.cpu.kernel.percent', c.name) - self.assertEqual(0.5841204961898534, c.volume) - - def test_compute_cpu_idle_percent(self): - c = self._process_notification(cpu.CpuIdlePercent(None)) - self.assertEqual('compute.node.cpu.idle.percent', c.name) - self.assertEqual(97.24985141658965, c.volume) - - def test_compute_cpu_user_percent(self): - c = self._process_notification(cpu.CpuUserPercent(None)) - self.assertEqual('compute.node.cpu.user.percent', c.name) - self.assertEqual(1.2959045637294348, c.volume) - - def test_compute_cpu_iowait_percent(self): - c = self._process_notification(cpu.CpuIowaitPercent(None)) - self.assertEqual('compute.node.cpu.iowait.percent', c.name) - self.assertEqual(0.8701235234910634, c.volume) - - def test_compute_cpu_percent(self): - c = self._process_notification(cpu.CpuPercent(None)) - self.assertEqual('compute.node.cpu.percent', c.name) - self.assertEqual(2.7501485834103515, c.volume) @@ -31,16 +31,6 @@ ceilometer.notification = instance = ceilometer.compute.notifications.instance:Instance instance_delete = ceilometer.compute.notifications.instance:InstanceDelete instance_scheduled = ceilometer.compute.notifications.instance:InstanceScheduled - cpu_frequency = ceilometer.compute.notifications.cpu:CpuFrequency - cpu_user_time = ceilometer.compute.notifications.cpu:CpuUserTime - cpu_kernel_time = ceilometer.compute.notifications.cpu:CpuKernelTime - cpu_idle_time = ceilometer.compute.notifications.cpu:CpuIdleTime - cpu_iowait_time = ceilometer.compute.notifications.cpu:CpuIowaitTime - cpu_kernel_percent = ceilometer.compute.notifications.cpu:CpuKernelPercent - cpu_idle_percent = ceilometer.compute.notifications.cpu:CpuIdlePercent - cpu_user_percent = ceilometer.compute.notifications.cpu:CpuUserPercent - cpu_iowait_percent = ceilometer.compute.notifications.cpu:CpuIowaitPercent - cpu_percent = ceilometer.compute.notifications.cpu:CpuPercent network = ceilometer.network.notifications:Network subnet = ceilometer.network.notifications:Subnet port = ceilometer.network.notifications:Port |