HOME


Mini Shell 1.0
DIR: /lib/python3/dist-packages/landscape/lib/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/landscape/lib/__pycache__/monitor.cpython-312.pyc
�

�~�e����ddlZddlZddlmZddlmZGd�d�ZGd�de�ZGd�d	e�ZGd
�de�ZGd�d
e�Z	y)�N)�format_delta)�format_percentc�0�eZdZdZdd�Zd�Zd�Zd�Zd�Zy)	�Timerzp
    A timer keeps track of the number of seconds passed during it's
    lifetime and since the last reset.
    Nc��|xstj|_|j�|_|j|_y�N)�time�_create_time�_creation_time�
_last_time)�self�create_times  �7/usr/lib/python3/dist-packages/landscape/lib/monitor.py�__init__zTimer.__init__s1��'�4�4�9�9���"�/�/�1����-�-���c�"�|j�Sr)r
�r
s rr	z
Timer.times��� � �"�"rc�<�|j�|jz
Sr)r
rrs r�since_startzTimer.since_starts��� � �"�T�%8�%8�8�8rc�<�|j�|jz
Sr�r
rrs r�since_resetzTimer.since_resets��� � �"�T�_�_�4�4rc�.�|j�|_yrrrs r�resetzTimer.resets���+�+�-��rr)	�__name__�
__module__�__qualname__�__doc__rr	rrr�rrrrs ���
.�
#�9�5�.rrc�:��eZdZdZd�fd�	Zd�Z�fd�Zd�Z�xZS)�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.
    c�P��t�|�|��||_d|_d|_y)N�rr)�superr�
event_name�count�total_count)r
r%r�	__class__s   �rrzMonitor.__init__+s)���
���[��1�$�����
���rc�X�|xjdz
c_|xjdz
c_y)N�)r&r'rs r�pingzMonitor.ping1s ���
�
�a��
����A��rc�0��t�|��d|_y)Nr)r$rr&�r
r(s �rrz
Monitor.reset5s���
��
����
rc	��tjd|j|jt	|j���|j
�y)Nz%%d %s events occurred in the last %s.)�logging�infor&r%rrrrs r�logzMonitor.log9s;�����3��J�J��O�O���)�)�+�,�		
�	
�
�
�rr)	rrrrrr+rr1�
__classcell__�r(s@rr!r! s�������rr!c�6��eZdZdZ	d�fd�	Z�fd�Zd�Z�xZS)�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.
    c�R��t�|�||��||_||_g|_y�Nr#)r$r�repeat_interval�
maximum_count�_last_times)r
r8r9r%rr(s     �rrzBurstMonitor.__init__Js/���	������=�.���*�����rc�8��t�|��|j�}|jj	|�|jd|z
|j
kDs%t
|j�|jdzkDr|jjd�yy)Nrr*)	r$r+r	r:�appendr8�lenr9�pop)r
�nowr(s  �rr+zBurstMonitor.pingVs����
�����i�i�k��������$����Q��#�%��(<�(<�<��4�#�#�$�t�'9�'9�A�'=�=���� � ��#�>rc���|jsy|j�|jdz
}||jkxr%t|j�|jdzk\S)NFrr*)r:r	r8r=r9)r
�deltas  r�warnzBurstMonitor.warn`s`�������	�	��d�.�.�q�1�1���D�(�(�(�
@��D�$�$�%��);�);�a�)?�?�	
rr)rrrrrr+rBr2r3s@rr5r5Cs�����
�$�
rr5c�R��eZdZdZ	d�fd�	Zed��Zed��Zd�Zd�Z	�xZ
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.
    c�D��t�|�||��||_||_yr7)r$rr8�min_percent)r
r8rFr%rr(s     �rrzCoverageMonitor.__init__us/���	����#�	�	
� /���&��rc�f�	|jt|j�zS#t$rYywxYw)Ng�?)r&�float�expected_count�ZeroDivisionErrorrs r�percentzCoverageMonitor.percent�s3��	��:�:��d�&9�&9� :�:�:�� �	��	�s�!$�	0�0c�N�t|j�|jz�Sr)�intrr8rs rrIzCoverageMonitor.expected_count�s!���4�#�#�%��(<�(<�<�=�=rc�l�d}|jr|jr|jdz}tj}|j	�rtj
}|d|j|j|jt|�t|j���|j�y)Ng�dz9%d of %d expected %s events (%s) occurred in the last %s.)rKrIr/r0rB�warningr&r%rrrr)r
rKr1s   rr1zCoverageMonitor.log�s������<�<�D�/�/��l�l�S�(�G��l�l���9�9�;��/�/�C��G��J�J�����O�O��7�#���)�)�+�,�
	
�	
�
�
�rc��|jr3|jr'|jsy|j|jkryy)NFT)r8rFrIrKrs rrBzCoverageMonitor.warn�s7�����D�$4�$4��&�&���|�|�d�.�.�.��rr)rrrrr�propertyrKrIr1rBr2r3s@rrDrDjsD�����'������>��>��&rrDc�L��eZdZdZ	d�fd�	Zed��Z�fd�Zd�Zd�Z	�xZ
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.
    c�n��t�|�||��||_||_|j	�|_yr7)r$rr8�
min_frequencyr
�_last_count)r
r8rVr%rr(s     �rrzFrequencyMonitor.__init__�s@���	����#�	�	
� /���*����,�,�.��rc�Z�|j�|jz
}||jzSr)r
rWr8)r
�
since_pings  rrIzFrequencyMonitor.expected_count�s,���&�&�(�4�+;�+;�;�
��T�1�1�1�1rc�L��t�|��|j�|_yr)r$r+r
rWr-s �rr+zFrequencyMonitor.ping�s���
�����,�,�.��rc	���|j�rJtjd|j|j|j
t
|j��|j�y)NzAOnly %d of %d minimum expected %s events occurred in the last %s.)	rBr/rPr&rIr%rr8rrs rr1zFrequencyMonitor.log�sL���9�9�;��O�O�+��
�
��#�#�����T�1�1�2�

�	
�
�
�rc��|jrP|jrD|j�|jz
|jk\r|j|jkryy)NTF)r8rVr
rWr&rs rrBzFrequencyMonitor.warn�sM�����D�$6�$6��!�!�#�d�&6�&6�6�$�:N�:N�N��*�*�t�1�1�1��rr)rrrrrrRrIr+r1rBr2r3s@rrTrT�s5�����
/��2��2�/�
�rrT)
r/r	�landscape.lib.formatrrrr!r5rDrTrrr�<module>r^sN����-�/�.�.�0 �e� �F$
�7�$
�N=�g�=�@4�w�4r