????

Your IP : 18.222.144.72


Current Path : /usr/lib/python3.6/site-packages/glances/amps/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/glances/amps/__pycache__/glances_amp.cpython-36.opt-1.pyc

3

Eo�c?�@s<dZddlmZddlmZddlmZGdd�de�ZdS)ay
I am your father...

...for all Glances Application Monitoring Processes (AMP).

AMP (Application Monitoring Process)
A Glances AMP is a Python script called (every *refresh* seconds) if:
- the AMP is *enabled* in the Glances configuration file
- a process is running (match the *regex* define in the configuration file)
The script should define a Amp (GlancesAmp) class with, at least, an update method.
The update method should call the set_result method to set the AMP return string.
The return string is a string with one or more line (
 between lines).
If the *one_line* var is true then the AMP will be displayed in one line.
�)�u)�Timer)�loggerc@s�eZdZdZdZdZdZdZdZd%dd�Z	dd�Z
dd	�Zd
d�Zdd
�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd&dd �Zd!d"�Zd#d$�ZdS)'�
GlancesAmpzMain class for Glances AMP.�?NcCsVtjdj|j|j��|dkr6|jjtd�d�|_n||_||_	i|_
td�|_dS)zInit AMP class.zAMP - Init {} version {}NZglances_r)
r�debug�format�NAME�VERSION�	__class__�
__module__�len�amp_name�args�configsr�timer)�self�namer�r�!/usr/lib/python3.6/glances_amp.py�__init__'szGlancesAmp.__init__cCsTd|j}t|d�r�|j|�r�tjdj|j��x�|j|�D]�\}}y|j||�|j	|<WnRt
k
r�|j||�jd�|j	|<t
|j	|�dkr�|j	|d|j	|<YnXtjdj|j||j	|��q<Wntjdj|j|j��d	S|j��r0xLdD]0}||j	kr�tjdj|j||j��d|j	d
<q�Wntjdj|j��d|j	d<|j�S)z0Load AMP parameters from the configuration file.Zamp_�has_sectionzAMP - {}: Load configuration�,�rz!AMP - {}: Load parameter: {} = {}z;AMP - {}: Can not find section {} in the configuration fileF�refreshzTAMP - {}: Can not find configuration key {} in section {} (the AMP will be disabled)Zfalse�enablezAMP - {} is disabled�count)r)r�hasattrrrrrr	�itemsZget_float_valuer�
ValueErrorZ	get_value�splitr
rZwarning)r�configZamp_sectionZparam�_�krrr�load_config;s.
"



zGlancesAmp.load_configcCs||jkr|j|SdSdS)z7Generic method to get the item in the AMP configurationN)r)r�keyrrr�getls

zGlancesAmp.getcCs(|jd�}|dkrdS|j�jd�SdS)zVReturn True|False if the AMP is enabled in the configuration file (enable=true|false).rNF�true)r&�lower�
startswith)r�retrrrrss
zGlancesAmp.enablecCs
|jd�S)zEReturn regular expression used to identified the current application.�regex)r&)rrrrr+{szGlancesAmp.regexcCs
|jd�S)zNReturn refresh time in seconds for the current application monitoring process.r)r&)rrrrrszGlancesAmp.refreshcCs(|jd�}|dkrdS|j�jd�SdS)zSReturn True|False if the AMP should be displayed in one line (one_line=true|false).�one_lineNFr')r&r(r))rr*rrrr,�s
zGlancesAmp.one_linecCs
|jj�S)z%Return time in seconds until refresh.)rr&)rrrr�time_until_refresh�szGlancesAmp.time_until_refreshcCs0|jj�r,|jj|j��|jj�|j�SdS)z�Return True is the AMP should be updated

        Conditions for update:
        - AMP is enable
        - only update every 'refresh' seconds
        F)rZfinished�setr�resetr)rrrr�
should_update�s


zGlancesAmp.should_updatecCs||jd<dS)z.Set the number of processes matching the regexrN)r)rrrrr�	set_count�szGlancesAmp.set_countcCs
|jd�S)z.Get the number of processes matching the regexr)r&)rrrrr�szGlancesAmp.countcCs
|jd�S)z#Get the minimum number of processesZcountmin)r&)rrrr�	count_min�szGlancesAmp.count_mincCs
|jd�S)z#Get the maximum number of processesZcountmax)r&)rrrr�	count_max�szGlancesAmp.count_max�cCs2|j�r t|�jd|�|jd<nt|�|jd<dS)z�Store the result (string) into the result key of the AMP

        If one_line is true then it replaces `
` by the separator
        �
�resultN)r,r�replacer)rr6Z	separatorrrr�
set_result�szGlancesAmp.set_resultcCs|jd�}|dk	rt|�}|S)z*Return the result of the AMP (as a string)r6N)r&r)rr*rrrr6�s
zGlancesAmp.resultcCs,|jt|��|j�r |j|�S|j�SdS)zWrapper for the children updateN)r1r
r0�updater6)rZprocess_listrrr�update_wrapper�s
zGlancesAmp.update_wrapper)NN)r4)�__name__r�__qualname__�__doc__r	r
ZDESCRIPTIONZAUTHORZEMAILrr$r&rr+rr,r-r0r1rr2r3r8r6r:rrrrrs,
1


rN)	r=Zglances.compatrZ
glances.timerrZglances.loggerr�objectrrrrr�<module>s