o
    :Di<                     @   s   d dl mZmZmZmZmZmZ ddlmZm	Z	m
Z
mZ ddlmZ dZG dd dZG dd	 d	eZeZG d
d deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZdS )    )DictListOptionalSequenceTupleUnion   )ExemplarNativeHistogramSample	Timestamp)_validate_metric_name)countergaugesummary	histogramgaugehistogramunknowninfostatesetc                   @   s   e Zd ZdZddedededefddZdded
eeef dedee	e
ef  dee dee dd	fddZdedefddZdefddZdd Zd	S )MetriczA single metric family and its samples.

    This is intended only for internal use by the instrumentation client.

    Custom collectors should use GaugeMetricFamily, CounterMetricFamily
    and SummaryMetricFamily instead.
     namedocumentationtypunitc                 C   sh   |r| d| s|d| 7 }t| || _|| _|| _|dkr"d}|tvr,td| || _g | _d S )N_untypedr   zInvalid metric type: )	endswithr   r   r   r   METRIC_TYPES
ValueErrortypesamples)selfr   r   r   r    r$   W/var/www/Datamplify/venv/lib/python3.10/site-packages/prometheus_client/metrics_core.py__init__   s   
zMetric.__init__Nlabelsvalue	timestampexemplarnative_histogramreturnc              	   C   s   | j t|||||| dS )z?Add a sample to the metric.

        Internal-only, do not use.N)r"   appendr   )r#   r   r'   r(   r)   r*   r+   r$   r$   r%   
add_sample#   s   zMetric.add_sampleotherc                 C   sF   t |to"| j|jko"| j|jko"| j|jko"| j|jko"| j|jkS N)
isinstancer   r   r   r!   r   r"   )r#   r/   r$   r$   r%   __eq__)   s   





zMetric.__eq__c                 C   s   d | j| j| j| j| jS )NzMetric({}, {}, {}, {}, {}))formatr   r   r!   r   r"   )r#   r$   r$   r%   __repr__1   s   zMetric.__repr__c                    s8    fdd| j D }|rt| j| j| j}||_ |S dS )zMBuild a snapshot of a metric with samples restricted to a given set of names.c                    s   g | ]
}|d   v r|qS )r   r$   ).0snamesr$   r%   
<listcomp><   s    z-Metric._restricted_metric.<locals>.<listcomp>N)r"   r   r   r   r!   )r#   r8   r"   mr$   r7   r%   _restricted_metric:   s   zMetric._restricted_metric)r   NNN)__name__
__module____qualname____doc__strr&   r   floatr   r   r   r	   r
   r.   objectboolr2   r4   r;   r$   r$   r$   r%   r      s    D	r   c                   @   n   e Zd ZdZ			ddededee deee  def
d	d
Zddee dedee	e
ef  ddfddZdS )UnknownMetricFamilyzOA single unknown metric and its samples.
    For use by custom collectors.
    Nr   r   r   r(   r'   r   c                 C   \   t | ||d| |d ur|d urtd|d u rg }t|| _|d ur,| g | d S d S )Nr   1Can only specify at most one of value and labels.r   r&   r    tuple_labelnames
add_metricr#   r   r   r(   r'   r   r$   r$   r%   r&   I      
zUnknownMetricFamily.__init__r)   r,   c                 C   (   | j t| jtt| j||| dS )zAdd a metric to the metric family.
        Args:
        labels: A list of label values
        value: The value of the metric.
        Nr"   r-   r   r   dictziprK   r#   r'   r(   r)   r$   r$   r%   rL   Y   s   (zUnknownMetricFamily.add_metricNNr   r0   r=   r>   r?   r@   rA   r   rB   r   r&   r   r   rL   r$   r$   r$   r%   rF   D   s"    

0rF   c                   @   s   e Zd ZdZ					ddededee deee  dee d	ed
ee fddZ				ddee dedee dee
eef  d
ee ddfddZdS )CounterMetricFamilyzIA single counter and its samples.

    For use by custom collectors.
    Nr   r   r   r(   r'   createdr   r*   c                 C   sx   | dr|d d }t| ||d| |d ur |d ur td|d u r&g }t|| _|d ur:| jg |||d d S d S )N_totalir   rH   )r*   )r   r   r&   r    rJ   rK   rL   )r#   r   r   r(   r'   rW   r   r*   r$   r$   r%   r&   l   s   


zCounterMetricFamily.__init__r)   r,   c                 C   sb   | j t| jd tt| j|||| |dur/| j t| jd tt| j||| dS dS )zAdd a metric to the metric family.

        Args:
          labels: A list of label values
          value: The value of the metric
          created: Optional unix timestamp the child was created at.
        rX   N_createdrP   )r#   r'   r(   rW   r)   r*   r$   r$   r%   rL      s   *,zCounterMetricFamily.add_metric)NNNr   Nr<   )r=   r>   r?   r@   rA   r   rB   r   r	   r&   r   r   rL   r$   r$   r$   r%   rV   f   sL    

rV   c                   @   rE   )GaugeMetricFamilyzGA single gauge and its samples.

    For use by custom collectors.
    Nr   r   r   r(   r'   r   c                 C   rG   )Nr   rH   rI   rM   r$   r$   r%   r&      rN   zGaugeMetricFamily.__init__r)   r,   c                 C   rO   )z|Add a metric to the metric family.

        Args:
          labels: A list of label values
          value: A float
        NrP   rS   r$   r$   r%   rL      s   (zGaugeMetricFamily.add_metricrT   r0   rU   r$   r$   r$   r%   rZ      s"    

0rZ   c                   @   s~   e Zd ZdZ				ddededee dee deee  d	efd
dZ		ddee dededee
eef  ddf
ddZdS )SummaryMetricFamilyzIA single summary and its samples.

    For use by custom collectors.
    Nr   r   r   count_value	sum_valuer'   r   c                 C   s   t | ||d| |d u |d u krtd|d ur!|d ur!td|d u r'g }t|| _|d ur=|d ur?| g || d S d S d S )Nr   z4count_value and sum_value must be provided together.rH   rI   )r#   r   r   r\   r]   r'   r   r$   r$   r%   r&      s   
zSummaryMetricFamily.__init__r)   r,   c                 C   sT   | j t| jd tt| j||| | j t| jd tt| j||| dS )zAdd a metric to the metric family.

        Args:
          labels: A list of label values
          count_value: The count value of the metric.
          sum_value: The sum value of the metric.
        _count_sumNrP   )r#   r'   r\   r]   r)   r$   r$   r%   rL      s   (,zSummaryMetricFamily.add_metricNNNr   r0   )r=   r>   r?   r@   rA   r   intrB   r   r&   r   r   rL   r$   r$   r$   r%   r[      s>    

r[   c                   @   s   e Zd ZdZ				ddededeeeeee	f eee	e
f f   dee	 deee  d	efd
dZ	ddee deeeee	f eee	e
f f  dee	 deeee	f  ddf
ddZdS )HistogramMetricFamilyzKA single histogram and its samples.

    For use by custom collectors.
    Nr   r   r   bucketsr]   r'   r   c                 C   sv   t | ||d| |d ur|d u rtd|d ur!|d ur!td|d u r'g }t|| _|d ur9| g || d S d S )Nr   z-sum value cannot be provided without buckets.3Can only specify at most one of buckets and labels.rI   )r#   r   r   rc   r]   r'   r   r$   r$   r%   r&      s   
zHistogramMetricFamily.__init__r)   r,   c           	   
   C   s   |D ]2}|dd \}}d}t |dkr|d }| jt| jd ttt| j|d|fg ||| qt	|d d dkrq|durs| jt| jd tt| j||d d	 | | jt| jd
 tt| j||| dS dS dS )az  Add a metric to the metric family.

        Args:
          labels: A list of label values
          buckets: A list of lists.
              Each inner list can be a pair of bucket name and value,
              or a triple of bucket name, value, and exemplar.
              The buckets must be sorted, and +Inf present.
          sum_value: The sum value of the metric.
        N      _bucketler   r^   r   r_   )
lenr"   r-   r   r   rQ   listrR   rK   rB   )	r#   r'   rc   r]   r)   bbucketr(   r*   r$   r$   r%   rL      s(   &z HistogramMetricFamily.add_metricr`   r0   )r=   r>   r?   r@   rA   r   r   r   r   rB   r	   r&   r   rL   r$   r$   r$   r%   rb      s>    $

 rb   c                   @   s   e Zd ZdZ				ddededeeeeef   dee deee  d	efd
dZ		ddee deeeef  dee dee
eef  ddf
ddZdS )GaugeHistogramMetricFamilyzQA single gauge histogram and its samples.

    For use by custom collectors.
    Nr   r   r   rc   
gsum_valuer'   r   c                 C   s^   t | ||d| |d ur|d urtd|d u rg }t|| _|d ur-| g || d S d S )Nr   rd   rI   )r#   r   r   rc   ro   r'   r   r$   r$   r%   r&   #  s   
z#GaugeHistogramMetricFamily.__init__r)   r,   c              
   C   s   |D ]\}}| j t| jd ttt| j|d|fg || q| j t| jd tt| j||d d |t| jd tt| j|||g dS )a  Add a metric to the metric family.

        Args:
          labels: A list of label values
          buckets: A list of pairs of bucket names and values.
              The buckets must be sorted, and +Inf present.
          gsum_value: The sum value of the metric.
        rg   rh   _gcountri   r   _gsumN)	r"   r-   r   r   rQ   rk   rR   rK   extend)r#   r'   rc   ro   r)   rm   r(   r$   r$   r%   rL   4  s   &
z%GaugeHistogramMetricFamily.add_metricr`   r0   )r=   r>   r?   r@   rA   r   r   r   rB   r&   r   r   rL   r$   r$   r$   r%   rn     s>    

rn   c                   @   sz   e Zd ZdZ		ddededeeeef  deee  fddZ	ddee deeef d	ee	e
ef  d
dfddZdS )InfoMetricFamilyzFA single info and its samples.

    For use by custom collectors.
    Nr   r   r(   r'   c                 C   Z   t | ||d |d ur|d urtd|d u rg }t|| _|d ur+| g | d S d S )Nr   rH   rI   r#   r   r   r(   r'   r$   r$   r%   r&   U     
zInfoMetricFamily.__init__r)   r,   c              	   C   s8   | j t| jd ttt| j|fi |d| dS )zAdd a metric to the metric family.

        Args:
          labels: A list of label values
          value: A dict of labels
        _infor   NrP   rS   r$   r$   r%   rL   d  s   
zInfoMetricFamily.add_metricNNr0   )r=   r>   r?   r@   rA   r   r   r   r&   r   r   rB   rL   r$   r$   r$   r%   rs   O  .    


rs   c                   @   sz   e Zd ZdZ		ddededeeeef  deee  fddZ		ddee deeef d	ee
eef  d
dfddZdS )StateSetMetricFamilyzJA single stateset and its samples.

    For use by custom collectors.
    Nr   r   r(   r'   c                 C   rt   )Nr   rH   rI   ru   r$   r$   r%   r&   }  rv   zStateSetMetricFamily.__init__r)   r,   c              
   C   s`   t |}t| D ]#\}}|rdnd}| jt| jtt| j	| jf ||f || q
dS )zAdd a metric to the metric family.

        Args:
          labels: A list of label values
          value: A dict of string state names to booleans
        r   r   N)
rJ   sorteditemsr"   r-   r   r   rQ   rR   rK   )r#   r'   r(   r)   stateenabledvr$   r$   r%   rL     s   zStateSetMetricFamily.add_metricrx   r0   )r=   r>   r?   r@   rA   r   r   rD   r   r&   r   r   rB   rL   r$   r$   r$   r%   rz   w  ry   rz   N)typingr   r   r   r   r   r   r"   r	   r
   r   r   
validationr   r   r   rF   UntypedMetricFamilyrV   rZ   r[   rb   rn   rs   rz   r$   r$   r$   r%   <module>   s     8. ,=2(