
    Mh`k                        d dl Z d dlmZ d dlZd dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZ d dlZddlmZ ddlmZmZmZ ddlmZ ddlmZmZmZ dd	lm Z m!Z! dd
l"m#Z#m$Z$ ddl%m&Z&m'Z'm(Z(  edd          Z) ededef                   Z*d Z+de,fdZ- e-            a.d Z/d Z0 G d de          Z1 G d de1          Z2 G d de1          Z3 G d de1          Z4 G d de1          Z5 G d d e1          Z6 G d! d"e1          Z7dS )#    N)Lock)AnyCallableDictIterableListLiteralOptionalSequenceTupleTypeTypeVarUnion   )values)ExceptionCounterInprogressTrackerTimer)Metric)	CollectorCollectorRegistryREGISTRY)ExemplarSample)floatToGoStringINF)_validate_exemplar_validate_labelnames_validate_metric_nameTMetricWrapperBase)boundF.c                    |st          d          d}|r||dz   z  }|r||dz   z  }||z  }| dk    r|                    d          r
|d d         }|r |                    d|z             s|d|z   z  }|r| dv rt          d|z             |S )	NzMetric name should not be empty _counter_totali)infostatesetz2Metric name is of a type that cannot have a unit: )
ValueErrorendswith)metric_typename	namespace	subsystemunit	full_names         Y/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/prometheus_client/metrics.py_build_full_namer4      s     <:;;;I %Y_$	 %Y_$	IiI$6$6x$@$@crcN	  I&&sTz22  S4Z	 [333MPYYZZZ    returnc                  j    t           j                            dd                                          dvS )N!PROMETHEUS_DISABLE_CREATED_SERIESFalse)true1t)osenvirongetlower r5   r3   _get_use_createdrB   ,   s+    :>>=wGGMMOOWiiir5   c                  
    da dS )zJDisable exporting _created metrics on counters, histograms, and summaries.FN_use_createdrA   r5   r3   disable_created_metricsrF   3   s     LLLr5   c                  
    da dS )zIEnable exporting _created metrics on counters, histograms, and summaries.TNrD   rA   r5   r3   enable_created_metricsrH   9   s     LLLr5   c                      e Zd ZU dZee         ed<   dZee         ed<   d Z	d Z
d Zd Zd	ee         fd
Zd	ee         fdZd	efdZd	efdZddddedfdedededee         dedededee         deee                  d	dfdZdededed	efdZded	dfdZd"dZd	ee         fdZd	ee         fdZd	ee         fd Zd! ZdS )#r!   N_typerA   _reserved_labelnamesc                 .    | j          p| j         o| j        S N_labelnames_labelvaluesselfs    r3   _is_observablez MetricWrapperBase._is_observableC   s      ##O(8(NT=NOr5   c                 v    |                                  s$t          dt          | j                  z            d S )Nz!%s metric is missing label values)rS   r+   strrJ   rQ   s    r3   _raise_if_not_observablez*MetricWrapperBase._raise_if_not_observableI   sA     ""$$ 	T@3tz??RSSS	T 	Tr5   c                      | j         o| j         S rM   rN   rQ   s    r3   
_is_parentzMetricWrapperBase._is_parentP   s    9(9$99r5   c                 N    t          | j        | j        | j        | j                  S rM   )r   _name_documentationrJ   _unitrQ   s    r3   _get_metriczMetricWrapperBase._get_metricS   s    dj$"5tz4:NNNr5   r6   c                 ,    |                                  gS rM   )r]   rQ   s    r3   describezMetricWrapperBase.describeV   s      ""##r5   c           	          |                                  }|                                 D ]+\  }}}}}}|                    | j        |z   |||||           ,|gS rM   )r]   _samples
add_samplerZ   )rR   metricsuffixlabelsvalue	timestampexemplarnative_histogram_values           r3   collectzMetricWrapperBase.collectY   sn    !!##RVR_R_RaRa 	o 	oNFFE9h8Ndj6165)XWmnnnnxr5   c                 $    | j          d| j         S )N:)rJ   rZ   rQ   s    r3   __str__zMetricWrapperBase.__str___   s    *++tz+++r5   c                 T    t          |           }|j         d|j         d| j         dS )N.())type
__module____name__rZ   )rR   r-   s     r3   __repr__zMetricWrapperBase.__repr__b   s4    4jj(OO;+?OO$*OOOOr5   r%   rR   r.   documentation
labelnamesr/   r0   r1   registryrP   c	                    t          | j        ||||          | _        t          | |          | _        t          |pd          | _        i | _        || _        || _	        t          | j                   |                                 rt                      | _        i | _        |                                 r|                                  | j        s|r|                    |            d S d S d S )NrA   )r4   rJ   rZ   r   rO   tuplerP   _kwargsr[   r\   r   rX   r   _lock_metricsrS   _metric_initregister)	rR   r.   rv   rw   r/   r0   r1   rx   rP   s	            r3   __init__zMetricWrapperBase.__init__f   s     &dj$	9dSS
/jAA!,"4"55')+
dj)))?? 	7DJ46DM   	   	( (!!$'''''	( 	(( (r5   labelvalueslabelkwargsc                    | j         st          d| z            | j        rHt          d                    | t	          t          | j         | j                                                |rrt          d          rUt                    t          | j                   k    rt          d          t          fd| j         D                       }nMt          |          t          | j                   k    rt          d          t          d |D                       }| j	        5  || j
        vr4 | j        | j        f| j        | j         | j        |d| j        | j
        |<   | j
        |         cd	d	d	           S # 1 swxY w Y   d	S )
ar  Return the child for the given labelset.

        All metrics can have labels, allowing grouping of related time series.
        Taking a counter as an example:

            from prometheus_client import Counter

            c = Counter('my_requests_total', 'HTTP Failures', ['method', 'endpoint'])
            c.labels('get', '/').inc()
            c.labels('post', '/submit').inc()

        Labels can also be provided as keyword arguments:

            from prometheus_client import Counter

            c = Counter('my_requests_total', 'HTTP Failures', ['method', 'endpoint'])
            c.labels(method='get', endpoint='/').inc()
            c.labels(method='post', endpoint='/submit').inc()

        See the best practices on [naming](http://prometheus.io/docs/practices/naming/)
        and [labels](http://prometheus.io/docs/practices/instrumentation/#use-labels).
        ,No label names were set when constructing %sz@{} already has labels set ({}); can not chain calls to .labels()z"Can't pass both *args and **kwargszIncorrect label namesc              3   B   K   | ]}t          |                   V  d S rM   rU   ).0lr   s     r3   	<genexpr>z+MetricWrapperBase.labels.<locals>.<genexpr>   s/      NNKN 3 3NNNNNNr5   zIncorrect label countc              3   4   K   | ]}t          |          V  d S rM   r   r   r   s     r3   r   z+MetricWrapperBase.labels.<locals>.<genexpr>   s(      <<1A<<<<<<r5   )rv   rw   r1   rP   N)rO   r+   rP   formatdictzipsortedrz   lenr|   r}   	__class__rZ   r[   r\   r{   )rR   r   r   s     `r3   re   zMetricWrapperBase.labels   s   .  	TKdRSSS 	_ffS)4+<==>>    
  	C; 	CABBB 	=k""fT-=&>&>>> !8999NNNNT=MNNNNNKK;3t'7#8#888 !8999<<<<<<<KZ 
	. 
	.$-//-;T^J."&"5#/!,. . l. .k* =-
	. 
	. 
	. 
	. 
	. 
	. 
	. 
	. 
	. 
	. 
	. 
	. 
	. 
	. 
	. 
	. 
	. 
	.s   (A
E??FFc                    dt           j        v sdt           j        v rt          j        dt                     | j        st          d| z            	 t          |          t          | j                  k    r&t          dt          | j                  |fz            t          d |D                       }| j	        5  || j
        v r| j
        |= d d d            d S # 1 swxY w Y   d S )Nprometheus_multiproc_dirPROMETHEUS_MULTIPROC_DIRzFRemoval of labels has not been implemented in  multi-process mode yet.r   z+Incorrect label count (expected %d, got %s)c              3   4   K   | ]}t          |          V  d S rM   r   r   s     r3   r   z+MetricWrapperBase.remove.<locals>.<genexpr>   s(      88qCFF888888r5   )r=   r>   warningswarnUserWarningrO   r+   r   rz   r|   r}   )rR   r   s     r3   removezMetricWrapperBase.remove   s@   %337QUWU_7_7_MX    	TKdRSSS8{s4#34444JcRVRbNcNcepMqqrrr88K88888Z 	/ 	/dm++M+.	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s   <CC"Cc                     dt           j        v sdt           j        v rt          j        dt                     | j        5  i | _        ddd           dS # 1 swxY w Y   dS )z$Remove all labelsets from the metricr   r   zBClearing labels has not been implemented in multi-process mode yetN)r=   r>   r   r   r   r|   r}   rQ   s    r3   clearzMetricWrapperBase.clear   s    %337QUWU_7_7_MT   Z 	 	DM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAc                 z    |                                  r|                                 S |                                 S rM   )rX   _multi_samples_child_samplesrQ   s    r3   ra   zMetricWrapperBase._samples   s8    ?? 	)&&(((&&(((r5   c              #     K   | j         5  | j                                        }d d d            n# 1 swxY w Y   |                                D ]\  }}t	          t          | j        |                    }|                                D ]N\  }}}}}	}
t          |t          |t	          |                                          z             |||	|
          V  Od S rM   )
r|   r}   copyitemslistr   rO   ra   r   r   )rR   metricsre   rc   series_labelsrd   sample_labelsrf   rg   rh   ri   s              r3   r   z MetricWrapperBase._multi_samples   sF     Z 	+ 	+m((**G	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+%mmoo 	L 	LNFF T%5v!>!>??M]c]l]l]n]n L LYuiCYVT-$}?R?R?T?T:U:U*U%V%VX]_hjr  uK  L  L  L  L  L  LL	L 	Ls   044c                 &    t          d| z            )Nz*_child_samples() must be implemented by %rNotImplementedErrorrQ   s    r3   r   z MetricWrapperBase._child_samples   s    !"NQU"UVVVr5   c                 &    t          d| z            )z
        Initialize the metric object as a child, i.e. when it has labels (if any) set.

        This is factored as a separate function to allow for deferred initialization.
        z(_metric_init() must be implemented by %rr   rQ   s    r3   r~   zMetricWrapperBase._metric_init   s     ""Lt"STTTr5   r6   N) rt   rs   __qualname__rJ   r
   rU   __annotations__rK   r   rS   rV   rX   r]   r   r   r_   rj   rm   ru   r   r    r   r   r   re   r   r   r   ra   r   r   r~   rA   r5   r3   r!   r!   ?   s        E8C=*,(3-,,,P P PT T T: : :O O O$(6* $ $ $ $&)    , , , , ,P# P P P P .0"$"$9A9=( (q (( #( &c](  	(
  ( ( $$56(  (6( ( ( ( (@5.Q 5.c 5.# 5.! 5. 5. 5. 5.n/3 /4 / / / /"   )(6* ) ) ) )L 0 L L L LW 0 W W W WU U U U Ur5   c                       e Zd ZdZdZddZddedeee	e	f                  ddfd	Z
dd
Zefdeee         eee         df         f         defdZdee         fdZdS )Countera  A Counter tracks counts of events or running totals.

    Example use cases for Counters:
    - Number of requests processed
    - Number of items that were inserted into a queue
    - Total amount of data that a system has processed

    Counters can only go up (and be reset when the process restarts). If your use case can go down,
    you should use a Gauge instead.

    An example for a Counter:

        from prometheus_client import Counter

        c = Counter('my_failures_total', 'Description of counter')
        c.inc()     # Increment by 1
        c.inc(1.6)  # Increment by given value

    There are utilities to count exceptions raised:

        @c.count_exceptions()
        def f():
            pass

        with c.count_exceptions():
            pass

        # Count only one type of exception
        with c.count_exceptions(ValueError):
            pass
            
    You can also reset the counter to zero in case your logical "process" restarts
    without restarting the actual python process.

       c.reset()

    r'   r6   Nc                     t          j        | j        | j        | j        dz   | j        | j        | j                  | _        t          j                    | _	        d S )Nr(   )
r   
ValueClassrJ   rZ   rO   rP   r[   _valuetime_createdrQ   s    r3   r~   zCounter._metric_init  sK    '
DJ
X@UW[Wg(,(94;NP P	r5   r   amountrh   c                 &   |                                   |dk     rt          d          | j                            |           |rKt	          |           | j                            t          ||t          j                                         dS dS )z&Increment counter by the given amount.r   z9Counters can only be incremented by non-negative amounts.N)rV   r+   r   incr   set_exemplarr   r   )rR   r   rh   s      r3   r   zCounter.inc  s    %%'''A::XYYY 	Nx(((K$$Xh	%L%LMMMMM	N 	Nr5   c                 j    | j                             d           t          j                    | _        dS )zqReset the counter to zero. Use this when a logical process restarts without restarting the actual python process.r   N)r   setr   r   rQ   s    r3   resetzCounter.reset(  s'    	r5   	exception.c                 J    |                                   t          | |          S )zCount exceptions in a block of code or function.

        Can be used as a function decorator or context manager.
        Increments the counter when an exception of the given
        type is raised up out of the code.
        )rV   r   )rR   r   s     r3   count_exceptionszCounter.count_exceptions-  s&     	%%'''i000r5   c                     t          di | j                                        d | j                                                  }t          r|t          di | j        d d           fS |fS )Nr(   r   )r   r   r?   get_exemplarrE   r   )rR   samples     r3   r   zCounter._child_samples7  se    "dkoo&7&7t{?W?W?Y?YZZ 	z2t}dDAA  yr5   r   )r   N)rt   rs   r   __doc__rJ   r~   floatr
   r   rU   r   r   	Exceptionr   r   BaseExceptionr   r   r   r   r   r   rA   r5   r3   r   r      s       $ $J E$ $ $ $
N N% NxS#X/G NSW N N N N$ $ $ $
 ir 1 1%]0CU4P]K^`cKcEd0d*e 1  wG 1 1 1 1 0      r5   r   c                   X    e Zd ZdZdZ ed          Z ed          Zddddeddfd	e	d
e	de
e	         de	de	de	dee         deee	                  ded         f fdZd!dZd"deddfdZd"deddfdZdeddfdZd!dZdefdZdefdZdeg ef         ddfdZde
e         fd Z xZS )#Gaugea  Gauge metric, to report instantaneous values.

     Examples of Gauges include:
        - Inprogress requests
        - Number of items in a queue
        - Free memory
        - Total memory
        - Temperature

     Gauges can go both up and down.

        from prometheus_client import Gauge

        g = Gauge('my_inprogress_requests', 'Description of gauge')
        g.inc()      # Increment by 1
        g.dec(10)    # Decrement by given value
        g.set(4.2)   # Set to a given value

     There are utilities for common use cases:

        g.set_to_current_time()   # Set to current unixtime

        # Increment when entered, decrement when exited.
        @g.track_inprogress()
        def f():
            pass

        with g.track_inprogress():
            pass

     A Gauge can also take its value from a callback:

        d = Gauge('data_objects', 'Number of objects')
        my_dict = {}
        d.set_function(lambda: len(my_dict))
    gauge)
allliveallminliveminmaxlivemaxsumlivesum
mostrecentlivemostrecent)r   r   rA   r%   Nr   r.   rv   rw   r/   r0   r1   rx   rP   multiprocess_modec
           
          |	| _         |	| j        vrt          d|	z             t                                          ||||||||           | j         | j        d<   | j         | j        v | _        d S )NzInvalid multiprocess mode: r.   rv   rw   r/   r0   r1   rx   rP   r   )_multiprocess_mode_MULTIPROC_MODESr+   superr   r{   _MOST_RECENT_MODES_is_most_recent)rR   r.   rv   rw   r/   r0   r1   rx   rP   r   r   s             r3   r   zGauge.__init__j  s     #4D$999:=NNOOO'!% 	 		
 		
 		
 -1,C()#6$:QQr5   r6   c           	          t          j        | j        | j        | j        | j        | j        | j        | j                  | _        d S )N)r   )	r   r   rJ   rZ   rO   rP   r[   r   r   rQ   s    r3   r~   zGauge._metric_init  sA    'J
DJ0@$BS43J
 
 
r5   r   r   c                     | j         rt          d          |                                  | j                            |           dS )z$Increment gauge by the given amount.z-inc must not be used with the mostrecent modeNr   RuntimeErrorrV   r   r   rR   r   s     r3   r   z	Gauge.inc  sI     	PNOOO%%'''r5   c                     | j         rt          d          |                                  | j                            |            dS )z$Decrement gauge by the given amount.z-dec must not be used with the mostrecent modeNr   r   s     r3   decz	Gauge.dec  sK     	PNOOO%%'''     r5   rf   c                    |                                   | j        r<| j                            t	          |          t          j                               dS | j                            t	          |                     dS )zSet gauge to the given value.)rg   N)rV   r   r   r   r   r   )rR   rf   s     r3   r   z	Gauge.set  si    %%''' 	*KOOE%LLDIKKO@@@@@KOOE%LL)))))r5   c                 R    |                      t          j                               dS )z"Set gauge to the current unixtime.N)r   r   rQ   s    r3   set_to_current_timezGauge.set_to_current_time  s     r5   c                 H    |                                   t          |           S )zTrack inprogress blocks of code or functions.

        Can be used as a function decorator or context manager.
        Increments the gauge when the code is entered,
        and decrements when it is exited.
        )rV   r   rQ   s    r3   track_inprogresszGauge.track_inprogress  s$     	%%''' &&&r5   c                 "    t          | d          S )zTime a block of code or function, and set the duration in seconds.

        Can be used as a function decorator or context manager.
        r   r   rQ   s    r3   r   z
Gauge.time  s    
 T5!!!r5   fc                     |                                   dt          dt          t                   ffd}t	          j        ||           | _        dS )zCall the provided function to return the Gauge value.

        The function must return a float, and may be called from
        multiple threads. All other methods of the Gauge become NOOPs.
        r&   r6   c                 V    t          di t                                 d d           fS Nr%   )r   r   )r&   r   s    r3   samplesz#Gauge.set_function.<locals>.samples  s(    2r5::tT::<<r5   N)rV   r   r   r   types
MethodTyper   )rR   r   r   s    ` r3   set_functionzGauge.set_function  se     	%%'''	=u 	=&!1 	= 	= 	= 	= 	= 	= $.w==r5   c                 X    t          di | j                                        d d           fS r   )r   r   r?   rQ   s    r3   r   zGauge._child_samples  s'    r2t{00$==??r5   r   )r   )rt   rs   r   r   rJ   	frozensetr   r   r   rU   r   r
   r   r   r	   r   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r   s   @r3   r   r   A  sB       # #H E y  "J  K  K"#CDD
 .0"$"$9A9= W\R RR #R &c]R  	R
  R R $$56R  (6R %,  -S  %TR R R R R R6
 
 
 
   %          ! !% ! ! ! ! !* *4 * * * *   '"3 ' ' ' '"e " " " ">hr5y1 >d > > > >@ 0 @ @ @ @ @ @ @ @r5   r   c                   X    e Zd ZdZdZdgZddZdeddfdZde	fd	Z
dee         fd
ZdS )Summarya  A Summary tracks the size and number of events.

    Example use cases for Summaries:
    - Response latency
    - Request size

    Example for a Summary:

        from prometheus_client import Summary

        s = Summary('request_size_bytes', 'Request size (bytes)')
        s.observe(512)  # Observe 512 (bytes)

    Example for a Summary using time:

        from prometheus_client import Summary

        REQUEST_TIME = Summary('response_latency_seconds', 'Response latency (seconds)')

        @REQUEST_TIME.time()
        def create_response(request):
          '''A dummy function'''
          time.sleep(1)

    Example for using the same Summary object as a context manager:

        with REQUEST_TIME.time():
            pass  # Logic to be timed
    summaryquantiler6   Nc                 2   t          j        | j        | j        | j        dz   | j        | j        | j                  | _        t          j        | j        | j        | j        dz   | j        | j        | j                  | _        t          j	                    | _
        d S )N_count_sum)r   r   rJ   rZ   rO   rP   r[   r   r   r   r   rQ   s    r3   r~   zSummary._metric_init  s    '
DJ
X@UW[Wg(,(94;NP P%dj$*dj6>QSWSceievx|  yL  M  M		r5   r   c                     |                                   | j                            d           | j                            |           dS af  Observe the given amount.

        The amount is usually positive or zero. Negative values are
        accepted but prevent current versions of Prometheus from
        properly detecting counter resets in the sum of
        observations. See
        https://prometheus.io/docs/practices/histograms/#count-and-sum-of-observations
        for details.
        r   N)rV   r   r   r   r   s     r3   observezSummary.observe  sD     	%%'''	fr5   c                 "    t          | d          S zTime a block of code or function, and observe the duration in seconds.

        Can be used as a function decorator or context manager.
        r   r   rQ   s    r3   r   zSummary.time      
 T9%%%r5   c           	      ,   t          di | j                                        d d           t          di | j                                        d d           g}t          r+|                    t          di | j        d d                      t          |          S )Nr   r   r   )r   r   r?   r   rE   appendr   rz   )rR   r   s     r3   r   zSummary._child_samples  s    8R!2!2D$??62ty}}d;;
  	NNN6*b$-tLLMMMW~~r5   r   )rt   rs   r   r   rJ   rK   r~   r   r   r   r   r   r   r   rA   r5   r3   r   r     s         : E&<$ $ $ $e     &e & & & & 0      r5   r   c                   Z    e Zd ZdZdZdgZdddddd	d
dddddddefZddddedefde	de	de
e	         de	de	de	dee         deee	                  deeee	f                  f fdZdeeee	f                  d dfd!Zd(d"Zd)d#ed$eee	e	f                  d dfd%Zd efd&Zd e
e         fd'Z xZS )*	Histograma  A Histogram tracks the size and number of events in buckets.

    You can use Histograms for aggregatable calculation of quantiles.

    Example use cases:
    - Response latency
    - Request size

    Example for a Histogram:

        from prometheus_client import Histogram

        h = Histogram('request_size_bytes', 'Request size (bytes)')
        h.observe(512)  # Observe 512 (bytes)

    Example for a Histogram using time:

        from prometheus_client import Histogram

        REQUEST_TIME = Histogram('response_latency_seconds', 'Response latency (seconds)')

        @REQUEST_TIME.time()
        def create_response(request):
          '''A dummy function'''
          time.sleep(1)

    Example of using the same Histogram object as a context manager:

        with REQUEST_TIME.time():
            pass  # Logic to be timed

    The default buckets are intended to cover a typical web/rpc request from milliseconds to seconds.
    They can be overridden by passing `buckets` keyword argument to `Histogram`.
    	histogramleg{Gzt?g{Gz?g?g?g333333?g?g      ?g      ?g      ?      ?g      @g      @g      @g      $@rA   r%   Nr.   rv   rw   r/   r0   r1   rx   rP   bucketsc
           
          |                      |	           t                                          ||||||||           |	| j        d<   d S )Nr   r  )_prepare_bucketsr   r   r{   )rR   r.   rv   rw   r/   r0   r1   rx   rP   r  r   s             r3   r   zHistogram.__init__5  sf     	g&&&'!% 	 		
 		
 		
 #*Yr5   source_bucketsr6   c                    d |D             }|t          |          k    rt          d          |r+|d         t          k    r|                    t                     t	          |          dk     rt          d          || _        d S )Nc                 ,    g | ]}t          |          S rA   )r   )r   bs     r3   
<listcomp>z.Histogram._prepare_buckets.<locals>.<listcomp>N  s    444588444r5   zBuckets not in sorted order   zMust have at least two buckets)r   r+   r   r  r   _upper_bounds)rR   r  r  s      r3   r
  zHistogram._prepare_bucketsM  s    44^444fWoo%% :;;; 	 wr{c))NN3w<<!=>>>$r5   c                    g | _         t          j                    | _        | j        dz   }t	          j        | j        | j        | j        dz   | j        | j        | j	                  | _
        | j        D ]`}| j                             t	          j        | j        | j        | j        dz   || j        t          |          fz   | j	                             ad S )N)r  r   _bucket)_bucketsr   r   rO   r   r   rJ   rZ   rP   r[   r   r  r  r   )rR   bucket_labelnamesr  s      r3   r~   zHistogram._metric_initY  s    13	 ,w6%dj$*dj6>QSWSceievx|  yL  M  M	# 	 	AM  !2


Y&!!_Q%7%7$99#"% "%    	 	r5   r   rh   c           	         |                                   | j                            |           t          | j                  D ]\  }}||k    rt| j        |                             d           |rOt          |           | j        |                             t          ||t          j	                                          dS dS r   )
rV   r   r   	enumerater  r  r   r   r   r   )rR   r   rh   ir"   s        r3   r   zHistogram.observeh  s     	%%'''	f!$"455 	 	HAua $$Q''' [&x000M!$11(8VTY[[2Y2YZZZ 	 	r5   c                 "    t          | d          S r   r   rQ   s    r3   r   zHistogram.time|  r   r5   c                    g }d}t          | j                  D ]y\  }}|| j        |                                         z  }|                    t          ddt          |          i|d | j        |                                                              z|                    t          di |d d                      | j        d         dk    r=|                    t          di | j                                        d d                      t          r+|                    t          di | j
        d d                      t          |          S )Ng        r  r  r   r   r   r   )r  r  r  r?   r  r   r   r   r   rE   r   rz   )rR   r   accr  r"   s        r3   r   zHistogram._child_samples  s,   !$"455 	z 	zHAu4=#'')))CNN6)dOE4J4J-KSRVX\XefgXhXuXuXwXwxxyyyyvhCt<<===a A%%NN6&"dimmootTJJKKK 	NNN6*b$-tLLMMMW~~r5   r   rM   )rt   rs   r   r   rJ   rK   r   DEFAULT_BUCKETSr   rU   r   r
   r   r   r   r   r   r
  r~   r   r   r   r   r   r   r   r   s   @r3   r  r    s       ! !D E 6S$T2sBS#sTWY]_bcO
 .0"$"$9A9=8G* ** #* &c]*  	*
  * * $$56*  (6* #5#45* * * * * *0
%xeSj8I/J 
%t 
% 
% 
% 
%    e xS#X/G SW    (&e & & & & 0        r5   r  c                   T    e Zd ZdZdZd Zdeeef         ddfdZde	e
         fdZdS )	Infoa  Info metric, key-value pairs.

     Examples of Info include:
        - Build information
        - Version information
        - Potential target metadata

     Example usage:
        from prometheus_client import Info

        i = Info('my_build', 'Description of info')
        i.info({'version': '1.2.3', 'buildhost': 'foo@bar'})

     Info metrics do not work in multiprocess mode.
    r)   c                 l    t          | j                  | _        t                      | _        i | _        d S rM   )r   rO   _labelname_setr   r|   r   rQ   s    r3   r~   zInfo._metric_init  s+    !$"233VV
r5   valr6   Nc                    | j                             |                                          r(t          d                    | j        |                    t          d |                                D                       rt          d          | j        5  t          |          | _
        ddd           dS # 1 swxY w Y   dS )zSet info metric.z8Overlapping labels for Info metric, metric: {} child: {}c              3      K   | ]}|d u V  	d S rM   rA   )r   r  s     r3   r   zInfo.info.<locals>.<genexpr>  s&      //QqDy//////r5   zLabel value cannot be NoneN)r!  intersectionkeysr+   r   rO   anyr   r|   r   r   )rR   r"  s     r3   r)   z	Info.info  s    ++CHHJJ77 	(W^^ #' ' ( ( (//#**,,///// 	;9:::Z 	$ 	$s))DK	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$s   B88B<?B<c                 v    | j         5  t          d| j        dd d           fcd d d            S # 1 swxY w Y   d S )N_infor  )r|   r   r   rQ   s    r3   r   zInfo._child_samples  s    Z 	D 	D7DKdDAAC	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	Ds   .22)rt   rs   r   r   rJ   r~   r   rU   r)   r   r   r   rA   r5   r3   r  r    s          E  
$S#X $4 $ $ $ $D 0 D D D D D Dr5   r  c                        e Zd ZdZdZddddeddfdededee         d	ed
ededee	         deee                  deee                  f fdZ
ddZdeddfdZdee         fdZ xZS )Enuma`  Enum metric, which of a set of states is true.

     Example usage:
        from prometheus_client import Enum

        e = Enum('task_state', 'Description of enum',
          states=['starting', 'running', 'stopped'])
        e.state('running')

     The first listed state will be the default.
     Enum metrics do not work in multiprocess mode.
    r*   rA   r%   Nr.   rv   rw   r/   r0   r1   rx   rP   statesc
           
          t                                          ||||||||           ||v rt          d|           |	st          d|           |	x| j        d<   | _        d S )Nr   z$Overlapping labels for Enum metric: z$No states provided for Enum metric: r,  )r   r   r+   r{   _states)rR   r.   rv   rw   r/   r0   r1   rx   rP   r,  r   s             r3   r   zEnum.__init__  s     	'!% 	 		
 		
 		
 :JDJJKKK 	LJDJJKKK066Xr5   r6   c                 :    d| _         t                      | _        d S )Nr   )r   r   r|   rQ   s    r3   r~   zEnum._metric_init  s    VV


r5   statec                     |                                   | j        5  | j                            |          | _        ddd           dS # 1 swxY w Y   dS )zSet enum metric state.N)rV   r|   r.  indexr   )rR   r0  s     r3   r0  z
Enum.state  s    %%'''Z 	4 	4,,,U33DK	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4s    A		AAc                       j         5   fdt           j                  D             cd d d            S # 1 swxY w Y   d S )Nc           	      d    g | ],\  }}t          d j        |i|j        k    rdnddd          -S )r%   r   r   N)r   rZ   r   )r   r  srR   s      r3   r  z'Enum._child_samples.<locals>.<listcomp>  sT       Aq rDJ?dk1A1AAAq$PTUU  r5   )r|   r  r.  rQ   s   `r3   r   zEnum._child_samples  s    Z 	 	    T\**  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s    6::r   )rt   rs   r   r   rJ   r   rU   r   r
   r   r   r~   r0  r   r   r   r   r   s   @r3   r+  r+    s2         E
 .0"$"$9A9=377 77 #7 &c]7  	7
  7 7 $$567  (67 "(3-07 7 7 7 7 76   43 44 4 4 4 4 0        r5   r+  )8r=   	threadingr   r   r   typingr   r   r   r   r   r	   r
   r   r   r   r   r   r   r%   r   context_managersr   r   r   metrics_corer   rx   r   r   r   r   r   r   utilsr   r   
validationr   r   r   r    r#   r4   boolrB   rE   rF   rH   r!   r   r   r   r  r  r+  rA   r5   r3   <module>r=     s   				                                           H H H H H H H H H H             < < < < < < < < < < % % % % % % % % ' ' ' ' ' ' ' '          GC*+++GCxS)***  &j$ j j j j  !!    oU oU oU oU oU	 oU oU oUdM M M M M M M M`D@ D@ D@ D@ D@ D@ D@ D@NC C C C C C C CL@ @ @ @ @! @ @ @F#D #D #D #D #D #D #D #DL: : : : : : : : : :r5   