Hacked By AnonymousFox

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

�

)�fP6����ddlmZddlmZddlZddlZddlZddlZddlZddlZddl	m
Z
mZddlm
Z
mZmZddlmZddlmZdZGd	�d
e��ZGd�de��ZGd
�de��ZdS)�)�absolute_import)�divisionN)�run_command�ExternalProgramFailed)�atomic_write_csv�atomic_write_str�deserialize_lve_id)�LveStatsPlugin)�mempages_to_bytes�iseletskc�8�eZdZdd�Zd�Zed���Zd�ZdS)�	FileSaver�
/var/lve/infoc�F�||_tjd��|_dS)z:type fname: strzplugin.file_saverN��fname�logging�	getLogger�log��selfrs  ��/builddir/build/BUILDROOT/lve-stats-4.2.8-1.el8.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/lvestats/plugins/generic/persistors.py�__init__zFileSaver.__init__s ����
��$�%8�9�9�����c��	t|j|��dS#t$r0}|j�d|j�d|����Yd}~dSd}~wwxYw)z9
        :type output: list
        :rtype: None
        �Error during saving the "�" file: N)rr�OSErrorr�error)r�output�es   r�writezFileSaver.writes|��
	P��T�Z��0�0�0�0�0���	P�	P�	P��H�N�N�N�t�z�N�N�1�N�N�O�O�O�O�O�O�O�O�O�����	P���s��
A�%A�Ac��|j|jkpR|j|jkpB|j|jkp2|j|jkp"|j|jkp|jdz|jk}|dkr|j|jk}nd}|p|S)z�
        :type LVE_VERSION: int
        :type lve_usage: lvestats.plugins.generic.aggregators.AggregatedLveUsage
        :type lve_stat: lvestat.LVEStat
        ��F)�lep�cpu�lcpu�lmem�lmemphy�lnproc�io�liops)�lve_stat�	lve_usage�LVE_VERSION�res1�res2s     r�compare_limitszFileSaver.compare_limits)s���
�L�I�M�)�
/��L�I�N�*�
/��M�Y�^�+�
/�
��	� 1�1�
/�
�O�y�/�/�	
/�

�K�$��)�,�.�
	
���?�?��>�Y�_�4�D�D��D��|�t�rc�`�|d}|�di��}|d}g}|���D�]"\}}g}|�|t|j��t|j��t|j��t|j��t|j��t|j	��t|j
��t|j��t|j��t|j
��t|j��t|j��t|j��t|j��dt|j��dzt|j��dzg��|dkr;|�t|j��t|j��g��|�dgdt-|��z
z��|�|j��|�|j��|�|j��|�|����$|���D�]�\}}	t7|��\}}
|
r�|�r�||v�rd|vr|j�d	���B|�|	|d|�
���rAg}|�|dt|	j��dt|	j��dt|	j	��ddt|	j��ddt|	j��ddddt|	j��g��|dkr)|�t|	j��dg��|�dgdt-|��z
z��|�d��|�d��|�d��|�|�����|� |��dS)z:type lve_data: dictr0�lve_usage_5s�statsrr$���z/No defaults collected to compare with, skipping)r.r/r0N)!�get�items�extend�int�mepr&�	cpu_usager(�	mem_usager)�	mem_fault�	mep_faultr*�memphy�memphy_faultr+�nproc�nproc_fault�io_usager,r-�iops�len�append�	cpu_fault�
iops_fault�io_faultr	r�warningr3r'r")r�lve_datar0�usages�new�output_rows�lve_id�v�data�new_lvestat�is_resellers           r�executezFileSaver.execute>s����}�-�����n�b�1�1���w����������!	%�!	%�I�F�A��D��K�K���A�E�
�
��A�E�
�
��A�K� � ��A�F����A�K� � ��A�F����A�K� � ��A�K� � ��A�I����A�H�
�
��A�N�#�#��A�H�
�
��A�G����A�M�"�"���A�J����%��A�D�	�	�4��%!�
"�
"�
"�&�a���������L�L����K�K�!�"�"�"�
�K�K���b��T���l�+�,�,�,�
�K�K���$�$�$��K�K���%�%�%��K�K��
�#�#�#����t�$�$�$�$�#&�9�9�;�;�/	-�/	-��F�K�"4�V�"<�"<��F�K��
���)
-�&��.�.��F�?�?��H�$�$�%V�W�W�W���&�&��v�a�y�^i�&�j�j�!-��D��K�K����K�O�,�,���K�O�,�,���K�,�-�-����K�/�0�0����K�.�/�/������K�N�+�+�%!-�.�.�.�&#�a�'�'������ 1�2�2��%� � � ��K�K���b��T���l� 3�4�4�4��K�K��N�N�N��K�K��N�N�N��K�K��N�N�N��&�&�t�,�,�,���
�
�;�����rN)r)�__name__�
__module__�__qualname__rr"�staticmethodr3rX�rrrrsi������:�:�:�:�
P�P�P�����\��(Y �Y �Y �Y �Y rrc�l�eZdZdZdd�Zd�Zd�Zed���Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�ZdS)�MySQLTopFileSaverz/usr/sbin/dbtop�/var/lve/cloudlinux_dbtop.jsonc��||_d|_tjd��|_|���|_|jr|���dSdS)Nz/var/lve/governor.tsz"plugin.cloudlinux_dbtop_file_saver)r�touch_fnamerrr�_check_dbtop_exist�_dbtop_exist�_create_touch_filers  rrzMySQLTopFileSaver.__init__�se����
�1����$�%I�J�J��� �3�3�5�5�����	&��#�#�%�%�%�%�%�	&�	&rc�n�|�|j��|�|j��dS)z*
        Try delete created files
        N)�_try_unlink_filerbr�rs r�__del__zMySQLTopFileSaver.__del__�s7��	
���d�.�/�/�/����d�j�)�)�)�)�)rc	��|j�d|z��	tj|��dS#t$rI}|jdkr3|j�d|�dt|������Yd}~dSYd}~dSd}~wt$r8}|j�d|�dt|������Yd}~dSd}~wwxYw)zb
        Try delete file; push warning to log if wrong
        :param fname: path to file
        zDelete %s  file�z
Can't delete z file; N)	r�debug�os�unlinkr�errnorN�str�SystemError)rrr!s   rrgz"MySQLTopFileSaver._try_unlink_file�s��
	
����(�5�0�1�1�1�	L��I�e��������	P�	P�	P��w�!�|�|��� � � ����s�1�v�v�v�!N�O�O�O�O�O�O�O�O�O��|�|�|�|�|������	L�	L�	L��H����E�E�E�3�q�6�6�6�J�K�K�K�K�K�K�K�K�K�����	L���s �5�
C�8B�
C�-C�Cc�:�	t|��S#t$r|ddvrt|dd���dzcYS|ddvrt|dd���dzdzcYS|ddvr"t|dd���dzdzdzcYSYdSwxYw)z6
        :type value: str
        :rtype: int
        ���)�k�K�kb�KbNr$)�m�M�mb�Mb)�g�G�gb�Gb)r=�
ValueError)�values r�_convert_to_bytesz#MySQLTopFileSaver._convert_to_bytes�s���	<��u�:�:����	<�	<�	<��R�y�2�2�2��5��"��:����-�-�-�-��r��4�4�4��5��"��:����-��4�4�4�4��r��4�4�4��5��"��:����-��4�t�;�;�;�;�5�4�4�	<���s��.B�'B�**B�Bc�f�|j�d|jz��	tjd��j}	t
jd��j}n)#t$rt
jd��j}YnwxYwt|jd��5	ddd��n#1swxYwYtj|j||��tj
|jd��dS#ttf$r9}|j�d|jt#|����Yd}~dSd}~wwxYw)zz
        Create file to touching; file owned by nobody and accessible to change
        everyone
        :return:
        zCreate %s file�nobody�nogroup�wNi�zCan't create %s file; %s)rrlrb�pwd�getpwnam�pw_uid�grp�getgrnam�gr_gid�KeyError�openrm�chown�chmod�IOErrorrrrp)r�uid�gidr!s    rrez$MySQLTopFileSaver._create_touch_file�s���	
����'�$�*:�:�;�;�;�	Q��,�x�(�(�/�C�
5��l�8�,�,�3�����
5�
5�
5��l�9�-�-�4����
5����
�d�&��,�,�
�
��
�
�
�
�
�
�
�
�
�
�
����
�
�
�
��H�T�%�s�C�0�0�0��H�T�%�u�-�-�-�-�-����!�	Q�	Q�	Q��H�N�N�5�t�7G��Q���P�P�P�P�P�P�P�P�P�����	Q���s^�C&�A�C&�#A>�;C&�=A>�>C&�B$�C&�$B(�(C&�+B(�,8C&�&D0�7.D+�+D0c��d}d}|dvr||fSd|vrd}nd|vrd}n	d|vrd}nd}	t|�d��d	��}n2#ttf$r|j�d
|��YnwxYw||fS)z=
        :rtype: (str, int)
        :type value: str
        �-r)r�r8r'�readr"�unknown�/rsz could not parse cause string: %s)r=�splitr�r�rr)rr��cause_of_restrict�time_of_restricts    r�_parse_dbtop_causez$MySQLTopFileSaver._parse_dbtop_cause�s���
 �����I���$�&6�6�6��E�>�>� %���
�u�_�_� &���
��
�
� '��� )��	F�"�5�;�;�s�#3�#3�B�#7�8�8�����*�%�	F�	F�	F��H�N�N�=�u�E�E�E�E�E�	F���� �"2�2�2s�(A�,A=�<A=c��|j�d|jz��tj�|j��S)zO
        Check if dbtop util exist
        :return bool: True if exist
        zCheck exist %s file)rrl�dbtoprm�path�existsrhs rrcz$MySQLTopFileSaver._check_dbtop_exist�s6��
	
����,�t�z�9�:�:�:��w�~�~�d�j�)�)�)rc	��	|���}nR#t$rE}dt|��vr(|j�dt|����icYd}~Sd}~wwxYwi}|dd�D�]}	|���\}}}}}	nM#t$r@}|j�dt|��t|����Yd}~�dd}~wwxYw|�|	��\}
}t|�d��d��|�	|�d��d��|�	|�d��d��z|
|d�||<��|S)	zT
        Try obtain and parse data from dtop -c output
        :rtype: dict
        zCan't connect to socketzdbtop execution is failed: %sN�zCan't unpack output: %s
%sr�r)r'r,r�r�)
�_get_dbtop_outputrrprrr�r�r�r=r�)r�dbtop_outputr!�resultr �userr'r�r"�causer�r�s            r�get_dbtop_infoz MySQLTopFileSaver.get_dbtop_infos���
	��1�1�3�3�L�L��$�	�	�	�(��A���6�6�����>��A���G�G�G��I�I�I�I�I�I�����	������"�1�2�2�&�	6�	6�F�
�06�����-��c�4������
�
�
�����<�c�&�k�k�3�q�6�6�R�R�R����������
����37�2I�2I�%�2P�2P�/��/��3�9�9�S�>�>�!�,�-�-��,�,�T�Z�Z��_�_�Q�-?�@�@�4�CY�CY�Z_�Ze�Ze�fi�Zj�Zj�kl�Zm�Cn�Cn�n�%6�$4�	6�6�F�4�L�L�
�
s2��
A&�:A!�A&�!A&�9B�
C�6C�Cc���|jdg}|j�dd�|��z��t	|��}|����d��S)zJ
        Run dbtop -c and split output
        :return list[str]:
        z-czRun "%s" command� �
)r�rrl�joinr�stripr�)r�cmdr�s   rr�z#MySQLTopFileSaver._get_dbtop_outputsa��
�z�4� ������)�C�H�H�S�M�M�9�:�:�:�"�3�'�'���!�!�#�#�)�)�$�/�/�/rc�&�|j�d|jz��tj|��}	t|j|��dS#ttf$r0}|j�d|j�d|����Yd}~dSd}~wwxYw)za
        Dump datat to file as json string
        :param result dict: data to need dump
        zDump data to %s filerrN)	rrlr�json�dumpsrr�rr�rr��json_resultr!s    r�_outputzMySQLTopFileSaver._output%s���
	
����-��
�:�;�;�;��j��(�(��	P��T�Z��5�5�5�5�5����!�	P�	P�	P��H�N�N�N�t�z�N�N�1�N�N�O�O�O�O�O�O�O�O�O�����	P���s�A�B� %B�Bc��tj�|j��o5t	j��tj|j��jz
dkS)z�
        Check needed dump data to file. If touch file exist and was touched
        last 60 seconds we need dump data
        :return bool:
        �<)rmr�r�rb�time�stat�st_mtimerhs r�
_need_dumpzMySQLTopFileSaver._need_dump1sG���w�~�~�d�.�/�/�G��	���b�g�d�&6�7�7�@�@�B�F�	Grc��|jr?|���r-|�d|���i��dSdSdS)N�
dbgov_data)rdr�r�r�)rrOs  rrXzMySQLTopFileSaver.execute:sa����	@����!2�!2�	@��L�L�,��(;�(;�(=�(=�>�?�?�?�?�?�	@�	@�	@�	@rN)r`)rYrZr[r�rrirgr\r�rer�rcr�r�r�r�rXr]rrr_r_�s��������E�&�&�&�&�*�*�*�L�L�L��
<�
<��\�
<�Q�Q�Q�.3�3�3�.*�*�*����40�0�0�
P�
P�
P�G�G�G�@�@�@�@�@rr_c�"�eZdZdd�Zd�Zd�ZdS)�CloudLinuxTopFileSaver�/var/lve/cloudlinux_top.jsonc�F�||_tjd��|_dS)Nz plugin.cloudlinux_top_file_saverrrs  rrzCloudLinuxTopFileSaver.__init__@s ����
��$�%G�H�H����rc���tj|��}	t|j|��dS#tt
f$r0}|j�d|j�d|����Yd}~dSd}~wwxYw)Nrr)r�r�rrr�rrrr�s    rr�zCloudLinuxTopFileSaver._outputDs����j��(�(��	P��T�Z��5�5�5�5�5����!�	P�	P�	P��H�N�N�N�t�z�N�N�1�N�N�O�O�O�O�O�O�O�O�O�����	P���s�-�A.�%A)�)A.c	�v�|d}|�di��}gg}}t|�����D]�\}}t|��\}}	|dkr�||jd|jdzid|jit|j��|j	d�|j
d|jdzid|jit|j
��|jd�d�}
|dkr |j|
d	d
<|j|
dd
<|	r|�|
����|�|
����|�||d���dS)
Nr0r5r�allgY@)�epr'r,�mem�pno)�id�usage�limitr7r�rHr�)�users�	resellers)r:�listr;r	r>r?rGrrCrEr&r(r,r*r+rHr-rJr�)rrO�lve_versionrPr�r�r�r�rSrWr�s           rrXzCloudLinuxTopFileSaver.executeKsj���}�-�����n�b�1�1���r�y���v�|�|�~�~�.�.�	'�	'�J�C��"4�S�"9�"9��F�K���z�z��#�i� %�u���'>�?�$�e�n�5�0���>�>�$�{�
,�,�$�i� %�u�z�E�'9�:�$�e�h�/�0���?�?�$�|�
-�-�.�.�� �!�#�#�,1�J�D��M�&�)�,1�K�D��M�&�)��'��$�$�T�*�*�*�*��L�L��&�&�&�����u�9�=�=�>�>�>�>�>rN)r�)rYrZr[rr�rXr]rrr�r�?sM������I�I�I�I�P�P�P�?�?�?�?�?rr�)�
__future__rrr�r�rrmr�r��clcommon.utilsrr�lvestats.lib.commons.funcrrr	�lvestats.core.pluginr
�lvestats.lib.commons.sizeutilr�
__author__rr_r�r]rr�<module>r�sb��'�&�&�&�&�&�������
�
�
�
���������	�	�	�	�
�
�
�
�����=�=�=�=�=�=�=�=�\�\�\�\�\�\�\�\�\�\�/�/�/�/�/�/�;�;�;�;�;�;�
�
�~ �~ �~ �~ �~ ��~ �~ �~ �Bb@�b@�b@�b@�b@��b@�b@�b@�J+?�+?�+?�+?�+?�^�+?�+?�+?�+?�+?r

Hacked By AnonymousFox1.0, Coded By AnonymousFox