heat engine : Add show_watch_metric RPC action

Adds show_watch_metric, which allow alarm/watch
metric data to be retrieved from the engine

Change-Id: Ie69691dbf781016e6262bbbabbe57f9c3396a5d5
Signed-off-by: Steven Hardy <shardy@redhat.com>
This commit is contained in:
Steven Hardy 2012-08-22 14:11:52 +01:00
parent a7f4e34e57
commit 00527198c8
3 changed files with 71 additions and 0 deletions

View File

@ -252,3 +252,35 @@ def format_watch(watch):
}
return result
WATCH_DATA_KEYS = (
WATCH_DATA_ALARM, WATCH_DATA_METRIC, WATCH_DATA_TIME,
WATCH_DATA_NAMESPACE, WATCH_DATA
) = (
'watch_name', 'metric_name', 'timestamp',
'namespace', 'data')
def format_watch_data(wd):
# Demangle DB format data into something more easily used in the API
# We are expecting a dict with exactly two items, Namespace and
# a metric key
namespace = wd.data['Namespace']
metric = [(k, v) for k, v in wd.data.items() if k != 'Namespace']
if len(metric) == 1:
metric_name, metric_data = metric[0]
else:
logger.error("Unexpected number of keys in watch_data.data!")
return
result = {
WATCH_DATA_ALARM: wd.watch_rule.name,
WATCH_DATA_METRIC: metric_name,
WATCH_DATA_TIME: heat_utils.strtime(wd.created_at),
WATCH_DATA_NAMESPACE: namespace,
WATCH_DATA: metric_data
}
return result

View File

@ -502,3 +502,27 @@ class EngineManager(manager.Manager):
result = [api.format_watch(w) for w in wrs]
return result
def show_watch_metric(self, context, namespace=None, metric_name=None):
'''
The show_watch method returns the datapoints for a metric
arg1 -> RPC context.
arg2 -> Name of the namespace you want to see, or None to see all
arg3 -> Name of the metric you want to see, or None to see all
'''
# DB API and schema does not yet allow us to easily query by
# namespace/metric, but we will want this at some point
# for now, the API can query all metric data and filter locally
if namespace != None or metric_name != None:
logger.error("Filtering by namespace/metric not yet supported")
return
try:
wds = db_api.watch_data_get_all(context)
except Exception as ex:
logger.warn('show_metric (all) db error %s' % str(ex))
return
result = [api.format_watch_data(w) for w in wds]
return result

View File

@ -232,3 +232,18 @@ class EngineAPI(heat.openstack.common.rpc.proxy.RpcProxy):
return self.call(ctxt, self.make_msg('show_watch',
watch_name=watch_name),
topic=_engine_topic(self.topic, ctxt, None))
def show_watch_metric(self, ctxt, namespace=None, metric_name=None):
"""
The show_watch_metric method returns the datapoints associated
with a specified metric, or all metrics if no metric_name is passed
:param ctxt: RPC context.
:param namespace: Name of the namespace you want to see,
or None to see all
:param metric_name: Name of the metric you want to see,
or None to see all
"""
return self.call(ctxt, self.make_msg('show_watch_metric',
namespace=namespace, metric_name=metric_name),
topic=_engine_topic(self.topic, ctxt, None))