HEX
Server: LiteSpeed
System: Linux us-phx-web1284.main-hosting.eu 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: u300739242 (300739242)
PHP: 8.2.30
Disabled: system, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //opt/alt/python37/lib/python3.7/site-packages/prometheus_client/__pycache__/metrics.cpython-37.pyc
B

bP�ef�@s�ddlZddlmZddlZddlZddlmZmZmZm	Z	m
Z
mZmZm
Z
mZmZmZddlmZddlmZmZmZddlmZmZmZmZddlmZmZmZdd	l m!Z!m"Z"dd
l#m$Z$m%Z%eddd
�Z&ededefd
�Z'dd�Z(dd�Z)dd�Z*dd�Z+e,d�dd�Z-e-�Z.Gdd�de�Z/Gdd�de/�Z0Gdd�de/�Z1Gd d!�d!e/�Z2Gd"d#�d#e/�Z3Gd$d%�d%e/�Z4Gd&d'�d'e/�Z5dS)(�N)�Lock)�Any�Callable�Dict�Iterable�List�Optional�Sequence�Tuple�Type�TypeVar�Union�)�values)�ExceptionCounter�InprogressTracker�Timer)�Metric�METRIC_LABEL_NAME_RE�METRIC_NAME_RE�RESERVED_METRIC_LABEL_NAME_RE)�	Collector�CollectorRegistry�REGISTRY)�Exemplar�Sample)�floatToGoString�INF�T�MetricWrapperBase)�bound�F.cCs�d}|r||d7}|r$||d7}||7}|dkrJ|�d�rJ|dd�}|rh|�d|�sh|d|7}|r�|dkr�td|��|S)N��_�counter�_totali����)�info�statesetz2Metric name is of a type that cannot have a unit: )�endswith�
ValueError)�metric_type�name�	namespace�	subsystem�unitZ	full_name�r/�J/opt/alt/python37/lib/python3.7/site-packages/prometheus_client/metrics.py�_build_full_namesr1cCs0t�|�std|��t�|�r,td|��dS)NzInvalid label metric name: zReserved label metric name: )r�matchr)r)�lr/r/r0�_validate_labelname(s

r4cCs8t|�}x*|D]"}t|�||jkrtd|��qW|S)NzReserved label metric name: )�tupler4�_reserved_labelnamesr))�cls�
labelnamesr3r/r/r0�_validate_labelnames/s

r9cCsNd}x4|��D](\}}t|�|t|�7}|t|�7}qW|dkrJtd��dS)Nr�zDExemplar labels have %d UTF-8 characters, exceeding the limit of 128)�itemsr4�lenr))�exemplarZrunes�k�vr/r/r0�_validate_exemplar8sr@)�returncCstj�dd���dkS)NZ!PROMETHEUS_DISABLE_CREATED_SERIES�False)�true�1�t)�os�environ�get�lowerr/r/r/r0�_get_use_createdBsrJc@s<eZdZUdZeeed<dZeeed<dd�Z	dd�Z
d	d
�Zdd�Ze
ed
�dd�Ze
ed
�dd�Zed
�dd�Zed
�dd�Zddddedfeeee
eeeeeeeeedd�
dd�Zeeeed�dd�Zedd�dd�Zdd
�d d!�Ze
ed
�d"d#�Ze
ed
�d$d%�Ze
ed
�d&d'�Zd(d)�ZdS)*rN�_typer/r6cCs|jp|jo|jS)N)�_labelnames�_labelvalues)�selfr/r/r0�_is_observableMsz MetricWrapperBase._is_observablecCs|��stdt|j���dS)Nz!%s metric is missing label values)rOr)�strrK)rNr/r/r0�_raise_if_not_observableSsz*MetricWrapperBase._raise_if_not_observablecCs|jo|jS)N)rLrM)rNr/r/r0�
_is_parentZszMetricWrapperBase._is_parentcCst|j|j|j|j�S)N)r�_name�_documentationrK�_unit)rNr/r/r0�_get_metric]szMetricWrapperBase._get_metric)rAcCs
|��gS)N)rV)rNr/r/r0�describe`szMetricWrapperBase.describecCsB|��}x2|��D]&\}}}}}|�|j|||||�qW|gS)N)rV�_samplesZ
add_samplerS)rN�metric�suffix�labels�value�	timestampr=r/r/r0�collectcszMetricWrapperBase.collectcCs|j�d|j��S)N�:)rKrS)rNr/r/r0�__str__iszMetricWrapperBase.__str__cCs$t|�}|j�d|j�d|j�d�S)N�.�(�))�type�
__module__�__name__rS)rNr*r/r/r0�__repr__lszMetricWrapperBase.__repr__r")
rNr+�
documentationr8r,r-r.�registryrMrAc		Cs�t|j||||�|_t||�|_t|p(d�|_i|_||_||_	t
�|j�sZtd|j��|�
�rpt�|_i|_|��r�|��|js�|r�|�|�dS)Nr/zInvalid metric name: )r1rKrSr9rLr5rM�_kwargsrTrUrr2r)rRr�_lock�_metricsrO�_metric_init�register)	rNr+rhr8r,r-r.rirMr/r/r0�__init__ps 
zMetricWrapperBase.__init__)rN�labelvalues�labelkwargsrAc	s�|jstd|��|jr6td�|tt|j|j�����|rF�rFtd���r~t��t|j�krdtd��t�fdd�|jD��}n,t|�t|j�kr�td��tdd�|D��}|j	�B||j
kr�|j|jf|j
|j|j|d	�|j��|j
|<|j
|SQRXd
S)arReturn 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).
        z,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 **kwargszIncorrect label namesc3s|]}t�|�VqdS)N)rP)�.0r3)rqr/r0�	<genexpr>�sz+MetricWrapperBase.labels.<locals>.<genexpr>zIncorrect label countcss|]}t|�VqdS)N)rP)rrr3r/r/r0rs�s)rhr8r.rMN)rLr)rM�format�dict�zip�sortedr5r<rkrl�	__class__rSrTrUrj)rNrprqr/)rqr0r[�s2
zMetricWrapperBase.labels)rprAc	Gsj|jstd|��t|�t|j�kr:tdt|j�|f��tdd�|D��}|j�|j|=WdQRXdS)Nz,No label names were set when constructing %sz+Incorrect label count (expected %d, got %s)css|]}t|�VqdS)N)rP)rrr3r/r/r0rs�sz+MetricWrapperBase.remove.<locals>.<genexpr>)rLr)r<r5rkrl)rNrpr/r/r0�remove�szMetricWrapperBase.removec	Cs|j�i|_WdQRXdS)z$Remove all labelsets from the metricN)rkrl)rNr/r/r0�clear�szMetricWrapperBase.clearcCs|��r|��S|��SdS)N)rR�_multi_samples�_child_samples)rNr/r/r0rX�szMetricWrapperBase._samplesc
	cs�|j�|j��}WdQRXxb|��D]V\}}tt|j|��}x<|��D]0\}}}}}	t|t	|t|����|||	�VqHWq&WdS)N)
rkrl�copyr;�listrvrLrXrru)
rNZmetricsr[rYZ
series_labelsrZZ
sample_labelsr\r]r=r/r/r0r{�sz MetricWrapperBase._multi_samplescCstd|��dS)Nz*_child_samples() must be implemented by %r)�NotImplementedError)rNr/r/r0r|�sz MetricWrapperBase._child_samplescCstd|��dS)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 %rN)r)rNr/r/r0rm�szMetricWrapperBase._metric_init) rfre�__qualname__rKrrP�__annotations__r6r	rOrQrRrVrrrWr^r`rgrrrrorr[ryrzrrXr{r|rmr/r/r/r0rIs0
&7c@s�eZdZdZdZdd�dd�Zdeeee	e	fdd�d	d
�Z
efee
eee
edffed�d
d�Zeed�dd�ZdS)�CounterarA 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
    r$N)rAcCs4t�|j|j|jd|j|j|j�|_t��|_	dS)Nr%)
r�
ValueClassrKrSrLrMrT�_value�time�_created)rNr/r/r0rmszCounter._metric_initr)�amountr=rAcCsL|��|dkrtd��|j�|�|rHt|�|j�t||t����dS)z&Increment counter by the given amount.rz9Counters can only be incremented by non-negative amounts.N)rQr)r��incr@�set_exemplarrr�)rNr�r=r/r/r0r�szCounter.inc.)�	exceptionrAcCs|��t||�S)z�Count 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.
        )rQr)rNr�r/r/r0�count_exceptions#szCounter.count_exceptionscCs<tdi|j��d|j���}tr6|tdi|jdd�fS|fS)Nr%r�)rr�rH�get_exemplar�_use_createdr�)rN�sampler/r/r0r|-s
zCounter._child_samples)rN)rfrer��__doc__rKrm�floatrrrPr��	Exceptionr
r�
BaseExceptionr
rr�rrr|r/r/r/r0r��s 
,
r�cs�eZdZdZdZed�Zddddeddfeee	eeeee
ee
eeed�	�fd	d
�
Z
dd�dd
�Zd"edd�dd�Zd#edd�dd�Zedd�dd�Zdd�dd�Zed�dd�Zed�dd�Zegefdd�dd�Ze	ed�d d!�Z�ZS)$�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))
    Zgauge)�allZliveall�minZlivemin�maxZlivemax�sumZlivesumr/r"Nr�)	r+rhr8r,r-r.rirM�multiprocess_modec


sH|	|_|	|jkrtd|	��t�j||||||||d�|j|jd<dS)NzInvalid multiprocess mode: )r+rhr8r,r-r.rirMr�)�_multiprocess_mode�_MULTIPROC_MODESr)�superrorj)
rNr+rhr8r,r-r.rirMr�)rxr/r0ro_s
zGauge.__init__)rAc	Cs,tj|j|j|j|j|j|j|jd�|_dS)N)r�)	rr�rKrSrLrMrTr�r�)rNr/r/r0rmyszGauge._metric_initr)r�rAcCs|��|j�|�dS)z$Increment gauge by the given amount.N)rQr�r�)rNr�r/r/r0r�sz	Gauge.inccCs|��|j�|�dS)z$Decrement gauge by the given amount.N)rQr�r�)rNr�r/r/r0�dec�sz	Gauge.dec)r\rAcCs|��|j�t|��dS)zSet gauge to the given value.N)rQr��setr�)rNr\r/r/r0r��sz	Gauge.setcCs|�t���dS)z"Set gauge to the current unixtime.N)r�r�)rNr/r/r0�set_to_current_time�szGauge.set_to_current_timecCs|��t|�S)z�Track 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.
        )rQr)rNr/r/r0�track_inprogress�szGauge.track_inprogresscCs
t|d�S)z�Time a block of code or function, and set the duration in seconds.

        Can be used as a function decorator or context manager.
        r�)r)rNr/r/r0r��sz
Gauge.time)�frAcs2|��tttd��fdd�}t�||�|_dS)z�Call 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#rAcstdit���dd�fS)Nr")rr�)r#)r�r/r0�samples�sz#Gauge.set_function.<locals>.samplesN)rQr�rr�types�
MethodTyper|)rNr�r�r/)r�r0�set_function�szGauge.set_functioncCstdi|j��dd�fS)Nr")rr�rH)rNr/r/r0r|�szGauge._child_samples)r)r)rfrer�r�rK�	frozensetr�rrPrrrr	rormr�r�r�r�r�rr�rr�rr�rr|�
__classcell__r/r/)rxr0r�7s&$6
r�c@sXeZdZdZdZdgZdd�dd�Zedd�d	d
�Ze	d�dd�Z
eed�d
d�Z
dS)�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
    �summaryZquantileN)rAcCsZt�|j|j|jd|j|j|j�|_t�|j|j|jd|j|j|j�|_t	�	�|_
dS)N�_count�_sum)rr�rKrSrLrMrTr�r�r�r�)rNr/r/r0rm�s&zSummary._metric_init)r�rAcCs$|��|j�d�|j�|�dS)afObserve 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.
        rN)rQr�r�r�)rNr�r/r/r0�observe�s
zSummary.observecCs
t|d�S)z�Time a block of code or function, and observe the duration in seconds.

        Can be used as a function decorator or context manager.
        r�)r)rNr/r/r0r��szSummary.timecCsPtdi|j��dd�tdi|j��dd�g}trH|�tdi|jdd��t|�S)Nr�r�r�)rr�rHr�r��appendr�r5)rNr�r/r/r0r|�s
zSummary._child_samples)rfrer�r�rKr6rmr�r�rr�rrr|r/r/r/r0r��sr�cs�eZdZdZdZdgZdddddd	d
ddd
ddddefZddddedefe	e	e
e	e	e	e	eeee
e	e
eee	fd�	�fdd�
Ze
eee	fdd�dd�Zdd�dd�Zd%eeee	e	fdd�dd �Zed�d!d"�Ze
ed�d#d$�Z�ZS)&�	HistogramaA 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`.
    Z	histogram�leg{�G�zt?g{�G�z�?g�������?g�������?g333333�?g�������?g�?g�?g�?g�?g@g@g@g$@r/r"N)	r+rhr8r,r-r.rirM�bucketsc


s4|�|	�t�j||||||||d�|	|jd<dS)N)r+rhr8r,r-r.rirMr�)�_prepare_bucketsr�rorj)
rNr+rhr8r,r-r.rirMr�)rxr/r0ro"s
zHistogram.__init__)�source_bucketsrAcCsZdd�|D�}|t|�kr"td��|r<|dtkr<|�t�t|�dkrPtd��||_dS)NcSsg|]}t|��qSr/)r�)rr�br/r/r0�
<listcomp>;sz.Histogram._prepare_buckets.<locals>.<listcomp>zBuckets not in sorted order����zMust have at least two buckets)rwr)rr�r<�
_upper_bounds)rNr�r�r/r/r0r�:s
zHistogram._prepare_buckets)rAcCs�g|_t��|_|jd}t�|j|j|jd|j|j|j	�|_
xB|jD]8}|j�t�|j|j|jd||jt
|�f|j	��qHWdS)N)r�r��_bucket)�_bucketsr�r�rLrr�rKrSrMrTr�r�r�r)rNZbucket_labelnamesr�r/r/r0rmFs

&
zHistogram._metric_init)r�r=rAcCsr|��|j�|�xXt|j�D]J\}}||kr |j|�d�|rht|�|j|�t||t	�	���Pq WdS)afObserve 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.
        rN)
rQr�r��	enumerater�r�r@r�rr�)rNr�r=�ir r/r/r0r�Us
zHistogram.observecCs
t|d�S)z�Time a block of code or function, and observe the duration in seconds.

        Can be used as a function decorator or context manager.
        r�)r)rNr/r/r0r�iszHistogram.timec
Cs�g}d}xPt|j�D]B\}}||j|��7}|�tddt|�i|d|j|����qW|�tdi|dd��|jddkr�|�tdi|j��dd��t	r�|�tdi|j
dd��t|�S)Ngr�r�r�rr�r�)r�r�r�rHr�rrr�r�r�r�r5)rNr��accr�r r/r/r0r|ps,zHistogram._child_samples)N)rfrer�r�rKr6rZDEFAULT_BUCKETSrrPrrrr	r
r�ror�rmrr�rr�rr|r�r/r/)rxr0r��s ""B r�c@sFeZdZdZdZdd�Zeeefdd�dd�Ze	e
d	�d
d�ZdS)�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&cCst|j�|_t�|_i|_dS)N)r�rL�_labelname_setrrkr�)rNr/r/r0rm�szInfo._metric_initN)�valrAc	CsB|j�|���r"td�|j|���|j�t|�|_WdQRXdS)zSet info metric.z8Overlapping labels for Info metric, metric: {} child: {}N)	r��intersection�keysr)rtrLrkrur�)rNr�r/r/r0r&�s
z	Info.info)rAc	Cs&|j�td|jddd�fSQRXdS)N�_infog�?)rkrr�)rNr/r/r0r|�szInfo._child_samples)rfrer�r�rKrmrrPr&rrr|r/r/r/r0r�~s
r�cs�eZdZdZdZddddeddfeeeeeeeee	eeeeeed�	�fdd�
Z
dd	�d
d�Zedd�d
d�Ze
ed	�dd�Z�ZS)�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'r/r"N)	r+rhr8r,r-r.rirM�statesc


sXt�j||||||||d�||kr2td|����|	sDtd|����|	|jd<|_dS)N)r+rhr8r,r-r.rirMz$Overlapping labels for Enum metric: z$No states provided for Enum metric: r�)r�ror)rj�_states)
rNr+rhr8r,r-r.rirMr�)rxr/r0ro�sz
Enum.__init__)rAcCsd|_t�|_dS)Nr)r�rrk)rNr/r/r0rm�szEnum._metric_init)�staterAc	Cs,|��|j�|j�|�|_WdQRXdS)zSet enum metric state.N)rQrkr��indexr�)rNr�r/r/r0r��sz
Enum.statec	s*�j��fdd�t�j�D�SQRXdS)Ncs4g|],\}}td�j|i|�jkr&dnddd��qS)r"rrN)rrSr�)rrr��s)rNr/r0r��sz'Enum._child_samples.<locals>.<listcomp>)rkr�r�)rNr/)rNr0r|�s
zEnum._child_samples)rfrer�r�rKrrPr	rrrormr�rrr|r�r/r/)rxr0r��s>r�)6rF�	threadingrr�r��typingrrrrrrr	r
rrr
r"rZcontext_managersrrrZmetrics_corerrrrrirrrr�rr�utilsrrrr!r1r4r9r@�boolrJr�rr�r�r�r�r�r�r/r/r/r0�<module>s64	
*E~F$