HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.60.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 5 05:00:59 EST 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/lib/python3.9/site-packages/cockpit/channels/__pycache__/metrics.cpython-39.pyc
a

�/�h��@s�ddlZddlZddlZddlZddlZddlmZddlmZm	Z	m
Z
mZmZm
Z
mZmZddlmZmZddlmZmZmZddlmZmZmZmZe�e�ZGdd	�d	e
�ZGd
d�de�Z dS)�N)�defaultdict)�Dict�List�
NamedTuple�Optional�Set�Tuple�Type�Union�)�AsyncChannel�ChannelError)�JsonList�
JsonObject�get_int)�SAMPLERS�SampleDescription�Sampler�Samplesc@s"eZdZUeeed<eed<dS)�
MetricInfo�derive�descN)�__name__�
__module__�__qualname__r�str�__annotations__r�rr�</usr/lib/python3.9/site-packages/cockpit/channels/metrics.pyr!s
rc@s�eZdZUdZdgZeeed<eed<dZ	e
eee
eeeffed<dZeed<d	Zeed
<dZeed<dZeed
<edd��Zedd�dd�Zeed�dd�Zed�dd�Zee
eeeefd�dd�Z eed�dd�Z!edd�dd �Z"dS)!�InternalMetricsChannelZmetrics1)�source�internal�metrics�samplersN�samplers_cache���intervalT�	need_metar�last_timestamp�next_timestampcCs|jdurdd�tD�|_dS)NcSs$i|]}|jD]}|j||f�qqSr)Zdescriptions�name)�.0�samplerrrrr�
<dictcomp>6�z:InternalMetricsChannel.ensure_samplers.<locals>.<dictcomp>)r$r)�clsrrr�ensure_samplers3s
z&InternalMetricsChannel.ensure_samplers)�options�returncCsxt�d||j�t|d|j�}|dks0|tjkrBtdd|��d��||_|�d�}t	|t
�rht|�dkr�t�d|�tdd	d��|j
s�Jd
��t�}|D]�}|�d�}|�d�}|�d
�}z|j
|\}	}
WnFt�y}z,t�d|�tdd|��d�|�WYd}~n
d}~00|�rD||
jk�rDtd|�d|
j�d|��d��|�|	�|j�t||
d��q�dd�|D�|_dS)Nz&metrics internal open: %s, channel: %sr&rzprotocol-errorzinvalid "interval" value: )�messager"zinvalid "metrics" value: %sz5invalid "metrics" option was specified (not an array)zensure_samples not calledr*�unitsrzunsupported metric: %sz
not-supportedzunsupported metric: z has units z, not )rrcSsh|]
}|��qSrr)r+r/rrr�	<setcomp>Zr.z7InternalMetricsChannel.parse_options.<locals>.<setcomp>)�logger�debug�channelrr&�sys�maxsizer
�get�
isinstance�list�len�errorr$�set�KeyErrorr4�addr"�appendrr#)�selfr1r&r"Zsampler_classesZmetricr*r4rr,r�excrrr�
parse_options8s2



*
z$InternalMetricsChannel.parse_options)�samples�	timestampcCs�g}|jD]`}|jjrH|�|jj|jjt||jj���|jjd��q
|�|jj|j	|jj|jjd��q
t
t���d}|jd|j
|d||d�d|_dS)N)r*r4�	instances�	semantics)r*rr4rJr%r!)r r&rH�nowr"F)r"r�	instancedrCr*r4r=�keysrJr�int�timeZ	send_jsonr&r')rDrGrHr"�
metricinforKrrr�	send_meta\s(
�
�
�z InternalMetricsChannel.send_meta)r2cCs"tt�}|jD]}|�|�q|S)N)r�dictr#�sample)rDrGr,rrrrSss
zInternalMetricsChannel.sample)�value�	old_valuer2cCs$|dur|||j|jSdSdS)NF)r)r()rDrTrUrrr�calculate_sample_rateysz,InternalMetricsChannel.calculate_sample_rate)rG�last_samplesc
CsPg}t��}||_|jD�]}||jj}|jjr�||jj}t|t�sLJ�t|t�sZJ�|��|��krpd|_	|j
dkr�g}|��D] \}	}
|�|�
|
|�|	���q�|�|�n|�t|����q|�|jj�}t|t�r�J�t|t�r�J�|j
dk�r|�|�
||��q|�|�q|j	�r2|�||�|j|_|�t�|g��dS)NTZrate)rOr)r"rr*rLr<rRrMr'r�itemsrCrVr;r=�valuesrQr(Z	send_text�json�dumps)rDrGrW�datarHrPrTrUrI�key�valrrr�send_updatess6
z#InternalMetricsChannel.send_updatesc�sdg|_t�|_t��|�|�|��tt�}|�	�}|�
||�|}t�|j
d�IdHq0dS)Nr%)r"r@r#rr0rFZreadyrrRrSr_�asyncio�sleepr&)rDr1rWrGrrr�run�s
zInternalMetricsChannel.run)#rrrZpayloadZrestrictionsrrrrr$rrrrr	rrr&rNr'�boolr(�floatr)�classmethodr0rrFrrQrSr
rVr_rbrrrrr&s"
$
$)r)!r`rZZloggingr9rO�collectionsr�typingrrrrrrr	r
r8rr
ZjsonutilrrrrGrrrrZ	getLoggerrr6rrrrrr�<module>s(