From ab8fb20514ed0a6e5ee2030967277a17c5008363 Mon Sep 17 00:00:00 2001 From: Jeremy Pollard Date: Fri, 22 Sep 2017 14:33:13 -0700 Subject: [PATCH 1/2] Add list metrics to datadog.api.metrics --- datadog/api/metrics.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/datadog/api/metrics.py b/datadog/api/metrics.py index 12e633310..dec392c63 100644 --- a/datadog/api/metrics.py +++ b/datadog/api/metrics.py @@ -4,10 +4,10 @@ # datadog from datadog.api.exceptions import ApiError -from datadog.api.resources import SearchableAPIResource, SendableAPIResource +from datadog.api.resources import SearchableAPIResource, SendableAPIResource, ListableAPIResource -class Metric(SearchableAPIResource, SendableAPIResource): +class Metric(SearchableAPIResource, SendableAPIResource, ListableAPIResource): """ A wrapper around Metric HTTP API """ @@ -16,6 +16,7 @@ class Metric(SearchableAPIResource, SendableAPIResource): _METRIC_QUERY_ENDPOINT = '/query' _METRIC_SUBMIT_ENDPOINT = '/series' + _METRIC_LIST_ENDPOINT = '/metrics' @classmethod def _process_points(cls, points): @@ -64,6 +65,26 @@ def rec_parse(points_lst): return rec_parse(points_lst) + @classmethod + def list(cls, from_epoch): + """ + Get a list of active metrics since a given time (Unix Epoc) + + :param from_epoch: Start time in Unix Epoc (seconds) + + :returns: Dictionary containing a list of active metrics + """ + + cls._class_url = cls._METRIC_LIST_ENDPOINT + + try: + seconds = int(from_epoch) + params={'from':seconds} + except ValueError: + raise ApiError("Parameter 'from_epoch' must be an integer") + + return super(Metric, cls).get_all(**params) + @classmethod def send(cls, metrics=None, **single_metric): """ From a83aeacf1caab0d60b6276bd91a8e76af3e4f50d Mon Sep 17 00:00:00 2001 From: Jeremy Pollard Date: Fri, 22 Sep 2017 15:02:59 -0700 Subject: [PATCH 2/2] Fixed styling --- datadog/api/metrics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datadog/api/metrics.py b/datadog/api/metrics.py index dec392c63..a5345d149 100644 --- a/datadog/api/metrics.py +++ b/datadog/api/metrics.py @@ -79,7 +79,7 @@ def list(cls, from_epoch): try: seconds = int(from_epoch) - params={'from':seconds} + params = {'from': seconds} except ValueError: raise ApiError("Parameter 'from_epoch' must be an integer")