????

Your IP : 216.73.217.84


Current Path : /opt/cloudlinux/venv/lib64/python3.11/site-packages/clsummary/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/clsummary/__pycache__/net_acct.cpython-311.pyc

�

�Ov���	��dZddlZddlmZmZmZdZeddh��ZdZ	de
deed	efd
�Z
dded	ee
effd�Z	dd
e
deeed	ee
effd�Zedfde
deeed	ee
effd�ZdS)uS
Telemetry collector for LVE Traffic Accounting (CLOS-4341).

Parses /proc/lve/list and produces a small set of metrics that let us answer:
- does this kernel expose net accounting at all (NETO/NETI columns present)?
- how many user LVEs exist and how many actually accumulated traffic?
- what's the cumulative NETO/NETI volume across user LVEs on this host?

/proc/lve/list contains two non-user LVE rows we exclude from all aggregates:
- *default* (user_id = UINT_MAX) — kernel catch-all for processes not
  attached to any specific LVE (sshd, systemd, dnf, ...). Has non-zero
  traffic on essentially every running CL host.
- *root* (user_id = 0) — LVE container for root (uid 0). Not a hosting user.

After exclusion the metrics describe user hosting activity, and lves_total
matches the count seen by `lvectl list` and the panel's user list.
�N)�Dict�Iterable�Optionalz/proc/lve/listl����net_acct_kernel_supported�net_acct_lves_total�net_acct_lves_with_traffic�net_acct_total_neto_bytes�net_acct_total_neti_bytes�lve_id_field�excluded�returnc��|�dd��d}	t|��|vS#t$rYdSwxYw)z�True if the LVE row's user_id is in the excluded set.

    LVE ids in /proc/lve/list use the form "<lvp_id>,<user_id>" (e.g. "0,1002")
    or just "<user_id>" on older kernels. Malformed rows are excluded.
    �,����T)�rsplit�int�
ValueError)rr
�user_ids   �py/clsummary/net_acct.py�_user_id_excludedr+sV���!�!�#�q�)�)�"�-�G���7�|�|�x�'�'�������t�t����s�/�
=�=�	supportedc��|ddddd�S)Nrr�)rs r�
_empty_resultr8s ��%.� �&'�%&�%&�����content�
skip_user_idsc��|st��S|���}|st��S|d}d|vr|�dd��d}|�d��}	|�d��}|�d��}n#t$rt��cYSwxYwtt��}|r|�|��d}d}	d}
d}|dd�D]�}|���s�|�d��}
t|
��t||��kr�Nt|
d|��r�e	t|
|��}t|
|��}n#t$rY��wxYw|dz
}|dks|dkr|	dz
}	|
|z
}
||z
}��d||	|
|d�S)	u�Parse /proc/lve/list text and return the 5 net_acct metrics.

    Format of /proc/lve/list:
        <version>:<TAB>LVE<TAB>...<TAB>NETO<TAB>NETI    # header
        <lve_id><TAB>...<TAB><neto><TAB><neti>          # one row per LVE

    The leading "<version>:" prefix is optional/version-dependent; we tolerate
    its presence and absence. NETO/NETI are cumulative byte counters; their
    lowercase counterparts lNETO/lNETI are limit columns and ignored here.

    skip_user_ids — additional user-id slots to exclude beyond the standard
    root/default. Used by cloudlinux-summary to skip its own transient
    self-LVE (created via _run_self_in_lve) which would otherwise inflate
    counts by 1 on every collection run.

    On any structural problem (no header, missing NETO/NETI columns, malformed
    rows) we treat the kernel as not supporting net accounting and return a
    zeroed result.
    r�:r�	�NETO�NETINr)
r�
splitlines�split�indexr�set�NON_USER_LVE_IDS�update�strip�len�maxrr)rr�lines�header�columns�neto_idx�neti_idx�excluded_ids�total�with_traffic�sum_neto�sum_neti�raw�fields�neto�netis                r�parse_proc_lve_listr<Bs��.��������� � �E�������
�1�X�F�
�f�}�}����c�1�%�%�a�(���l�l�4� � �G���=�=��(�(���=�=��(�(�������������������'�(�(�L��+����M�*�*�*�
�E��L��H��H��Q�R�R�y�����y�y�{�{�	�����4�����v�;�;�#�h��1�1�1�1���V�A�Y��5�5�	��	��v�h�'�(�(�D��v�h�'�(�(�D�D���	�	�	��H�	����	��
���!�8�8�t�a�x�x��A��L��D����D����&'�$�&2�%-�%-���s$�3*B�B9�8B9�*F
�

F�F�pathc�<�tj�|��st��S	t	|ddd���5}|���}ddd��n#1swxYwYn#t$rt��cYSwxYwt||���S)z�Read /proc/lve/list and return parsed metrics.

    Missing file (older kernels, non-CL kernels, Ubuntu without lve) yields
    kernel_supported=0 and zeros for the rest.
    �rzutf-8�replace)�encoding�errorsN)r)�osr=�existsr�open�read�OSErrorr<)r=r�fhrs    r�collect_net_acct_metricsrI�s����7�>�>�$���������
�$��g�i�
@�
@�
@�	 �B��g�g�i�i�G�	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 ����	 �	 �	 �	 ������������������w�m�D�D�D�Ds5�A/�A#�A/�#A'�'A/�*A'�+A/�/B
�	B
)r)N)�__doc__rC�typingrrr�
PROC_LVE_LIST�	frozensetr)�METRIC_NAMES�strr�boolrrr<rIrrr�<module>rQsh����$
�	�	�	�+�+�+�+�+�+�+�+�+�+� �
��9�a��_�-�-����
�C�
�8�C�=�
�T�
�
�
�
���S���c�3�h������.2�M�M�
�M��H�S�M�*�M�
�#�s�(�^�M�M�M�M�b�-1�E�E�

�E��H�S�M�*�E�
�#�s�(�^�E�E�E�E�E�Er