diff options
author | gordon chung <gord@live.ca> | 2015-08-20 17:22:50 -0400 |
---|---|---|
committer | gordon chung <gord@live.ca> | 2015-08-27 16:12:51 -0400 |
commit | d836f8f54a712ba1ad793e393a7eaef0c8cf6024 (patch) | |
tree | 0d76b334ffcb93d3cdc75ed2c1f30e97339784be /ceilometer/meter | |
parent | e8929f3e18a5124b305838b564478c988fe0958e (diff) | |
download | ceilometer-d836f8f54a712ba1ad793e393a7eaef0c8cf6024.tar.gz |
support custom metadata
this patch allows us to define metadata rather than blindly capturing
entire payload.
Change-Id: Id445f7f6d1231f8fdfddb43389783142190db662
Diffstat (limited to 'ceilometer/meter')
-rw-r--r-- | ceilometer/meter/notifications.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/ceilometer/meter/notifications.py b/ceilometer/meter/notifications.py index 8fd08258..6f033125 100644 --- a/ceilometer/meter/notifications.py +++ b/ceilometer/meter/notifications.py @@ -76,6 +76,13 @@ class MeterDefinition(object): continue elif isinstance(field, six.integer_types): self._field_getter[name] = field + elif isinstance(field, dict) and name == 'metadata': + meta = {} + for key, val in field.items(): + parts = self.parse_jsonpath(val) + meta[key] = functools.partial(self._parse_jsonpath_field, + parts) + self._field_getter['metadata'] = meta else: parts = self.parse_jsonpath(field) self._field_getter[name] = functools.partial( @@ -100,6 +107,11 @@ class MeterDefinition(object): getter = self._field_getter.get(field) if not getter: return + elif isinstance(getter, dict): + dict_val = {} + for key, val in getter.items(): + dict_val[key] = val(message, all_values) + return dict_val elif callable(getter): return getter(message, all_values) else: @@ -232,6 +244,7 @@ class ProcessMeterNotifications(plugin_base.NotificationBase): projectid = self.get_project_id(d, notification_body) resourceid = d.parse_fields('resource_id', notification_body) ts = d.parse_fields('timestamp', notification_body) + metadata = d.parse_fields('metadata', notification_body) if d.cfg.get('lookup'): meters = d.parse_fields('name', notification_body, True) if not meters: # skip if no meters in payload @@ -265,7 +278,8 @@ class ProcessMeterNotifications(plugin_base.NotificationBase): yield sample.Sample.from_notification( name=m, type=t, unit=unit, volume=v, resource_id=r, user_id=user, project_id=p, - message=notification_body, timestamp=ts) + message=notification_body, timestamp=ts, + metadata=metadata) else: yield sample.Sample.from_notification( name=d.cfg['name'], @@ -276,7 +290,7 @@ class ProcessMeterNotifications(plugin_base.NotificationBase): user_id=userid, project_id=projectid, message=notification_body, - timestamp=ts) + timestamp=ts, metadata=metadata) @staticmethod def get_user_id(d, notification_body): |