
    Xh<                        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      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)    )DictListOptionalSequenceTupleUnion   )ExemplarNativeHistogramSample	Timestamp)_validate_metric_name)countergaugesummary	histogramgaugehistogramunknowninfostatesetc                       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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        |       || _        || _        || _        |dk(  rd}|t
        vrt        d|z         || _        g | _        y )N_untypedr   zInvalid metric type: )	endswithr   r   r   r   METRIC_TYPES
ValueErrortypesamples)selfr   r   r   r   s        R/var/www/html/myenv/lib/python3.12/site-packages/prometheus_client/metrics_core.py__init__zMetric.__init__   st    cDj1C$JDd#	"/	)Cl"4s:;;	%'    Nlabelsvalue	timestampexemplarnative_histogramreturnc           
      V    | 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,   r-   s          r&   
add_samplezMetric.add_sample#   s&     	F4	8M]^_r(   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%   r2   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__1   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) NNN)__name__
__module____qualname____doc__strr'   r   floatr   r   r   r
   r   r1   objectboolr6   r9   r>    r(   r&   r   r      s    (S ( (3 (c (`s `DcN `5 `U]^cdmotdt^uUv `  JR  S[  J\ `  w  @O  wP `  \` `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__I   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$   r0   r   r   dictziprP   r%   r)   r*   r+   s       r&   rQ   zUnknownMetricFamily.add_metricY   s9     	F499d3t7G7G3P.QSXZcder(   NNr?   r4   rA   rB   rC   rD   rE   r   rF   r   r'   r   r   rQ   rI   r(   r&   rK   rK   D   s     +/37'' #' !' "(3-0	'
 ' f# fu fRWXachXhRiIj fvz fr(   rK   c                       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
Z		 	 	 ddee   dedee   dee
eef      d	ee   ddfdZy)CounterMetricFamilyzIA single counter and its samples.

    For use by custom collectors.
    Nr   r   r*   r)   createdr   r,   c                     |j                  d      r|d d }t        j                  | ||d|       ||t        d      |g }t	        |      | _        || j                  g |||       y y )N_totalir   rM   )r,   )r    r   r'   r"   rO   rP   rQ   )r%   r   r   r*   r)   r\   r   r,   s           r&   r'   zCounterMetricFamily.__init__l   s{     =="9DdM9dC%"3PQQ>F =OOBwOB r(   r+   r.   c                 P   | 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_createdrT   )r%   r)   r*   r\   r+   r,   s         r&   rQ   zCounterMetricFamily.add_metric   s     	F499x#7c$BRBRTZ>[9\^cenpxyzLLtyy:'=tCHXHXZ`Da?bdkmv wx r(   )NNNr?   Nr@   )rA   rB   rC   rD   rE   r   rF   r   r
   r'   r   r   rQ   rI   r(   r&   r[   r[   f   s     +/37,004CC #C !C "(3-0	C
 #5/C C $H-C0 /3BF26y#C=yy %UOy 'uY-='>?	y
 &h/y y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)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   rM   rN   rR   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
        NrT   rW   s       r&   rQ   zGaugeMetricFamily.add_metric   s9     	F499d3t7G7G3P.QSXZcder(   rX   r4   rY   rI   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.rM   rN   )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_sumNrT   )r%   r)   rg   rh   r+   s        r&   rQ   zSummaryMetricFamily.add_metric   sz     	F499x#7c$BRBRTZ>[9\^iktuvF499v#5tC@P@PRX<Y7Z\egpqrr(   NNNr?   r4   )rA   rB   rC   rD   rE   r   intrF   r   r'   r   r   rQ   rI   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.rN   )r%   r   r   rq   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$   r0   r   r   rU   listrV   rP   rF   )	r%   r)   rq   rh   r+   bbucketr*   r,   s	            r&   rQ   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(   rm   r4   )rA   rB   rC   rD   rE   r   r   r   r   rF   r
   r'   r   rQ   rI   r(   r&   rp   rp      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(   rp   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   rq   
gsum_valuer)   r   c                     t         j                  | ||d|       ||t        d      |g }t        |      | _        || j                  g ||       y y )Nr   rs   rN   )r%   r   r   rq   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.
        rw   rx   _gcountry   r	   _gsumN)	r$   r0   r   r   rU   r{   rV   rP   extend)r%   r)   rq   r   r+   r}   r*   s          r&   rQ   z%GaugeHistogramMetricFamily.add_metric4  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(   rm   r4   )rA   rB   rC   rD   rE   r   r   r   rF   r'   r   r   rQ   rI   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   rM   rN   r%   r   r   r*   r)   s        r&   r'   zInfoMetricFamily.__init__U  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	   NrT   rW   s       r&   rQ   zInfoMetricFamily.add_metricd  sN     	FIIc$**F34>>	
 	r(   NNr4   )rA   rB   rC   rD   rE   r   r   r   r'   r   r   rF   rQ   rI   r(   r&   r   r   O  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   rM   rN   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)
rO   sorteditemsr$   r0   r   r   rU   rV   rP   )r%   r)   r*   r+   stateenabledvs          r&   rQ   zStateSetMetricFamily.add_metric  s     v$U[[]3 	NE71ALL		S))TYYL8&E8:KLM	! 	r(   r   r4   )rA   rB   rC   rD   rE   r   r   rH   r   r'   r   r   rF   rQ   rI   r(   r&   r   r   w  s     5937	'' #' !c4i1' "(3-0	'$ CG#C=sDy/ 'uY-='>? 	r(   r   N)typingr   r   r   r   r   r   r$   r
   r   r   r   
validationr   r!   r   rK   UntypedMetricFamilyr[   rb   rf   rp   r   r   r   rI   r(   r&   <module>r      s    ? ? A A -5 5pf& f> * +y& +y\f f@)s& )sX:gF :gz/ /d%v %P(6 (r(   