????

Your IP : 3.19.208.67


Current Path : /proc/self/root/lib/python3.6/site-packages/glances/plugins/__pycache__/
Upload File :
Current File : //proc/self/root/lib/python3.6/site-packages/glances/plugins/__pycache__/glances_cpu.cpython-36.pyc

3

Eo�c�=�@sDdZddlmZddlmZddlmZddlmZm	Z	m
Z
ddlmZ
ddlmZddlZd	d
d�dd
d�d
d
d�dd
d�dd
d�dd
d�dd
d�dd
d�dd
d�dddddd�dddddd�dddddd�dddddd�d dd�d!d"d�d#�Zd$d%d&d'�d
d(id
d(id)d*d+d,�d-�Zd.d/d0d1�d2d3d0d1�gZGd4d5�d5e�ZdS)6zCPU plugin.�)�getTimeSinceLastUpdate)�iterkeys)�cpu_percent)�LINUX�WINDOWS�SUNOS)�Plugin)�
GlancesPluginNz)Sum of all CPU percentages (except idle).�percent)�description�unitzrpercent time spent in kernel space. System CPU time is the time spent running code in the Operating System kernel.z�CPU percent time spent in user space. User CPU time is the time spent on the processor running your program's code (or code in libraries).zP*(Linux)*: percent time spent by the CPU waiting for I/O operations to complete.zA*(Windows)*: time spent servicing deferred procedure calls (DPCs)z�percent of CPU used by any program. Every program or task that runs on a computer system occupies a certain amount of processing time on the CPU. If the CPU has completed all tasks it is idle.z�*(Linux and BSD)*: percent time spent servicing/handling hardware/software interrupts. Time servicing interrupts (hardware + software).z�*(Unix)*: percent time occupied by user level processes with a positive nice value. The time the CPU has spent running users' processes that have been *niced*.z}*(Linux)*: percentage of time a virtual CPU waits for a real CPU while the hypervisor is servicing another virtual processor.z�number of context switches (voluntary + involuntary) per second. A context switch is a procedure that a computer's CPU (central processing unit) follows to change from one task (or process) to another while ensuring that the tasks do not conflict.ZnumberT�KZctx_sw)rrZrateZ
min_symbolZ
short_namez number of interrupts per second.ZinterzOnumber of software interrupts per second. Always set to 0 on Windows and SunOS.Zsw_intz8number of system calls per second. Always 0 on Linux OS.Zsys_callzTotal number of CPU core.z$Number of seconds since last update.Zseconds)�total�system�user�iowait�dpc�idle�irq�nice�steal�ctx_switches�
interrupts�soft_interrupts�syscalls�cpucore�time_since_updatez1.3.6.1.4.1.2021.11.9.0z1.3.6.1.4.1.2021.11.10.0z1.3.6.1.4.1.2021.11.11.0)rrrz1.3.6.1.2.1.25.3.3.1.2z1.3.6.1.4.1.789.1.2.1.3.0z1.3.6.1.4.1.789.1.2.1.5.0z1.3.6.1.4.1.789.1.2.1.6.0)rrr)�default�windows�esxiZnetapprzUser CPU usage�%)�namerZy_unitrzSystem CPU usagecs\eZdZdZd�fdd�	Zejejdd���Zdd�Z	d	d
�Z
�fdd�Zdd
d�Z�Z
S)rzxGlances CPU plugin.

    'stats' is a dictionary that contains the system-wide CPU utilization as a
    percentage.
    NcsXtt|�j||ttd�d|_yt|jd�j�d|_	Wnt
k
rRd|_	YnXdS)zInit the CPU plugin.)�args�config�items_history_list�fields_descriptionT)r"�log�N)�superr�__init__r$r%Z
display_curse�
CorePluginr"�update�nb_log_core�	Exception)�selfr"r#)�	__class__��!/usr/lib/python3.6/glances_cpu.pyr)�s
zPlugin.__init__cCs<|jdkr|j�}n|jdkr(|j�}n|j�}||_|jS)z(Update CPU stats using the input method.ZlocalZsnmp)Zinput_method�update_local�update_snmp�get_init_value�stats)r.r5r0r0r1r+�s



z
Plugin.updatecCs�|j�}tj�|d<tjdd�}x|jD]}t||�||<q(Wtj�}td�|d<|j	|d<t
|d�s�xP|jD]}d||<qnWn8x6|jD],}t||�d	k	r�t||�t|j|�||<q�W||_|S)
zUpdate CPU stats using psutil.rg)ZintervalZcpurr�
cpu_stats_oldrN)r4r�get�psutil�cpu_times_percent�_fields�getattr�	cpu_statsrr,�hasattrr6)r.r5r9�statr<r0r0r1r2�s 	

zPlugin.update_localcCsl|j�}|jdkr�y|jt|jdd�}Wntk
rF|j�YnXd|d<d|d<x>|D]6}|jd�r^|dt|d	�7<|dd
7<q^W|ddkr�|d|d|d<d|d|d<d|d|d<n�y|jt|jd
�}Wn&tk
�r|jtdd
�}YnX|ddk�r4|j�|jSx"t	|�D]}t||�||<�q>Wd|d|d<|S)zUpdate CPU stats using SNMP.rrT)�snmp_oidZbulkrr,rr
z	percent.3r'�dr)r?r�)rr)
r4Zshort_system_nameZget_stats_snmpr?�KeyError�reset�
startswith�floatr5r)r.r5r<�c�keyr0r0r1r3�s6


zPlugin.update_snmpcs�tt|�j�x4dD],}||jkr|j|j||d�|j|d<qWx4dD],}||jkrJ|j|j||d�|j|d<qJWx@dD]8}||jkr�|j|j|d
|jd|d�|j|d<q�Wx$dD]}||jkr�d|j|d<q�WdS)zUpdate stats views.rrrrr)�header�
decorationrrr@r)ZmaximumrHrrrrrrT�optionalN)rrrrr)r)r)rrrrrrrr)r(r�update_viewsr5Z
get_alert_logZviewsZ	get_alert)r.rG)r/r0r1rKs

"

"

*

zPlugin.update_viewsc	Cs�g}|js|jjs|j�r |Sd|jk}djd�}|j|j|d��|jd�}|jd�}|dksj|dkrpd}n||}dj|j|��}|j|j|��dj|jd	�}|j|j||j	d	d
d���d|jko�|�r,d
jd�}|j|j||j	ddd�d��dj|jd�}|j|j||j	ddd�d��t
�rRt�rR|j|j
dddd��|j|j��|�s||j|j
ddd��n d|jk�r�|j|j
ddd��|j|j
dddd��|j|j
dddd��|j|j��|�s�|j|j
ddd��n|j|j
ddd��|j|j
dddd��t
�rDt�rD|j|j
dddd��n|j|j
dddd��|j|j��d|jk�r�|j|j
ddd��n d|jk�r�|j|j
ddd��|j|j
dddd��t�s�|j|j
dddd��|S) z%Return the list to display in the UI.rz{}ZCPUZTITLErNz {:4}z{:5.1f}%rrI)rGZoptionrz  {:8}rJ)rJz{:4.1f}%r�z  )�widthrH)rMr�rZcorerrrrrr)r5r"ZpercpuZis_disabled�format�appendZcurse_add_lineZ	get_trendZ	trend_msgZ	get_viewsrr�extendZcurse_add_statZcurse_new_liner)	r.r"Z	max_width�retZidle_tag�msgZ
trend_userZtrend_systemZ	trend_cpur0r0r1�	msg_curse6s\




zPlugin.msg_curse)NN)NN)�__name__�
__module__�__qualname__�__doc__r)r	Z_check_decoratorZ_log_result_decoratorr+r2r3rKrT�
__classcell__r0r0)r/r1r�sA.r)rXZ
glances.timerrZglances.compatrZglances.cpu_percentrZglances.globalsrrrZglances.plugins.glances_corerr*Zglances.plugins.glances_pluginr	r8r%r?r$r0r0r0r1�<module>
sr