Hacked By AnonymousFox

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

�

)�f� ���ddlZddlmZmZmZddlmZddlmZm	Z	m
Z
ddlmZej
d��ZGd�de��Zd	�Zd
�Zd�ZGd�d
e��ZdS)�N)�List�Dict�Optional)�	mysql_lib)�	db_access�dblogin_cplogin_pairs�cpusers)�run_command�ustatec��eZdZdS)�MySQLOperationalErrorN)�__name__�
__module__�__qualname__���~/builddir/build/BUILDROOT/lve-stats-4.2.8-1.el8.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/lvestats/lib/ustate.pyr
r
s�������Drr
c
���|�d��}|�d��}|���}ddd���fd�|D��}i}d}t|��D�]h\}}|s�	|�dt|��dz
��}t|��t|��ko|d���}	|	s<|�dt|��d	z
��}|�dd
��t|��t|��kr@t�d|dd
|td|dz
��|dz�ii����nctt||����}
|	rqt|
�d����}	|
d=n#t$rYnwxYw|
||<t��||d<||�dd�����|
�dd��|
�dd��|
�dd��|
�dd��	|
||dt|
�d����<��##ttf$r3}t�dt|����Yd}~��bd}~wwxYw|S)a)
    pars /usr/sbin/lveps -c 1 -p -d -n result
    example returned data:
    {504:
        {'CPU': '26%', 'IO': '0', 'MEM': '1', 'EP': '0', 'IOPS': 'N/A', 'PNO': '3', 'TNO': '3', 'TID':
            {4400:
                {'CPU': '26%', 'IO': 'N/A', 'MEM': '1', 'CMD': 'md5sum', 'IOPS': 'N/A'},
            4381:
                {'CPU': '0%', 'IO': 'N/A', 'MEM': '1', 'CMD': 'su', 'IOPS': 'N/A'},
            4382:
                {'CPU': '0%', 'IO': 'N/A', 'MEM': '1', 'CMD': 'bash', 'IOPS': 'N/A'}}},
    500:
        {'CPU': '13%', 'IO': '0', 'MEM': '1', 'EP': '0', 'IOPS': 'N/A', 'PNO': '3', 'TNO': '3', 'TID':
            {4266:
                {'CPU': '0%', 'IO': 'N/A', 'MEM': '1', 'CMD': 'su', 'IOPS': 'N/A'},
            4299:
                {'CPU': '13%', 'IO': 'N/A', 'MEM': '1', 'CMD': 'cat', 'IOPS': 'N/A'},
            4267:
                {'CPU': '0%', 'IO': 'N/A', 'MEM': '1', 'CMD': 'bash', 'IOPS': 'N/A'}}}}

    example of data manipulation:
    getting a list of user id
    >>> lveps_data = _pars_lveps()
    >>> user_id_list = lveps_data.keys()
    a list of processes tid particular user id 504
    >>> user_tid_list = lveps_data[504]['TID'].keys()
    getting CPU load user
    >>> user_cpu = lveps_data[504]['CPU']
    getting CPU load specific process
    >>> lveps_data[504]['TID'][4400]
    �
r�CPU�CMD)�SPEED�COMc�<��g|]}��||����Sr)�get)�.0�col_name�replace_cols  �r�
<listcomp>z_pars_lveps.<locals>.<listcomp><s'���U�U�U�H�K�O�O�H�h�7�7�U�U�UrN���zlveps output was incorrect: %s�data�lveps_lines��)�extra�ID�TID�PID�EP�PNO�TNOzCan't parse lveps output: %s)�split�pop�	enumerate�len�isdigit�insert�log�error�max�dict�zip�int�KeyError�
ValueError�str)
�lveps_outputr$�header_line�columns_name�
lveps_data�user_id�lveps_line_index�
lveps_line�lveps_line_splited�has_id�lveps_dict_line�ers
            @r�_pars_lvepsrHs)���@�$�$�T�*�*�K��/�/�!�$�$�K��$�$�&�&�L�!�%�0�0�K�U�U�U�U��U�U�U�L��J��G�(1�+�(>�(>�!B�!B�$��*��	��'�-�-�d�C��4E�4E�a�4G�H�H���)�*�*�c�,�.?�.?�?�d�EW�XY�EZ�Eb�Eb�Ed�Ed���	-�!+�!1�!1�$��L�8I�8I�!�8K�!L�!L���%�%�a��,�,�,��!�"�"�c�,�&7�&7�7�7��I�I�6�
����C��;K�a�;O�4P�4P�Rb�eg�Rg�4g�(h�i�Kk�I�
l�
l�
l��E��s�<�1C�D�D�E�E���	B��/�-�-�d�3�3�4�4�G�
�#�E�*�*���
�
�
���
����"1�J�w��)-���J�w���&��w��#�#�E�4�0�0�0�0�����d�+�+�+�����t�,�,�,�����t�,�,�,�����d�+�+�+�
B�N]�
�7�#�E�*�3��/B�/B�5�/I�/I�+J�+J�K�K����)�
B�
B�
B��	�	�8�#�a�&�&�A�A�A�A�A�A�A�A�����
B�����s*�/F3�3
G�?G�1J	�	K
�(K�K
c�<�t��}t|��S�N)�_get_lveps_outputrH�r=s r�	get_lvepsrMes��$�&�&�L��|�$�$�$rc�T�tgd�d���}|�dd��S)N)z/usr/sbin/lvepsz-c�1z-pz-dz-nz-oz;id:10,ep:10,pno:10,pid:15,tno:5,tid:15,cpu:7,mem:15,com:256F)�convert_to_strzutf-8�replace)r
�decoderLs rrKrKjsE��� j� j� j�����L����w�	�2�2�2rc�F�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
dd
�Zd	S)�SQLSnapshotc�`�d|_t��|_t��|_dSrJ)�_mysql_connr7�_dblogin_cplogin_map�set�	_db_users��selfs r�__init__zSQLSnapshot.__init__us%�����$(�F�F��!�������rc�.�|���|SrJ)�connectrZs r�	__enter__zSQLSnapshot.__enter__zs���������rc�.�|���dSrJ)�close)r[�exc_type�exc_val�exc_tbs    r�__exit__zSQLSnapshot.__exit__~s���
�
�����rc�<�t��}|d}|d}|�dd��}tj|||dd���}	|���|_dS#tj$r"}tt|����|�d}~wwxYw)	zB
        Obtain access data and connect to mysql database
        �login�pass�host�	localhostT�utf8mb4)ri�user�passwd�use_unicode�charsetN)	rrr�MySQLConnectorr^rV�
MySQLErrorr
r<)r[�access�mysql_login�
mysql_pass�
mysql_host�	connectorrGs       rr^zSQLSnapshot.connect�s��������W�o���F�^�
��Z�Z���4�4�
��,�*�;�4>�D�5>�@�@�@�	�	7�(�0�0�2�2�D������#�	7�	7�	7�'��A���/�/�Q�6�����	7���s�A*�*B�9B�Bc�F�tt����|_dS)z;
        Refresh <database user>:<system user> map
        N)r7rrWrZs r�_refresh_mapzSQLSnapshot._refresh_map�s!��%)�)>�)@�)@�$A�$A��!�!�!rc�8�|j���dS)z(
        Close Mysql connection
        N)rVrarZs rrazSQLSnapshot.close�s��	
���� � � � � rc�(�t��}	|j���}|�d��|���}n?#t
tjf$r&}t�	d|���Yd}~nd}~wwxYw|S)NzSHOW FULL PROCESSLISTzCError occurred during executing the `SHOW FULL PROCESSLIST` command)�exc_info)
�tuplerV�cursor�execute�fetchall�UnicodeDecodeErrorrrqr4�warning)r[�resultr}rGs    r�_raw_processlistzSQLSnapshot._raw_processlist�s�������	k��%�,�,�.�.�F��N�N�2�3�3�3��_�_�&�&�F�F��"�I�$8�9�	k�	k�	k��K�K�]�hi�K�j�j�j�j�j�j�j�j�����	k�����
s�AA�B�)B
�
Bc�$�t��}|���D]l}|d}|d}|d}|dpd}|dkr�+|||g}|�|t����}|�|��|||<�m|S)zN
        Group processlist by database user name
        :rtype: dict
        r �r%�r"�Sleep)r7r�r�list�append)	r[�process_snapshot�	sql_tuple�db_username�sql_cmd�sql_time�	sql_query�
snapshot_line�grouped_by_users	         r�_get_sql_process_listz!SQLSnapshot._get_sql_process_list�s���
 �6�6���.�.�0�0�	<�	<�I�#�A�,�K���l�G� ��|�H�!�!��*��I��'�!�!��$�h�	�:�M�.�2�2�;����G�G�O��"�"�=�1�1�1�,;��[�)�)��rNc���|���}t|�����|jz
}|rp|���t
�dtt|����dd���|D]}|j�	|���t��}|pt��p
t��}t|�����D]a\}}|j
�|��}	|	�@|	|vr<|�|	t����}
|
�|��|
||	<�b|S)z�
        :param cplogin_lst: a list of users to retrieve data;
            None if the data is returned for all users registered in the control panel
        :return: sql queries for each user
        z>New database user(s) %s detected; database users map refreshedr ���)r�rX�keysrYrxr4�debugr<r��addr7r	�itemsrWr�extend)r[�cplogin_lstr��new_db_users�new_db_user�sql_snapshot�cplogin_lst_r��sql_snap�cp_username�	sql_snap_s           rrzSQLSnapshot.get�sg�� �5�5�7�7���+�0�0�2�2�3�3�d�n�D���	0��������I�I�5�69�$�|�:L�:L�6M�6M�a�PR�d�6S�
U�
U�
U� ,�
0�
0����"�"�;�/�/�/�/��v�v��"�9�g�i�i�9�4�6�6��%)�*:�*@�*@�*B�*B�%C�%C�	6�	6�!�K���3�7�7��D�D�K��&�;�,�+F�+F�(�,�,�[�$�&�&�A�A�	�� � ��*�*�*�,5��[�)���rrJ)rrrr\r_rer^rxrar�r�rrrrrTrTts����������
������7�7�7� B�B�B�!�!�!���� � � �(�����rrT)�logging�typingrrr�clcommonr�clcommon.cpapirrr	�clcommon.utilsr
�	getLoggerr4�	Exceptionr
rHrMrK�objectrTrrr�<module>r�s������'�'�'�'�'�'�'�'�'�'�������D�D�D�D�D�D�D�D�D�D�&�&�&�&�&�&��g���!�!��	�	�	�	�	�I�	�	�	�L�L�L�^%�%�%�
3�3�3�d�d�d�d�d�&�d�d�d�d�dr

Hacked By AnonymousFox1.0, Coded By AnonymousFox