diff --git a/datadog/api/metrics.py b/datadog/api/metrics.py index 12e633310..a5345d149 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): """