HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/self/root/usr/lib/python3/dist-packages/landscape/lib/__pycache__/monitor.cpython-38.pyc
U

���c��@s�ddlmZddlZddlZddlmZmZGdd�de�ZGdd�de�Z	Gdd	�d	e	�Z
Gd
d�de	�ZGdd
�d
e	�ZdS)�)�absolute_importN)�format_delta�format_percentc@s:eZdZdZd
dd�Zdd�Zdd�Zd	d
�Zdd�ZdS)�Timerzp
    A timer keeps track of the number of seconds passed during it's
    lifetime and since the last reset.
    NcCs"|ptj|_|��|_|j|_dS�N)�time�_create_time�_creation_time�
_last_time)�self�create_time�r
�7/usr/lib/python3/dist-packages/landscape/lib/monitor.py�__init__s
zTimer.__init__cCs|��Sr)r�rr
r
rrsz
Timer.timecCs|��|jSr)rr	rr
r
r�since_startszTimer.since_startcCs|��|jSr�rr
rr
r
r�since_resetszTimer.since_resetcCs|��|_dSrrrr
r
r�resetszTimer.reset)N)	�__name__�
__module__�__qualname__�__doc__rrrrrr
r
r
rr	s
rcs>eZdZdZd�fdd�	Zdd�Z�fdd�Zd	d
�Z�ZS)�Monitora�
    A monitor tracks the number of pings it received during it's
    lifetime and since the last reset.  The component being monitored
    is responsible for calling C{ping()} everytime a monitored
    activity occurs.  It should register a reactor event that logs
    statistics from this monitor every N seconds.  Essentially,
    monitors are just statistics checkers that components can use to
    monitor themselves.
    Ncs(tt|�j|d�||_d|_d|_dS)N�rr)�superrr�
event_name�count�total_count)rrr��	__class__r
rr,szMonitor.__init__cCs |jd7_|jd7_dS)N�)rrrr
r
r�ping2szMonitor.pingcstt|���d|_dS)Nr)rrrrrrr
rr6sz
Monitor.resetcCs(t�d|j|jt|����|��dS)Nz%%d %s events occurred in the last %s.)�logging�inforrrrrrr
r
r�log:s


�zMonitor.log)N)	rrrrrr"rr%�
__classcell__r
r
rrr!s

rcs6eZdZdZd	�fdd�	Z�fdd�Zdd�Z�ZS)
�BurstMonitorz�
    A burst monitor tracks the volume pings it receives.  It goes into
    warn mode when too many pings are received in a short period of
    time.
    Ncs*tt|�j||d�||_||_g|_dS�Nr)rr'r�repeat_interval�
maximum_count�_last_times)rr)r*rrrr
rrGszBurstMonitor.__init__csZtt|���|��}|j�|�|jd||jksJt|j�|jdkrV|j�	d�dS)Nrr!)
rr'r"rr+�appendr)�lenr*�pop)rZnowrr
rr"Ns�zBurstMonitor.pingcCs:|js
dS|��|jd}||jko8t|j�|jdkS)NFrr!)r+rr)r-r*)rZdeltar
r
r�warnWs
�zBurstMonitor.warn)N)rrrrrr"r/r&r
r
rrr'@s
�	r'csJeZdZdZd
�fdd�	Zedd��Zedd��Zd	d
�Zdd�Z	�Z
S)�CoverageMonitora�
    A coverage monitor tracks the volume of pings received since the
    last reset.  It has normal and warn states that are determined by
    calculating the number of expected pings since the last reset.  If
    the actual number of pings falls below the minimum required
    percent the monitor goes into warn mode.  The component being
    monitored should register a reactor event that logs statistics
    from this monitor every N seconds.
    Ncs$tt|�j||d�||_||_dSr()rr0rr)�min_percent)rr)r1rrrr
rrjs
�zCoverageMonitor.__init__cCs.z|jt|j�WStk
r(YdSXdS)Ng�?)r�float�expected_count�ZeroDivisionErrorrr
r
r�percentqszCoverageMonitor.percentcCst|��|j�Sr)�intrr)rr
r
rr3xszCoverageMonitor.expected_countc	Cs^d}|jr|jr|jd}tj}|��r.tj}|d|j|j|jt|�t	|�
���|��dS)Ng�dz9%d of %d expected %s events (%s) occurred in the last %s.)r5r3r#r$r/�warningrrrrrr)rr5r%r
r
rr%|s

�zCoverageMonitor.logcCs*|jr&|jr&|jsdS|j|jkr&dSdS)NFT)r)r1r3r5rr
r
rr/�szCoverageMonitor.warn)N)rrrrr�propertyr5r3r%r/r&r
r
rrr0_s�

r0csJeZdZdZd
�fdd�	Zedd��Z�fdd�Zd	d
�Zdd�Z	�Z
S)�FrequencyMonitoraz
    A frequency monitor tracks the number of pings received during a
    fixed period of time.  It has normal and warn states; a warn state
    is triggered when the minimum expected pings were not received
    during the specified interval.  The component being monitored
    should register a reactor event that checks the warn state of this
    monitor every N seconds.
    Ncs.tt|�j||d�||_||_|��|_dSr()rr:rr)�
min_frequencyr�_last_count)rr)r;rrrr
rr�s�zFrequencyMonitor.__init__cCs|��|j}||jSr)rr<r))rZ
since_pingr
r
rr3�szFrequencyMonitor.expected_countcstt|���|��|_dSr)rr:r"rr<rrr
rr"�szFrequencyMonitor.pingcCs2|��r&t�d|j|j|jt|j��|��dS)NzAOnly %d of %d minimum expected %s events occurred in the last %s.)	r/r#r8rr3rrr)rrr
r
rr%�s�zFrequencyMonitor.logcCs4|jr0|jr0|��|j|jkr0|j|jkr0dSdS)NTF)r)r;rr<rrr
r
rr/�s�
�zFrequencyMonitor.warn)N)rrrrrr9r3r"r%r/r&r
r
rrr:�s
�
r:)
Z
__future__rr#rZlandscape.lib.formatrr�objectrrr'r0r:r
r
r
r�<module>s4