
    9Yfa                     J    d dl mZ d dlmZ d dlmZmZmZ  G d deee      Zy)    )ApiError)format_points)SearchableAPIResourceSendableAPIResourceListableAPIResourcec                   v     e Zd ZdZdZdZdZdZe fd       Z	e
d        Zed
 fd	       Ze fd	       Z xZS )Metricz*
    A wrapper around Metric HTTP API
    Nqueryseriesmetricsc                     | j                   | _        	 t        |      }d|i}t        t        |   di |S # t        $ r t	        d      w xY w)z
        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
        fromz)Parameter 'from_epoch' must be an integer )_METRIC_LIST_ENDPOINT_resource_nameint
ValueErrorr   superr	   get_all)cls
from_epochsecondsparams	__class__s       S/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/datadog/api/metrics.pylistzMetric.list   sb     !66	H*oGg&F VS)3F33  	HFGG	Hs	   6 Ac                 6    d| v r| j                  d      | d<   yy)z
        FIXME DROPME in 1.0:

        API documentation was illegitimately promoting usage of `metric_type` parameter
        instead of `type`.
        To be consistent and avoid 'backward incompatibilities', properly rename this parameter.
        metric_typetypeN)pop)metrics    r   _rename_metric_typezMetric._rename_metric_type)   s#     F"#ZZ6F6N #    c                 X   | j                   | _        	 |r?|D ]5  }t        |t              s| j	                  |       t        |d         |d<   7 d|i}n)| j	                  |       t        |d         |d<   |g}d|i}t        t        | &  d||d|S # t        $ r t        d      w xY w)a  
        Submit a metric or a list of metrics to the metric API
        A metric dictionary should consist of 5 keys: metric, points, host, tags, type (some of which optional),
        see below:

        :param metric: the name of the time series
        :type metric: string

        :param compress_payload: compress the payload using zlib
        :type compress_payload: bool

        :param metrics: a list of dictionaries, each item being a metric to send
        :type metrics: list

        :param points: a (timestamp, value) pair or list of (timestamp, value) pairs
        :type points: list

        :param host: host name that produced the metric
        :type host: string

        :param tags:  list of tags associated with the metric.
        :type tags: string list

        :param type: type of the metric
        :type type: 'gauge' or 'count' or 'rate' string

        >>> api.Metric.send(metric='my.series', points=[(now, 15), (future_10s, 16)])

        >>> metrics = [{'metric': 'my.series', 'type': 'gauge', 'points': [(now, 15), (future_10s, 16)]},
                {'metric': 'my.series2', 'type': 'gauge', 'points': [(now, 15), (future_10s, 16)]}]
        >>> api.Metric.send(metrics=metrics)

        :returns: Dictionary representing the API's JSON response
        pointsr   z'points' parameter is required)attach_host_namecompress_payloadr   )
_METRIC_SUBMIT_ENDPOINTr   
isinstancedictr"   r   KeyErrorr   r	   send)r   r   r&   r'   single_metricr!   metrics_dictr   s          r   r,   zMetric.send5   s    J !88	=% KF!&$///7+89I+Jx(K !)'2''6*7h8O*Ph'(/ ('2
 VS& 
-@P
T`
 	
  	=;<<	=s   B AB B)c                    | j                   | _        	 |j                  d      |d<   |j                  d      |d<   t        t        | &  di |S # t        $ r,}t	        dj                  |j                  d               d}~ww xY w)	a]  
        Query metrics from Datadog

        :param start: query start timestamp
        :type start: POSIX timestamp

        :param end: query end timestamp
        :type end: POSIX timestamp

        :param query: metric query
        :type query: string query

        :returns: Dictionary representing the API's JSON response

        *start* and *end* should be less than 24 hours apart.
        It is *not* meant to retrieve metric data in bulk.

        >>> api.Metric.query(start=int(time.time()) - 3600, end=int(time.time()),
                             query='avg:system.cpu.idle{*}')
        startr   endtozThe parameter '{0}' is requiredr   Nr   )
_METRIC_QUERY_ENDPOINTr   r    r+   r   formatargsr   r	   _search)r   r   er   s      r   r
   zMetric.queryq   s    . !77
	P#ZZ0F6N!::e,F4L VS)3F33  	P<CCAFF1INOO	Ps   (A 	B'A??B)NTF)__name__
__module____qualname____doc__r   r3   r(   r   classmethodr   staticmethodr"   r,   r
   __classcell__)r   s   @r   r	   r	   
   sp     N$&%4 4& 	7 	7 9
 9
v !4 !4r#   r	   N)	datadog.api.exceptionsr   datadog.api.formatr   datadog.api.resourcesr   r   r   r	   r   r#   r   <module>rB      s(   
 , , a aI4"$79L I4r#   