
    $e<                     x   d dl Z d dlmZmZmZmZmZmZ ddlm	Z	m
Z
mZ dZ e j                  d      Z e j                  d      Z e j                  d      Z G d	 d
      Z G d de      ZeZ G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zy)    N)DictListOptionalSequenceTupleUnion   )ExemplarSample	Timestamp)countergaugesummary	histogramgaugehistogramunknowninfostatesetz^[a-zA-Z_:][a-zA-Z0-9_:]*$z^[a-zA-Z_][a-zA-Z0-9_]*$z^__.*$c                       e Zd ZdZddedededefdZddedeeef   d	ed
ee	e
ef      dee   ddfdZdedefdZdefdZd Zy)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                    |r|j                  d|z         s|d|z   z  }t        j                  |      st        d|z         || _        || _        || _        |dk(  rd}|t        vrt        d|z         || _        g | _	        y )N_zInvalid metric name: untypedr   zInvalid metric type: )
endswithMETRIC_NAME_REmatch
ValueErrorr   r   r   METRIC_TYPEStypesamples)selfr   r   r   r   s        @/usr/lib/python3/dist-packages/prometheus_client/metrics_core.py__init__zMetric.__init__   s    cDj1C$JD##D)4t;<<	"/	)Cl"4s:;;	%'    Nlabelsvalue	timestampexemplarreturnc           	      T    | j                   j                  t        |||||             y)z?Add a sample to the metric.

        Internal-only, do not use.N)r$   appendr   )r%   r   r)   r*   r+   r,   s         r&   
add_samplezMetric.add_sample'   s#     	F4	8LMr(   otherc                 0   t        |t              xr | j                  |j                  k(  xrj | j                  |j                  k(  xrO | j                  |j                  k(  xr4 | j
                  |j
                  k(  xr | j                  |j                  k(  S N)
isinstancer   r   r   r#   r   r$   )r%   r1   s     r&   __eq__zMetric.__eq__-   s    5&) 2II+2&&%*=*==2 II+2 II+	2
 LLEMM1	3r(   c                     dj                  | j                  | j                  | j                  | j                  | j
                        S )NzMetric({}, {}, {}, {}, {}))formatr   r   r#   r   r$   )r%   s    r&   __repr__zMetric.__repr__5   s:    +22IIIIIILL
 	
r(   c                     | j                   D cg c]  }|d   |v s| }}|r4t        | j                  | j                  | j                        }||_         |S yc c}w )zMBuild a snapshot of a metric with samples restricted to a given set of names.r   N)r$   r   r   r   r#   )r%   namessr$   ms        r&   _restricted_metriczMetric._restricted_metric>   sV    "ll<adem1<<tyy$"4"4dii@AAIH =s
   AA) NN)__name__
__module____qualname____doc__strr'   r   floatr   r   r   r
   r0   objectboolr5   r8   r=    r(   r&   r   r      s    (S ( (3 (c (Ns NDcN N5 NU]^cdmotdt^uUv N  JR  S[  J\ N  hl N3F 3t 3
# 
r(   r   c                   v    e Zd ZdZ	 	 	 ddededee   deee      def
dZddee   ded	ee	e
ef      d
dfdZy)UnknownMetricFamilyzOA single unknown metric and its samples.
    For use by custom collectors.
    Nr   r   r*   r)   r   c                     t         j                  | ||d|       ||t        d      |g }t        |      | _        || j                  g |       y y )Nr   1Can only specify at most one of value and labels.r   r'   r!   tuple_labelnames
add_metricr%   r   r   r*   r)   r   s         r&   r'   zUnknownMetricFamily.__init__M   s^     	dM9dC%"3PQQ>F =OOB& r(   r+   r-   c                     | j                   j                  t        | j                  t	        t        | j                  |            ||             y)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ziprO   r%   r)   r*   r+   s       r&   rP   zUnknownMetricFamily.add_metric]   s9     	F499d3t7G7G3P.QSXZcder(   NNr>   r3   r@   rA   rB   rC   rD   r   rE   r   r'   r   r   rP   rH   r(   r&   rJ   rJ   H   s     +/37'' #' !' "(3-0	'
 ' f# fu fRWXachXhRiIj fvz fr(   rJ   c                       e Zd ZdZ	 	 	 	 ddededee   deee      dee   defd	Z	 	 ddee   dedee   d
ee	e
ef      ddf
dZy)CounterMetricFamilyzIA single counter and its samples.

    For use by custom collectors.
    Nr   r   r*   r)   createdr   c                     |j                  d      r|d d }t        j                  | ||d|       ||t        d      |g }t	        |      | _        || j                  g ||       y y )N_totalir   rL   )r   r   r'   r!   rN   rO   rP   )r%   r   r   r*   r)   r[   r   s          r&   r'   zCounterMetricFamily.__init__p   sw     =="9DdM9dC%"3PQQ>F =OOBw/ r(   r+   r-   c                 N   | j                   j                  t        | j                  dz   t	        t        | j                  |            ||             |R| j                   j                  t        | j                  dz   t	        t        | j                  |            ||             yy)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.
        r]   N_createdrS   )r%   r)   r*   r[   r+   s        r&   rP   zCounterMetricFamily.add_metric   s     	F499x#7c$BRBRTZ>[9\^cenopLLtyy:'=tCHXHXZ`Da?bdkmv wx r(   NNNr>   r?   rX   rH   r(   r&   rZ   rZ   j   s     +/37,000 #0 !0 "(3-0	0
 #5/0 0. /3BF	y#C=yy %UOy 'uY-='>?	y
 yr(   rZ   c                   v    e Zd ZdZ	 	 	 ddededee   deee      def
dZddee   ded	ee	e
ef      d
dfdZy)GaugeMetricFamilyzGA single gauge and its samples.

    For use by custom collectors.
    Nr   r   r*   r)   r   c                     t         j                  | ||d|       ||t        d      |g }t        |      | _        || j                  g |       y y )Nr   rL   rM   rQ   s         r&   r'   zGaugeMetricFamily.__init__   s^     	dM7DA%"3PQQ>F =OOB& r(   r+   r-   c                     | j                   j                  t        | j                  t	        t        | j                  |            ||             y)z|Add a metric to the metric family.

        Args:
          labels: A list of label values
          value: A float
        NrS   rV   s       r&   rP   zGaugeMetricFamily.add_metric   s9     	F499d3t7G7G3P.QSXZcder(   rW   r3   rX   rH   r(   r&   rb   rb      s     +/37'' #' !' "(3-0	'
 ' f# fu fRWXachXhRiIj fvz fr(   rb   c                       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	Z		 ddee   deded
ee
eef      ddf
dZy)SummaryMetricFamilyzIA single summary and its samples.

    For use by custom collectors.
    Nr   r   count_value	sum_valuer)   r   c                     t         j                  | ||d|       |d u |d u k7  rt        d      ||t        d      |g }t        |      | _        ||| j                  g ||       y y y )Nr   z4count_value and sum_value must be provided together.rL   rM   )r%   r   r   rg   rh   r)   r   s          r&   r'   zSummaryMetricFamily.__init__   s     	dM9dC;$#67STT+"9PQQ>F ="y'<OOBY7 (="r(   r+   r-   c                 H   | j                   j                  t        | j                  dz   t	        t        | j                  |            ||             | j                   j                  t        | j                  dz   t	        t        | j                  |            ||             y)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_sumNrS   )r%   r)   rg   rh   r+   s        r&   rP   zSummaryMetricFamily.add_metric   sz     	F499x#7c$BRBRTZ>[9\^iktuvF499v#5tC@P@PRX<Y7Z\egpqrr(   r`   r3   )r@   rA   rB   rC   rD   r   intrE   r   r'   r   r   rP   rH   r(   r&   rf   rf      s     /3.23788 #8 'sm8 %UO	8
 "(3-08 82 8<s#C=s #s $s
 E%"234s sr(   rf   c                       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	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Zy)HistogramMetricFamilyzKA single histogram and its samples.

    For use by custom collectors.
    Nr   r   bucketsrh   r)   r   c                     t         j                  | ||d|       ||t        d      ||t        d      |g }t        |      | _        || j                  g ||       y y )Nr   z-sum value cannot be provided without buckets.3Can only specify at most one of buckets and labels.rM   )r%   r   r   rp   rh   r)   r   s          r&   r'   zHistogramMetricFamily.__init__   sv     	dM;E W_LMM'"5RSS>F =OOB3 r(   r+   r-   c                    |D ]  }|dd \  }}d}t        |      dk(  r|d   }| j                  j                  t        | j                  dz   t        t        t        | j                  |            d|fgz         |||              t        |d   d         dk\  r|| j                  j                  t        | j                  dz   t        t        | j                  |            |d   d	   |             | j                  j                  t        | j                  d
z   t        t        | j                  |            ||             yyy)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   rk   r	   rl   )
lenr$   r/   r   r   rT   listrU   rO   rE   )	r%   r)   rp   rh   r+   bbucketr*   r,   s	            r&   rP   z HistogramMetricFamily.add_metric   s;     	AbqEMFEH1v{Q4LL		I%T#d..78T6N;KKL! 	 A1$)>LLtyy8+T#d6F6F2O-PRYZ\R]^_R`bklnLLtyy6)4D4D4Df0M+NPY[deg	 *?$r(   r`   r3   )r@   rA   rB   rC   rD   r   r   r   r   rE   r
   r'   r   rP   rH   r(   r&   ro   ro      s
    gk.23744 #4 #8E%U
2CU3PUW_K_E`2`,a#bc4 %UO	4
 "(3-04 4. CG	!g#C=!g$U5e+<eCPXDX>Y+Y%Z[!g 'uo!g 'uY-='>?	!g LP	!gr(   ro   c                       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	Z		 ddee   deeeef      dee   d
ee
eef      ddf
dZy)GaugeHistogramMetricFamilyzQA single gauge histogram and its samples.

    For use by custom collectors.
    Nr   r   rp   
gsum_valuer)   r   c                     t         j                  | ||d|       ||t        d      |g }t        |      | _        || j                  g ||       y y )Nr   rr   rM   )r%   r   r   rp   r   r)   r   s          r&   r'   z#GaugeHistogramMetricFamily.__init__&  sa     	dM3CTJ'"5RSS>F =OOB4 r(   r+   r-   c                    |D ]e  \  }}| j                   j                  t        | j                  dz   t	        t        t        | j                  |            d|fgz         ||             g | j                   j                  t        | j                  dz   t	        t        | j                  |            |d   d   |      t        | j                  dz   t	        t        | j                  |            ||      g       y)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.
        rv   rw   _gcountrx   r	   _gsumN)	r$   r/   r   r   rT   rz   rU   rO   extend)r%   r)   rp   r   r+   r|   r*   s          r&   rP   z%GaugeHistogramMetricFamily.add_metric7  s     % 	#MFELL		I%T#d..78T6N;KKLy!" #	# 	499y($s43C3CV/L*MwWY{[\~_hi499w&S1A1A6-J(KZYbc
 	r(   r`   r3   )r@   rA   rB   rC   rD   r   r   r   rE   r'   r   r   rP   rH   r(   r&   r~   r~      s     CG/33755 #5 #8E#u*,=#>?5 &e_	5
 "(3-05 5* CG	#C=$U3:%67  ( 'uUI-='>?	
 r(   r~   c                       e Zd ZdZ	 	 ddededeeeef      deee      fdZ	 ddee   deeef   dee	e
ef      d	dfd
Zy)InfoMetricFamilyzFA single info and its samples.

    For use by custom collectors.
    Nr   r   r*   r)   c                     t         j                  | ||d       ||t        d      |g }t        |      | _        || j                  g |       y y )Nr   rL   rM   r%   r   r   r*   r)   s        r&   r'   zInfoMetricFamily.__init__X  s\     	dM6:%"3PQQ>F =OOB& r(   r+   r-   c                     | j                   j                  t        | j                  dz   t	        t	        t        | j                  |            fi |d|             y)zAdd a metric to the metric family.

        Args:
          labels: A list of label values
          value: A dict of labels
        _infor	   NrS   rV   s       r&   rP   zInfoMetricFamily.add_metricg  sN     	FIIc$**F34>>	
 	r(   r?   r3   )r@   rA   rB   rC   rD   r   r   r   r'   r   r   rE   rP   rH   r(   r&   r   r   R  s     4837	'' #' !c3h0' "(3-0	'$ CG#C=sCx. 'uY-='>? 	r(   r   c                       e Zd ZdZ	 	 ddededeeeef      deee      fdZ		 ddee   deeef   dee
eef      d	dfd
Zy)StateSetMetricFamilyzJA single stateset and its samples.

    For use by custom collectors.
    Nr   r   r*   r)   c                     t         j                  | ||d       ||t        d      |g }t        |      | _        || j                  g |       y y )Nr   rL   rM   r   s        r&   r'   zStateSetMetricFamily.__init__  s\     	dM:>%"3PQQ>F =OOB& r(   r+   r-   c                 (   t        |      }t        |j                               D ]k  \  }}|rdnd}| j                  j	                  t        | j                  t        t        | j                  | j                  fz   ||fz               ||             m y)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)
rN   sorteditemsr$   r/   r   r   rT   rU   rO   )r%   r)   r*   r+   stateenabledvs          r&   rP   zStateSetMetricFamily.add_metric  s     v$U[[]3 	NE71ALL		S))TYYL8&E8:KLM	! 	r(   r?   r3   )r@   rA   rB   rC   rD   r   r   rG   r   r'   r   r   rE   rP   rH   r(   r&   r   r   z  s     5937	'' #' !c4i1' "(3-0	'$ CG#C=sDy/ 'uY-='>? 	r(   r   )retypingr   r   r   r   r   r   r$   r
   r   r   r"   compiler   METRIC_LABEL_NAME_RERESERVED_METRIC_LABEL_NAME_REr   rJ   UntypedMetricFamilyrZ   rb   rf   ro   r~   r   r   rH   r(   r&   <module>r      s    	 ? ? 0 0 9:!rzz"=>  *

9 5 6 6rf& f> * )y& )yXf f@)s& )sX:gF :g|/ /d%v %P(6 (r(   