|
| 1 | +# datadog |
| 2 | +from datadog.api.resources import GetableAPIResource, UpdatableAPIResource |
| 3 | + |
| 4 | + |
| 5 | +class Metadata(GetableAPIResource, UpdatableAPIResource): |
| 6 | + """ |
| 7 | + A wrapper around Metric Metadata HTTP API |
| 8 | + """ |
| 9 | + _class_url = '/metrics' |
| 10 | + _json_name = 'metrics' |
| 11 | + |
| 12 | + @classmethod |
| 13 | + def get(cls, metric_name): |
| 14 | + """ |
| 15 | + Get metadata information on an existing Datadog metric |
| 16 | +
|
| 17 | + param metric_name: metric name (ex. system.cpu.idle) |
| 18 | +
|
| 19 | + :returns: JSON response from HTTP request |
| 20 | + """ |
| 21 | + if not metric_name: |
| 22 | + raise KeyError("'metric_name' parameter is required") |
| 23 | + |
| 24 | + return super(Metadata, cls).get(metric_name) |
| 25 | + |
| 26 | + @classmethod |
| 27 | + def update(cls, metric_name, **params): |
| 28 | + """ |
| 29 | + Update metadata fields for an existing Datadog metric. |
| 30 | + If the metadata does not exist for the metric it is created by |
| 31 | + the update. |
| 32 | +
|
| 33 | + :param type: type of metric (ex. "gauge", "rate", etc.) |
| 34 | + see http://docs.datadoghq.com/metrictypes/ |
| 35 | + :type type: string |
| 36 | +
|
| 37 | + :param description: description of the metric |
| 38 | + :type description: string |
| 39 | +
|
| 40 | + :param short_name: short name of the metric |
| 41 | + :type short_name: string |
| 42 | +
|
| 43 | + :param unit: unit type associated with the metric (ex. "byte", "operation") |
| 44 | + see http://docs.datadoghq.com/units/ for full list |
| 45 | + :type unit: string |
| 46 | +
|
| 47 | + :param per_unit: per unit type (ex. "second" as in "queries per second") |
| 48 | + see http://docs.datadoghq.com/units/ for full list |
| 49 | + :type per_unit: string |
| 50 | +
|
| 51 | + :param statsd_interval: statsd flush interval for metric in seconds (if applicable) |
| 52 | + :type statsd_interval: integer |
| 53 | +
|
| 54 | + :return: JSON response from HTTP request |
| 55 | +
|
| 56 | + >>> api.Metadata.update(metric_name='api.requests.served', metric_type="counter") |
| 57 | + """ |
| 58 | + if not metric_name: |
| 59 | + raise KeyError("'metric_name' parameter is required") |
| 60 | + |
| 61 | + return super(Metadata, cls).update(id=metric_name, **params) |
0 commit comments