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: //usr/lib/python3.6/site-packages/glances/plugins/__pycache__/glances_network.cpython-36.pyc
3

Eo�c�=�
@s�dZddlmZddlZddlmZddlmZddlm	Z	ddl
mZddlZdd	d
�dd	d
�dd
d
�dd
d
�dd
d
�ddd
�ddd
�ddd
�dd
d
�ddd
�ddd
�d�Z
ddddd�iZdd d!d"�d#d$d!d"�gZGd%d&�d&e�ZdS)'zNetwork plugin.�)�unicode_literalsN)�getTimeSinceLastUpdate)�
GlancesPlugin)�n)�loggerzInterface name.�string)�description�unitz Interface alias name (optional).z,The received/input rate (in bit per second).Zbpsz)The sent/output rate (in bit per second).z6The cumulative received+sent rate (in bit per second).z@The number of bytes received through the interface (cumulative).�bytesz<The number of bytes sent through the interface (cumulative).zTThe cumulative number of bytes reveived and sent through the interface (cumulative).zSMaximum interface speed (in bit per second). Can return 0 on some operating-system.zIs the interface up ?�boolz$Number of seconds since last update.Zseconds)�interface_name�alias�rx�tx�cx�
cumulative_rx�
cumulative_tx�
cumulative_cx�speed�is_up�time_since_update�defaultz1.3.6.1.2.1.2.2.1.2z1.3.6.1.2.1.2.2.1.10z1.3.6.1.2.1.2.2.1.16)rrrrzDownload rate per secondzbit/s)�namerZy_unitrzUpload rate per secondcsNeZdZdZd
�fdd�	Zdd�Zejdd��Z�fd	d
�Z	ddd�Z
�ZS)�Pluginz1Glances network plugin.

    stats is a list
    Ncsftt|�j||ttgd�d|_|dk	r>|j|jddd�|_nd|_ddg|_	|j
�|jjd	�dS)
zInit the plugin.)�args�config�items_history_list�fields_descriptionZstats_init_valueTN�	hide_zeroF)rrrr)
�superr�__init__rrZ
display_curseZget_bool_valueZplugin_namer�hide_zero_fields�updateZ
refresh_timer�set)�selfrr)�	__class__��%/usr/lib/python3.6/glances_network.pyr Ns

zPlugin.__init__cCsdS)zReturn the key of the list.rr&)r$r&r&r'�get_keyfszPlugin.get_keyc8Csz|j�}|jdk�r�ytjdd�}Wn2tk
rV}ztjdj|��|jSd}~XnXi}ytj	�}Wn2t
k
r�}ztjdj|��WYdd}~XnXt|d�s�y
||_Wnt
tfk
r�YnX|jStd�}|}x�|D]�}|j|�s�||k�r�q�y�||j}||j}	||	}
||j|j}|	|j|j}||}
t|�|jt|��||||	||
|
||j||jd	|j�d
�}Wntk
�r�w�Yq�X|j|�q�W||_�n�|jdk�rny|jt|jdd�}Wn(tk
�r|jtd
dd�}YnXt|d��s<y
||_Wnt
tfk
�r6YnX�n2td�}|}�x|D�]}|j|��sf�qPy�|jdk�r�yttj|dd�j ���}Wnt!k
�r�|}YnXn|}t"||d�}t"||d�}	||	}
|t"|j|d�}|	t"|j|d�}||}
||j|�||||	||
|
d�	}Wntk
�rJ�wPYnX|j�|d<|j|��qPW||_||_|jS)zsUpdate network stats using the input method.

        :return: list of stats dict (one dict per interface)
        ZlocalT)Zpernicz+Can not get network interface counters ({})Nz)Can not get network interface status ({})�network_old�neti)rr
rrrrrrrrr�keyZsnmp)�snmp_oidZbulkrZwindows�rr)	rr
rrrrrrrr+���)#Zget_init_valueZinput_method�psutil�net_io_counters�UnicodeDecodeErrorr�debug�format�statsZnet_if_stats�OSError�hasattrr)�IOError�UnboundLocalErrorrZ
is_displayZ
bytes_recvZ
bytes_sentrZ	has_aliasZisuprr(�KeyError�appendZget_stats_snmpr,Zshort_system_name�str�base64Z	b16decode�upper�	TypeError�float)r$r4r0�eZ
net_statusrZnetwork_newr*rrrrrrZnetstatrr&r&r'r"ks�"








z
Plugin.updatecs(tt|�j�|j��x
|j�D]�}|djd�d}t|d|dd�}t|d|dd�}|j||dd	�}|j||d
d	�}|dkr�d|kr�|ddkr�|j||ddd
�}|dkr�d|kr�|ddkr�|j||ddd
�}||j||j	�dd<||j||j	�dd<q"WdS)zUpdate stats views.r�:rrr�rZ_rx)�headerZ_txZDEFAULTr)ZcurrentZmaximumrC�
decorationN)
rr�update_viewsZupdate_views_hiddenZget_raw�split�intZ	get_alertZviewsr()r$�iZif_real_nameZbps_rxZbps_txZalert_rxZalert_tx)r%r&r'rEszPlugin.update_viewsc	sJg}�js�j�r|S|d}djd|d�}|j�j|d��|jr�|jrhdjd�}|j�j|��q�djd	�}|j�j|��djd
�}|j�j|��nV|jr�djd�}|j�j|��n4djd�}|j�j|��djd
�}|j�j|���xN�j�D�]@�d�k�r"�ddk�r"�qt��fdd��j	D���rB�q�ddk�rd�dj
d�d}n�d}t|�|k�r�d||dd�}|j�r�d}d}nd}d}|j�r�j
t�d|��|}	�j
t�d|��|}
�j
t�d|�t�d|��|}n~�j
t�d�d|��|}	�j
t�d �d|��|}
�j
t�d�d|�t�d �d|��|}|j�j��dj||d�}|j�j|��|j�r�dj|�}|j�j|��n`dj|	�}|j�j|�j��j�dd!d"���dj|
�}|j�j|�j��j�d d!d"����qW|S)#z2Return the dict to display in the curse interface.�z
{:{width}}ZNETWORK)�widthZTITLEz{:>14}zRx+Txz{:>7}ZRxZTxzRx+Tx/szRx/szTx/srFcs$g|]}�j��j�|dd��qS)Zhidden)�itemr+�option)�	get_viewsr()�.0�f)rHr$r&r'�
<listcomp>Msz$Plugin.msg_curse.<locals>.<listcomp>r
NrrAr�_��rB�brrrrrrD)rKr+rL)r4Zis_disabledr3r:Zcurse_add_lineZ
network_cumulZnetwork_sumZsorted_stats�allr!rF�lenZbyteZ	auto_unitrGZcurse_new_linerMr()r$rZ	max_width�retZname_max_width�msgZif_nameZto_bitr	rrZsxr&)rHr$r'�	msg_curse!sv





,""

"
(zPlugin.msg_curse)NN)NN)�__name__�
__module__�__qualname__�__doc__r r(rZ_log_result_decoratorr"rErY�
__classcell__r&r&)r%r'rHsr)r]Z
__future__rr<Z
glances.timerrZglances.plugins.glances_pluginrZglances.compatrZglances.loggerrr/rr,rrr&r&r&r'�<module>
s8