From dcce2c7323c0e8c9426604bc15a7e8f6ee70b86d Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 19 Jul 2012 17:01:34 +0200 Subject: [PATCH] Fix and document counter types Document each counter type available and fixes the various counter already implemented. This fixes bug #1023969. Change-Id: Ibc8b726d59c3f9433109096958b1d40db043e70d Signed-off-by: Julien Danjou --- ceilometer/compute/libvirt.py | 2 +- ceilometer/compute/network.py | 2 +- ceilometer/compute/notifications.py | 2 +- ceilometer/counter.py | 17 ++++++++++++++++- doc/source/contributing/plugins.rst | 2 +- tests/compute/test_notifications.py | 2 +- 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/ceilometer/compute/libvirt.py b/ceilometer/compute/libvirt.py index c23a9f26a9..4d940b2961 100644 --- a/ceilometer/compute/libvirt.py +++ b/ceilometer/compute/libvirt.py @@ -120,7 +120,7 @@ class CPUPollster(plugin.PollsterBase): ) yield make_counter_from_instance(instance, name='instance', - type='delta', + type='cumulative', volume=1, ) except Exception as err: diff --git a/ceilometer/compute/network.py b/ceilometer/compute/network.py index 1818bbf58e..a59b8b8bbe 100644 --- a/ceilometer/compute/network.py +++ b/ceilometer/compute/network.py @@ -39,7 +39,7 @@ class FloatingIPPollster(plugin.PollsterBase): yield counter.Counter( source='?', name='floating_ip', - type='delta', + type='cumulative', volume=1, user_id=None, project_id=ip.project_id, diff --git a/ceilometer/compute/notifications.py b/ceilometer/compute/notifications.py index 7cebca1bf8..6afb8b0add 100644 --- a/ceilometer/compute/notifications.py +++ b/ceilometer/compute/notifications.py @@ -39,7 +39,7 @@ class InstanceNotifications(plugin.NotificationBase): return [counter.Counter( source='?', name='instance', - type='delta', + type='cumulative', volume=1, user_id=message['payload']['user_id'], project_id=message['payload']['tenant_id'], diff --git a/ceilometer/counter.py b/ceilometer/counter.py index c8e736f0a9..26fe6fbafd 100644 --- a/ceilometer/counter.py +++ b/ceilometer/counter.py @@ -24,7 +24,22 @@ in by the plugins that create them. import collections - +# Fields explanation: +# +# Source: +# Name: the name of the counter, must be unique +# Type: the type of the counter, must be either: +# - cumulative: the value is incremented and never reset to 0 +# - delta: the value is reset to 0 each time it is sent +# - absolute: the value is an absolute value and is not a counter +# Volume: the counter value +# User ID: the user ID +# Project ID: the project ID +# Resource ID: the resource ID +# Timestamp: when the counter has been read +# Duration: duration in seconds determining how long the value is valid. +# adding this to timestamp give the end time of the counter +# Resource metadata: various metadata Counter = collections.namedtuple('Counter', ' '.join(['source', 'name', diff --git a/doc/source/contributing/plugins.rst b/doc/source/contributing/plugins.rst index edf54b6ffa..238353a8fd 100644 --- a/doc/source/contributing/plugins.rst +++ b/doc/source/contributing/plugins.rst @@ -64,7 +64,7 @@ from libvirt and send back two ``Counter`` objects. The first one, named "cpu", is of type "cumulative", meaning that between two polls, its value is not reset, or in other word that the cpu value is always provided as a duration that continuously increases since the creation of the instance. The second one, -named "instance", is of type "delta", meaning that it's value is just the +named "instance", is of type "cumulative", meaning that it's value is just the volume since the last poll. Here, the instance counter is only used as a way to tell the system that the instance is still running, hence the hard coded value of 1. diff --git a/tests/compute/test_notifications.py b/tests/compute/test_notifications.py index e03425b39a..c9c958f10b 100644 --- a/tests/compute/test_notifications.py +++ b/tests/compute/test_notifications.py @@ -172,7 +172,7 @@ def test_process_notification(): for name, actual, expected in [ ('counter_name', info.name, 'instance'), - ('counter_type', info.type, 'delta'), + ('counter_type', info.type, 'cumulative'), ('counter_volume', info.volume, 1), ('timestamp', info.timestamp, INSTANCE_CREATE_END['timestamp']),