HEX
Server: LiteSpeed
System: Linux baran.dnsprotection.me 4.18.0-553.83.1.lve.el8.x86_64 #1 SMP Wed Nov 12 10:04:12 UTC 2025 x86_64
User: ddir12 (3618)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/glances/plugins/__pycache__/glances_plugin.cpython-36.opt-1.pyc
3

Eo�c;��
@s�dZddlZddlZddlmZmZddlmZmZm	Z	m
Z
mZmZm
Z
ddlmZddlmZddlmZddlmZdd	lmZdd
lmZmZddlmZdd
iZddddddddddddd�ZGdd�de�Z dS)z2
I am your father...

...for all Glances plugins.
�N)�
json_dumps�json_dumps_dictlist)�iterkeys�
itervalues�listkeys�map�mean�	nativestr�PY3)�GlancesActions)�GlancesHistory)�logger)�glances_events)�glances_thresholds)�Counter�Timer)�unicode_message�percent�%�float�int)rZpercents�numberZnumbersrZintsrZfloats�secondZsecondsZbyte�bytesc@s�eZdZdZdddidfdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
d�dd�Zd�dd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd�d d!�Zd�d"d#�Zd�d$d%�Zd�d&d'�Zd�d)d*�Zed+d,��Zejd-d,��Zed.d/��Zd0d1�Zejd2d/��Zd3d4�Zd�d6d7�Zd8d9�Zd:d;�Zd<d=�Z d>d?�Z!d@dA�Z"dBdC�Z#dDdE�Z$dFdG�Z%dHdI�Z&d�dJdK�Z'd�dLdM�Z(dNdO�Z)edPdQ��Z*e*jdRdQ��Z*dSdT�Z+dUdV�Z,dWdX�Z-dYdZ�Z.d�d[d\�Z/d]d^�Z0d�d`da�Z1d�ddde�Z2dfdg�Z3dhdi�Z4d�djdk�Z5d�dldm�Z6d�dndo�Z7d�dpdq�Z8d�drds�Z9d_dgfdtdu�Z:d�dvdw�Z;d�dxdy�Z<d�dzd{�Z=d|d}�Z>d�d~d�Z?d�d�d��Z@d�d�d��ZAd�d��ZBd�d�d��ZCed�d���ZDeDjd�d���ZDd�d�d��ZEd�d�d��ZFd�d��ZGd�d��ZHeIeG�ZGeIeH�ZHdS)��
GlancesPluginzMain class for Glances plugin.NcCs�|jjjd�td�d}|jj|d�|_||_d|_d|_d|_||_	|j
�|_t�|_
|dk	r�tjdj|j|j���|j|d�t|d	�|_t�|_d
|_g|_td�|_||_||_d|_|j�dS)a
Init the plugin of plugins class.

        All Glances' plugins should inherit from this class. Most of the
        methods are already implemented in the father classes.

        Your plugin should return a dict or a list of dicts (stored in the
        self.stats). As an example, you can have a look on the mem plugin
        (for dict) or network (for list of dicts).

        A plugin should implement:
        - the __init__ constructor: define the self.display_curse
        - the reset method: to set your self.stats variable to {} or []
        - the update method: where your self.stats variable is set
        and optionally:
        - the get_key method: set the key of the dict (only for list of dict)
        - the update_view method: only if you need to trick your output
        - the msg_curse: define the curse (UI) message (if display_curse is True)

        :args: args parameters
        :items_history_list: list of items to store in the history
        :stats_init_value: Default value for a stats item
        �glances_Zglances�N�leftZlocalzLoad section {} in {})�config)�argsFr)�	__class__�
__module__�find�len�plugin_namer�_align�
_input_method�_short_system_name�items_history_list�init_stats_history�
stats_history�dict�_limitsr
�debug�formatZconfig_file_paths�load_limitsr�actions�views�	hide_zero�hide_zero_fieldsr�
refresh_timer�fields_description�stats_init_value�stats�reset)�selfrrr(r6r5�pos�r;�$/usr/lib/python3.6/glances_plugin.py�__init__3s*

zGlancesPlugin.__init__cCs|jS)zReturn the raw stats.)r7)r9r;r;r<�__repr__yszGlancesPlugin.__repr__cCs
t|j�S)z Return the human-readable stats.)�strr7)r9r;r;r<�__str__}szGlancesPlugin.__str__cCstj|j�S)z Return a copy of the init value.)�copyr6)r9r;r;r<�get_init_value�szGlancesPlugin.get_init_valuecCs|j�|_dS)zVReset the stats.

        This method should be overwritten by child classes.
        N)rBr7)r9r;r;r<r8�szGlancesPlugin.resetcCstjdj|j��dS)z$Just log an event when Glances exit.zStop the {} pluginN)r
r-r.r$)r9r;r;r<�exit�szGlancesPlugin.exitcCsdS)zReturn the key of the list.Nr;)r9r;r;r<�get_key�szGlancesPlugin.get_keycCsN|s
|j}yt|jd|�}Wn&tk
rDt|jd|d�}YnX|dkS)z!Return true if plugin is enabled.Zdisable_Zenable_TF)r$�getattrr�AttributeError)r9r$�dr;r;r<�
is_enabled�szGlancesPlugin.is_enabledcCs|j|d�S)z"Return true if plugin is disabled.)r$)rH)r9r$r;r;r<�is_disabled�szGlancesPlugin.is_disabledcCs |jdk	o|jjo|j�dk	S)N)rZdisable_history�get_items_history_list)r9r;r;r<�history_enable�szGlancesPlugin.history_enablecCs4|j�r.dd�|j�D�}tjdj|j|��t�S)z2Init the stats history (dict of GlancesAttribute).cSsg|]}|d�qS)�namer;)�.0�ar;r;r<�
<listcomp>�sz4GlancesPlugin.init_stats_history.<locals>.<listcomp>z1Stats history activated for plugin {} (items: {}))rKrJr
r-r.r$r)r9Z	init_listr;r;r<r)�sz GlancesPlugin.init_stats_historycCs<|j�r8dd�|j�D�}tjdj|j|��|jj�dS)z3Reset the stats history (dict of GlancesAttribute).cSsg|]}|d�qS)rLr;)rMrNr;r;r<rO�sz5GlancesPlugin.reset_stats_history.<locals>.<listcomp>z'Reset history for plugin {} (items: {})N)rKrJr
r-r.r$r*r8)r9Z
reset_listr;r;r<�reset_stats_history�sz!GlancesPlugin.reset_stats_historycCs�|j�r�|j�r�|j�dkr"d}n|j�}x�|j�D]�}t|j�t�r�x�|j�D]B}|jjt||�dt|d�||d|d|j	dd�qPWq4|jjt|d�|j�|d|d|j	dd�q4WdS)zUpdate stats history.N��_rL�description�history_size)rSZhistory_max_size)
�
get_exportrKrDrJ�
isinstance�listr*�addr	r,)r9Z	item_name�iZl_exportr;r;r<�update_stats_history�s"

z"GlancesPlugin.update_stats_historycCs|jS)zReturn the items history list.)r()r9r;r;r<rJ�sz$GlancesPlugin.get_items_history_listrcCs2|jj|d�}|dkr|S||kr*||SdSdS)z�Return the history (RAW format).

        - the stats history (dict of list) if item is None
        - the stats history for the given item (list) instead
        - None if item did not exist in the history
        )�nbN)r*�get)r9�itemr[�sr;r;r<�get_raw_history�szGlancesPlugin.get_raw_historycCs2|jj|d�}|dkr|S||kr*||SdSdS)aReturn the history (JSON format).

        - the stats history (dict of list) if item is None
        - the stats history for the given item (list) instead
        - None if item did not exist in the history
        Limit to lasts nb items (all if nb=0)
        )r[N)r*�get_json)r9r]r[r^r;r;r<�get_json_history�szGlancesPlugin.get_json_historycCs|j|d�S)z*Return the stats history object to export.)r])r_)r9r]r;r;r<�get_export_history�sz GlancesPlugin.get_export_historycCs&|j|d�}|dkrt|�St||�S)z'Return the stats history (JSON format).)r[N)rarr)r9r]r[r^r;r;r<�get_stats_history�szGlancesPlugin.get_stats_history�cCsL|j||d�}|dks"t|�|kr&dSdd�|D�}|dt|dd��S)z�Get the trend regarding to the last nb values.

        The trend is the diff between the mean of the last nb values
        and the current one.
        )r]r[NcSsg|]}|d�qS)rr;)rM�vr;r;r<rOsz+GlancesPlugin.get_trend.<locals>.<listcomp>r���rf)r_r#r)r9r]r[Zraw_historyZlast_nbr;r;r<�	get_trends
zGlancesPlugin.get_trendcCs|jS)zGet the input method.)r&)r9r;r;r<�input_methodszGlancesPlugin.input_methodcCs
||_dS)z�Set the input method.

        * local: system local grab (psutil or direct access)
        * snmp: Client server mode via SNMP
        * glances: Client server mode via Glances API
        N)r&)r9rhr;r;r<rhscCs|jS)z&Get the short detected OS name (SNMP).)r')r9r;r;r<�short_system_nameszGlancesPlugin.short_system_namecsN�j��yt�j��fdd�d�Stk
rHt�j��fdd�d�SXdS)z5Get the stats sorted by an alias (if present) or key.cs,ttdd�tjd�j|��p$|����S)NcSs|j�rt|�S|j�S)N)�isdigitr�lower)�partr;r;r<�<lambda>+sz>GlancesPlugin.sorted_stats.<locals>.<lambda>.<locals>.<lambda>z	(\d+|\D+))�tupler�re�split�	has_alias)�stat)�keyr9r;r<rm)sz,GlancesPlugin.sorted_stats.<locals>.<lambda>)rscs,ttdd�tjd�j|��p$|����S)NcSs|j�S)N)rk)rlr;r;r<rm5sz>GlancesPlugin.sorted_stats.<locals>.<lambda>.<locals>.<lambda>z	(\d+|\D+))rnrrorprq)rr)rsr9r;r<rm4sN)rD�sortedr7�	TypeError)r9r;)rsr9r<�sorted_stats#szGlancesPlugin.sorted_statscCs
||_dS)z&Set the short detected OS name (SNMP).N)r')r9�
short_namer;r;r<ri9scCs
||_dS)zSet the stats to input_stats.N)r7)r9Zinput_statsr;r;r<�	set_stats>szGlancesPlugin.set_statsFc
Csr|pi}ddlm}||jj|jj|jj|jjd�}i}|�r<|jddt|��}t	|�dkr�x�|D]T}t
|�djt|�d�rbt|�d|t
|�dt
|�djt|�d�d<qbWn~d}x�|D]p}i}	d}
xLt
|�D]@}||dt
|�}||kr�|
dk�r||}
q�|||	|<q�W|	�r.|	||
<|d7}q�Wn2|jt|��}x"t
|�D]}|||||<�qTW|S)zeUpdate stats using SNMP.

        If bulk=True, use a bulk request instead of a get request.
        r)�GlancesSNMPClient)�hostZport�versionZ	community�
rN�.)Zglances.snmpryrZclientZ	snmp_portZsnmp_versionZsnmp_communityZgetbulk_by_oidrr#r�
startswithrpr?Z
get_by_oid)
r9ZbulkZsnmp_oidryZsnmp_client�retZsnmp_resultr]�indexZ
item_statsZitem_keyrsZoidr;r;r<�get_stats_snmpBsB
6


zGlancesPlugin.get_stats_snmpcCs|jS)zReturn the stats object.)r7)r9r;r;r<�get_raw|szGlancesPlugin.get_rawcCs|j�S)z"Return the stats object to export.)r�)r9r;r;r<rU�szGlancesPlugin.get_exportcCs
t|j�S)z'Return the stats object in JSON format.)rr7)r9r;r;r<�	get_stats�szGlancesPlugin.get_statscCs|j�S)z'Return the stats object in JSON format.)r�)r9r;r;r<r`�szGlancesPlugin.get_jsoncCst|j|�S)z�Return the stats object for a specific item in JSON format.

        Stats should be a list of dict (processlist, network...)
        )rr7)r9r]r;r;r<�get_stats_item�szGlancesPlugin.get_stats_itemcs�t|jt�sdSt�t�r,�j�r,t���yt���fdd�|jD�i�Sttfk
r�}ztj	dj
��|��dSd}~XnXdS)z�Return the stats object for a specific item=value in JSON format.

        Stats should be a list of dict (processlist, network...)
        Ncsg|]}|��kr|�qSr;r;)rMrY)r]�valuer;r<rO�sz1GlancesPlugin.get_stats_value.<locals>.<listcomp>z"Cannot get item({})=value({}) ({}))rVr7rWrrjr�KeyError�
ValueErrorr
�errorr.)r9r]r��er;)r]r�r<�get_stats_value�szGlancesPlugin.get_stats_valuecs��js
dSt�j�t�r�j�dk	r�j�dk	r�x��j�D]��t�fdd��jD��r�x>�jD]4}�j��j�|d�j��j�|d<q^WxJ�jD]@}�j��j�|doƈ|dk�j��j�|d<q�Wq:Wn�t�j�t��r��j�dk	�r�x�t	�j��D]�}t�fdd��jD���r\x(�jD]}�j|d�j|d<�q:Wx4�jD]*}�jd�o��j|dk�j|d<�qdW�qWd	S)
a�Update the hidden views

        If the self.hide_zero is set then update the hidden field of the view
        It will check if all fields values are already be different from 0
        In this case, the hidden field is set to True

        Note: This function should be called by plugin (in the update_views method)

        Example (for network plugin):
        __Init__
            self.hide_zero_fields = ['rx', 'tx']
        Update views
            ...
            self.update_views_hidden()
        FNcsg|]}�|�qSr;r;)rM�f)rYr;r<rO�sz5GlancesPlugin.update_views_hidden.<locals>.<listcomp>�hidden�_zerorcsg|]}�j�|�qSr;)r�)rMr�)r9r;r<rO�sT)
r2rVr�rWrD�anyr3r1r+r)r9r�rsr;)rYr9r<�update_views_hidden�s"&4F0z!GlancesPlugin.update_views_hiddencCsfi}t|j�t�r�|j�dk	r�|j�dk	r�x�|j�D]�}i|||j�<x�t|�D]�}ddddd||j�|jkr�||j||j�kr�d|j||j�|kr�|j||j�|dndd�}||||j�|<qRWq4Wnxt|j�t�o�|j�dk	�rZxZt|j��D]J}ddddd||jk�rDd|j|k�rD|j|dndd�}|||<�qW||_|jS)a�Update the stats views.

        The V of MVC
        A dict of dict with the needed information to display the stats.
        Example for the stat xxx:
        'xxx': {'decoration': 'DEFAULT',  >>> The decoration of the stats
                'optional': False,        >>> Is the stat optional
                'additional': False,      >>> Is the stat provide additional information
                'splittable': False,      >>> Is the stat can be cut (like process lon name)
                'hidden': False,          >>> Is the stats should be hidden in the UI
                '_zero': True}            >>> For internal purpose only
        N�DEFAULTFZzeror�T)�
decoration�optional�
additional�
splittabler�r�)rVr�rWrDrr1r+)r9rrYrsr�r;r;r<�update_views�s4
&42zGlancesPlugin.update_viewscCs
||_dS)zSet the views to input_views.N)r1)r9Zinput_viewsr;r;r<�	set_views�szGlancesPlugin.set_viewscCsV|dkr|j}n
|j|}|dkr&|S|dkr6||S|||krN|||SdSdS)aCReturn the views object.

        If key is None, return all the view for the current plugin
        else if option is None return the view for the specific key (all option)
        else return the view of the specific key/option

        Specify item if the stats are stored in a dict of dict (ex: NETWORK, FS...)
        Nr�)r1)r9r]rs�optionZ
item_viewsr;r;r<�	get_viewss	
zGlancesPlugin.get_viewscCst|j|||��S)zReturn the views (in JSON).)rr�)r9r]rsr�r;r;r<�get_json_viewsszGlancesPlugin.get_json_viewscCs�d|jd<t|d�sdS|jd�rP|jdddd�|jd<tjdjd|jd��|j|j�r�x�|j|j�D]x\}}dj	|j|g�}y|j|j|�|j|<Wn.t
k
r�|j|j|�jd	�|j|<YnXtjd
j||j|��qjWdS)z6Load limits from the configuration file, if it exists.i�prT�has_sectionF�global)�defaultzLoad configuration key: {} = {}rR�,zLoad limit: {} = {}T)
r,�hasattrr�Zget_float_valuer
r-r.r$�items�joinr�Z	get_valuerp)r9r�levelrR�limitr;r;r<r/s


 zGlancesPlugin.load_limitscCs|jS)zReturn the limits object.)r,)r9r;r;r<�limits:szGlancesPlugin.limitscCs
||_dS)zSet the limits to input_limits.N)r,)r9Zinput_limitsr;r;r<r�?scCs|jd|�dS)zSet the plugin refresh rate�refreshN)�
set_limits)r9r�r;r;r<�set_refreshDszGlancesPlugin.set_refreshcCs |jdd�}|dkr|jj}|S)zReturn the plugin refresh timer�)r]N)�
get_limitsrZtime)r9rr;r;r<�get_refreshHszGlancesPlugin.get_refreshcCs|j�S)zReturn the plugin refresh time)r�)r9r;r;r<�get_refresh_timeOszGlancesPlugin.get_refresh_timecCs||jdj|j|�<dS)zSet the limits object.z{}_{}N)r,r.r$)r9r]r�r;r;r<r�SszGlancesPlugin.set_limitscCs*|dkr|jS|jjdj|j|�d�SdS)zReturn the limits object.Nz{}_{})r,r\r.r$)r9r]r;r;r<r�WszGlancesPlugin.get_limitscCs|jS)z�Return stats for the action.

        By default return all the stats.
        Can be overwrite by plugins implementation.
        For example, Docker will return self.stats['containers']
        )r7)r9r;r;r<�get_stats_action^szGlancesPlugin.get_stats_actionrQcCs|j}|dkr|d|7}|S)z. "Return the stat name with an optional headerrQrR)r$)r9�headerrr;r;r<�
get_stat_namegszGlancesPlugin.get_stat_name�dTc	
Cs"|r|dkrdSy|d|}	Wn&tk
r6dStk
rHdSX|j|d�}
|r^dnd}yX|	|jd|
d�kr|d	}n<|	|jd
|
d�kr�d}n$|	|jd|
d�kr�d
}n||kr�d
}Wntk
r�dSXd}|j|
|d��r�d}tj||
j�|	�|j	|
|�|j
|
|j�||�||S)aReturn the alert status relative to a current value.

        Use this function for minor stats.

        If current < CAREFUL of max then alert = OK
        If current > CAREFUL of max then alert = CAREFUL
        If current > WARNING of max then alert = WARNING
        If current > CRITICAL of max then alert = CRITICAL

        If highlight=True than 0.0 is highlighted

        If defined 'header' is added between the plugin name and the status.
        Only useful for stats with several alert status.

        If defined, 'action_key' define the key for the actions.
        By default, the action_key is equal to the header.

        If log=True than add log if necessary
        elif log=False than do not log
        elif log=None than apply the config given in the conf file
        rr�r�)r��MAXZOKZcritical)�	stat_nameZCRITICALZwarningZWARNINGZcarefulZCAREFULrQ)r��default_actionZ_LOG)�ZeroDivisionErrorrur��	get_limitr��
get_limit_logrrX�upper�manage_threshold�
manage_actionrk)
r9�current�minimum�maximumZhighlight_zeroZis_maxr��
action_key�logr�r�rZlog_strr;r;r<�	get_alertns8!zGlancesPlugin.get_alertcCstj||�dS)z*Manage the threshold for the current stat.N)rrX)r9r��triggerr;r;r<r��szGlancesPlugin.manage_thresholdc	Cs�y|j||d�\}}Wn"tk
r8|jj||�YnhX|dkrF|}t|j�t�r�i}x0|j�D]}||j�|krb|}PqbWn|j�}|jj|||||d�dS)z'Manage the action for the current stat.)r�N)�
mustache_dict)	�get_limit_actionr�r0�setrVr�rWrDZrun)	r9r�r�r�r�Zcommand�repeatr�r]r;r;r<r��szGlancesPlugin.manage_actioncCs|j|||||dd�S)zGet the alert log.T)r�r�r�r�r�r�)r�)r9r�r�r�r�r�r;r;r<�
get_alert_log�szGlancesPlugin.get_alert_logcCs2|dkr|jd||jkS|d||jkSdS)zBReturn true if the criticality limit exist for the given stat_namerQrRN)r$r,)r9�criticalityr�r;r;r<�is_limit�szGlancesPlugin.is_limitcCsDy|j|d|}Wn(tk
r>|j|jd|}YnX|S)z%Return the limit value for the alert.rR)r,r�r$)r9r�r�r�r;r;r<r��s
zGlancesPlugin.get_limitcCs�|d|ddf|d|ddf|jd|ddf|jd|ddfg}x0|D](}|d|jkrV|j|d|dfSqVWt�dS)	zxReturn the tuple (action, repeat) for the alert.

        - action is a command line
        - repeat is a bool
        rRZ_actionFZ_action_repeatTrrN)r$r,r�)r9r�r�r�rr;r;r<r��s

zGlancesPlugin.get_limit_actioncCsby|j|d}Wn>tk
rPy|j|jd}Wntk
rJ|SXYnX|dj�dkS)z!Return the log tag for the alert.Z_logr�true)r,r�r$rk)r9r�r�Zlog_tagr;r;r<r�szGlancesPlugin.get_limit_logcCsN|dkr|j}|dkr"|d|}y|j|d|Stk
rH|SXdS)z~Return the configuration (header_) value for the current plugin.

        ...or the one given by the plugin_name var.
        NrQrR)r$r,r�)r9r�r�r$r�r;r;r<�get_conf_value%szGlancesPlugin.get_conf_valuecs*tdd��fdd�|jd|d�D�D��S)a0Return True if the value is in the show configuration list.

        If the show value is empty, return True (show by default)

        The show configuration list is defined in the glances.conf file.
        It is a comma separated list of regexp.
        Example for diskio:
        show=sda.*
        css|]
}|VqdS)Nr;)rM�jr;r;r<�	<genexpr>Csz(GlancesPlugin.is_show.<locals>.<genexpr>cs g|]}tj|j��j���qSr;)ro�	fullmatchrk)rMrY)r�r;r<rOCsz)GlancesPlugin.is_show.<locals>.<listcomp>�show)r�)r�r�)r9r�r�r;)r�r<�is_show7szGlancesPlugin.is_showcs*tdd��fdd�|jd|d�D�D��S)z�Return True if the value is in the hide configuration list.

        The hide configuration list is defined in the glances.conf file.
        It is a comma separated list of regexp.
        Example for diskio:
        hide=sda2,sda5,loop.*
        css|]
}|VqdS)Nr;)rMr�r;r;r<r�Psz(GlancesPlugin.is_hide.<locals>.<genexpr>cs g|]}tj|j��j���qSr;)ror�rk)rMrY)r�r;r<rOPsz)GlancesPlugin.is_hide.<locals>.<listcomp>Zhide)r�)r�r�)r9r�r�r;)r�r<�is_hideFs	zGlancesPlugin.is_hidecCs4|jd|d�gkr |j||d�S|j||d�SdS)z6Return True if the value should be displayed in the UIr�)r�N)r�r�r�)r9r�r�r;r;r<�
is_displaySszGlancesPlugin.is_displaycCsBy$|j|jd|j�dddSttfk
r<dSXdS)zJReturn the alias name for the relative header it it exists otherwise None.rR�aliasrN)r,r$rkr��
IndexError)r9r�r;r;r<rqZs$zGlancesPlugin.has_aliascCs|jt|j��gS)z8Return default string to display in the curse interface.)�curse_add_liner?r7)r9r�	max_widthr;r;r<�	msg_cursecszGlancesPlugin.msg_cursecCsZd}t|d�r|j}t|d�r$|j}|dk	rD||j||d�|d�}n||j|�|d�}|S)aIReturn a dict with all the information needed to display the stat.

        key     | description
        ----------------------------
        display | Display the stat (True or False)
        msgdict | Message to display (list of dict [{ 'msg': msg, 'decoration': decoration } ... ])
        align   | Message position
        F�
display_curse�alignN)r�)ZdisplayZmsgdictr�)r�r�r%r�)r9rr�r�Zalign_curserr;r;r<�get_stats_displaygs	

zGlancesPlugin.get_stats_displayr�cCs|||||d�S)abReturn a dict with.

        Where:
            msg: string
            decoration:
                DEFAULT: no decoration
                UNDERLINE: underline
                BOLD: bold
                TITLE: for stat title
                PROCESS: for process name
                STATUS: for process status
                NICE: for process niceness
                CPU_TIME: for process cpu time
                OK: Value is OK and non logged
                OK_LOG: Value is OK and logged
                CAREFUL: Value is CAREFUL and non logged
                CAREFUL_LOG: Value is CAREFUL and logged
                WARNING: Value is WARNING and non logged
                WARNING_LOG: Value is WARNING and logged
                CRITICAL: Value is CRITICAL and non logged
                CRITICAL_LOG: Value is CRITICAL and logged
            optional: True if the stat is optional (display only if space is available)
            additional: True if the stat is additional (display only if space is available after optional)
            spittable: Line can be split to fit on the screen (default is not)
        )�msgr�r�r�r�r;)r9r�r�r�r�r�r;r;r<r�~s
zGlancesPlugin.curse_add_linecCs
|jd�S)zGo to a new line.�
)r�)r9r;r;r<�curse_new_line�szGlancesPlugin.curse_new_linecCs||jkrgS|sd}n,||jkr@d|j|kr@|j|d}n|}||jkr�d|j|kr�|j|dtkr�t|j|d}nd}||jkr�d|j|kr�|j|dtkr�t|j|d}	nd}	||jko�d|j|ko�|j|ddk�r
|j||jd}
n
|j|}
|dk�r:|d	j|�|}d
}d}
n"|dj||d
d�|}d}d}
|	dk�rx|j|
|�|}nNd|j|k�r�|
j|jt|
�|j|dd�|�|}n|
jt|
�|�|}|j|dd�}|j|dd�}|j||d�|j|||d�gS)a�Return a list of dict messages with the 'key: value' result

          <=== width ===>
        __key     : 80.5%__
        | |       | |    |_ trailer
        | |       | |_ self.stats[key]
        | |       |_ separator
        | |_ 'short_name' description or key or nothing if display_key is True
        |_ header

        Instead of:
            msg = '  {:8}'.format('idle:')
            ret.append(self.curse_add_line(msg, optional=self.get_views(key='idle', option='optional')))
            msg = '{:5.1f}%'.format(self.stats['idle'])
            ret.append(self.curse_add_line(msg, optional=self.get_views(key='idle', option='optional')))

        Use:
            ret.extend(self.curse_add_stat('idle', width=15, header='  '))

        rQrwZunitrZrateTZtime_since_updateNz{}z{:.1f}{}z{}{}z
{:{width}}�)�widthz	{:5.1f}{}z{:>5}{}�
min_symbol)r�r�)rsr�r�)r�)r�r�)	r7r5�fields_unit_short�fields_unit_typer.�	auto_unitrr�r�)r9rsr�r�Zdisplay_keyZ	separatorZtrailerZkey_nameZ
unit_shortZ	unit_typer�Zmsg_itemZmsg_template_floatZmsg_templateZ	msg_valuer�r�r;r;r<�curse_add_stat�sP






zGlancesPlugin.curse_add_statcCs|jS)zGet the curse align.)r%)r9r;r;r<r�szGlancesPlugin.aligncCs
||_dS)zBSet the curse align.

        value: left, right, bottom.
        N)r%)r9r�r;r;r<r�	s�Kc		Cs�d}||kr||j|�d	�}d
ddd
ddddd�}x�t|�D]t}t|�||}|dkr>d}|dkrld}n|dkrxd}|r�|dkr�d}q�td|�}n|dkr�d}dj|||d�Sq>Wdj|�S)avMake a nice human-readable string out of number.

        Number of decimal places increases as quantity approaches 1.
        CASE: 613421788        RESULT:       585M low_precision:       585M
        CASE: 5307033647       RESULT:      4.94G low_precision:       4.9G
        CASE: 44968414685      RESULT:      41.9G low_precision:      41.9G
        CASE: 838471403472     RESULT:       781G low_precision:       781G
        CASE: 9683209690677    RESULT:      8.81T low_precision:       8.8T
        CASE: 1073741824       RESULT:      1024M low_precision:      1024M
        CASE: 1181116006       RESULT:      1.10G low_precision:       1.1G

        :low_precision: returns less decimal places potentially (default is False)
                        sacrificing precision for more readability.
        :min_symbol: Do not approach if number < min_symbol (default is K)
        r��M�G�T�P�E�Z�YNl lll li@ii)r�r�r�r�r�r�r�r�rrr|�r�ZMKz{:.{decimal}f}{symbol})Zdecimal�symbolz{!s})r�r�r�r�r�r�r�r�)r��reversedr�minr.)	r9rZ
low_precisionr�Zsymbols�prefixr�r�Zdecimal_precisionr;r;r<r�s6zGlancesPlugin.auto_unitrcCsHd}|dkstrd}n,||kr.td|j�}n||krDtd|j�}|S)z[Return the trend message.

        Do not take into account if trend < significant
        �-N� ZARROW_UPZ
ARROW_DOWN)r
rr)r9ZtrendZsignificantrr;r;r<�	trend_msgAs
zGlancesPlugin.trend_msgcs�fdd�}|S)z�Check decorator for update method.

        It checks:
        - if the plugin is enabled.
        - if the refresh_timer is finished
        csT|j�rJ|jj�s|j|jkrJ�|f|�|�}|jj|j��|jj�n|j}|S)N)rHr4Zfinishedr7rBr�r�r8)r9r�kwr)�fctr;r<�wrapperWsz/GlancesPlugin._check_decorator.<locals>.wrapperr;)r�r�r;)r�r<�_check_decoratorOs
zGlancesPlugin._check_decoratorcs�fdd�}|S)z+Log (DEBUG) the result of the function fct.csRt�}�||�}|j�}tjd|djj|djjtd�d��j||f�|S)Nz %s %s %s return %s in %s secondsrr)rr\r
r-r �__name__r!r#)rr�ZcounterrZduration)r�r;r<r�is


z4GlancesPlugin._log_result_decorator.<locals>.wrapperr;)r�r�r;)r�r<�_log_result_decoratorfsz#GlancesPlugin._log_result_decorator)N)N)Nr)Nr)N)Nr)rd)FN)NNN)NNN)N)rQ)rrr�TFrQNF)rrr�rQN)rQ)rQ)rQ)F)rQ)rQ)rQ)NN)NN)r�FFF)NrQTrQrQ)Fr�)r)Jr�r!�__qualname__�__doc__r=r>r@rBr8rCrDrHrIrKr)rPrZrJr_rarbrcrg�propertyrh�setterrirvrxr�r�rUr�r`r�r�r�r�r�r�r�r/r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rqr�r�r�r�r�r�r�r�r�r��staticmethodr;r;r;r<r0s�F






	


:(3


	
	
G







	


"
`
0
r)!r�rorAZglances.globalsrrZglances.compatrrrrrr	r
Zglances.actionsrZglances.historyrZglances.loggerr
Zglances.eventsrZglances.thresholdsrZ
glances.timerrrZglances.outputs.glances_unicoderr�r��objectrr;r;r;r<�<module>s2$