CyberAlphaWolf

Server : Apache
System : Linux 182.49.167.72.host.secureserver.net 4.18.0-553.92.1.el8_10.x86_64 #1 SMP Wed Jan 14 06:31:58 EST 2026 x86_64
User : kikai ( 1014)
PHP Version : 8.3.30
Disable Function : NONE
Directory :  /lib/fm-agent/plugins/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/fm-agent/plugins/__pycache__/process.cpython-36.pyc
3

,`ri�D�
@sTddlZddlZddlZyddlZWndZYnXddlZGdd�dej�ZdS)�Nc@s0eZdZdZdZedd��Zdd�Zdd�Zd	S)
�
ProcessPlugin�process�ProcesscCs�tj}d}dtjkr tj}d}nrdtjkr6tj}d}n\dtjkrLtj}d}nFtdkrl|jjd�tj}d}n&tj	j
d�s�|jjd�tj}d}iSdtjkr�d	d||d
dd�d
d||d
dd�dd||ddd�dd||ddd�d�}n�dd||d
d�d	d||d
dd�dd||ddd�dd||ddd�dd||ddd�dd||ddd�d
d||d
dd�dd||ddd�dd||ddd�dd||ddd�dd||ddd�dd||ddd�d�}|S)N�aix�darwin�vmwarez=Unable to import psutil library, no process metrics availablezDUnable to import psutil library, please install and rebuild metadataz/procz/proc not foundzEnable procfs.zNumber of processes - name�	processesT)�label�options�status�
error_message�unit�
option_stringz'Number of processes - full command linezProcess is runningZbooleanz&Process is running - full command line)zprocess.named_countzprocess.named_count.fullzprocess.existszprocess.exists.fullzNumber of processes running)r	r
rrr
z%Memory percentage of processes - name�percentz"CPU percentage of processes - namez+Process Thread Count - executable name only�threadsz2Memory percentage of processes - full command linez2MB of memory used by processes - full command line�MBz/CPU percentage of processes - full command linez/Process Thread Count - executable name and args)zprocess.running_countzprocess.named_countzprocess.named_memory_percentagezprocess.named_cpu_percentagezprocess.existszprocess.thread_countzprocess.named_count.fullz$process.named_memory_percentage.fullz process.named_memory_raw_mb.fullz!process.named_cpu_percentage.fullzprocess.exists.fullzprocess.thread_count.full)�
agent_util�	SUPPORTED�sys�platform�psutil�log�info�UNSUPPORTED�os�path�exists)�self�configr�msg�metadata�r!�$/usr/lib/fm-agent/plugins/process.py�get_metadatas�



zProcessPlugin.get_metadatac&sldtjksdtjk�r�dtjkr&d}ndtjkr4d}tj|�\}}|jd�}|jd�r`|jd�}|dkrtt|�dSd	}g}x6|dd�D]&}	||	kr�|d7}|j|	j�d	�q�W|d
kr�|S|dkr�|r�dSd	Sn�|d3k�r�d	}
d	}d	}x�|D]�}
dtjk�rd|
}ndtjk�r d|
}tj|�\}}|j	�jd�}t|�dk�rN�q�|dj�}t
|d	�}t
|d�}t
|d�}|
|7}
||7}||7}�q�W|dk�r�|S|dk�r�t
|�dS|
SdSdtjk�rxtjd�}d}|�s�|jj
d�dS|jd��rd|}nd|}|d|7}tj|�\}}|jd�}|jd
��rRt|�dS|jd��rxt|�dd	k�rtdSd	Stdk�r�|jjd�dSd�|jd��r�|jd�}d�tj�}g}t|�}|jd
��rF�dk�rFxh|D]`}y0tj||j���r|j|jddddgd ��Wn(tjk
�r<|jjd!��w�YnX�q�Wn�|jd
��rΈdk�r�x�|D]f}y6tj|d"j|j����r�|j|jddddgd ��Wn(tjk
�r�|jjd!��wbYnX�qbWn^x\|D]T}y$|j|jdddd#d$d%d&gd ��Wn(tjk
�r$|jjd!��w�YnX�q�Wx6|D].}|d�sLd|d<�q2d"j|d�|d<�q2W|jjd'|�|dk�s�|d(k�r�ttj��S|d
k�rg}|jjd)|�x8|D]0}|�dk	�r�tj||���r�|j|��q�W|jj|�t|�S|dk�rvg}|jjd)|�x8|D]0}|�dk	�r$tj||���r$|j|��q$W|jj|�|�rndSd	S�n�|d4k�r�g}|jjd)|�x8|D]0}|�dk	�r�tj||���r�|j|��q�W|jj|�|jjd+�fd,d-�|D��|�sd	Sd	}
d	}d	}d	}d.tjk�rJ|j|�}|d#}
|d$}|d%}|d&}n^xP|D]H}
|
d#}|
d$}|
d%j}|
d&}|
|7}
||7}||7}||7}�qPWt
|�d5}|dk�r�|S|dk�r�|S|d*k�r�|S|
Sn�|d6k�rh|�r�td0d-�|D��} nd1S|j ||�}!|!�s$|j!||| �dS|!d	\}"}#| |#|"}$|j!||| �tj"�}%|%�s\d}%|$|%d2Sd	S)7Nr�sunoszps axwwzps -eo pid' 'args�
z.fullzprocess.running_count�rzprocess.named_countzprocess.exists�process.named_memory_percentage�process.named_cpu_percentage�named_memory_raw_mbzps -fp %s -o pcpu,pmem,rss��process.named_memory_raw_mbir�pgrep�z5Unable to find 'pgrep'! Unable to check for processesz%s -fz%sz %sz=Unable to import psutil library, no process metrics available�nameZcmdline_str�pid�cmdline�	cpu_times)�attrszUnable to get process.� �cpu_percent�memory_percent�memory_info�num_threadszAll running processes:
%s
�countzSearching processes for '%s'�process.thread_countzFound matching processes: %scsg|]}|��qSr!r!)�.0�p)�searchr!r"�
<listcomp>osz'ProcessPlugin.check.<locals>.<listcomp>r�!process.named_cpu_percentage.fullcSs$g|]}|jd�j|jd�j�qS)r1)�get�user�system)r:r;r!r!r"r=�sg�d)r'r(r))r'r+r9i)r(r>)#rrr�execute_command�split�endswith�rstrip�len�append�strip�float�whichr�error�
startswithrr�process_iter�str�rer<r.�as_dict�
NoSuchProcess�	exception�joinr0�debug�pids�findDarwinProcInfo�rss�sum�get_cache_results�cache_result�	cpu_count)&r�textkey�datarZps_cmd�retcode�outputr8rV�lineZall_cpuZall_memZ
all_raw_kbr/Zps�ret�fields�cpu�memZraw_kbr,�cmd�outZprocess_objsr�proc�found_procsZall_raw_memZall_thread_count�rvZmem_rawZthread_countZuser_sumZlast_result�deltaZpreviousZtime_used_resultZnumber_of_coresr!)r<r"�check�s�





















 

 
 






zProcessPlugin.checkcCs�g}x|D]}|jt|d��q
Wtjdjdj|���\}}|jd�}|dd�}td�td�td�t|�d�}xh|D]`}	|	j�}
t|
�d	krx|d
t|
d�7<|dt|
d
�7<|dt|
d�7<qxW|d}t|�d|d<|S)z�
        On OSX, psutil will not report process information on processes
        belonging to other users, unless the requesting process is privileged.
        https://github.com/giampaolo/psutil/issues/883
        r/zps uM -p {}�,r%r&Nr)r4r5r6r7�r4r*r5�r6�i)	rHrOrrC�formatrTrDrJrG)rrirV�fp�rcr`�linesZ	procLinesrj�lr�mr!r!r"rW�s&


z ProcessPlugin.findDarwinProcInfoN)	�__name__�
__module__�__qualname__r]r	�classmethodr#rlrWr!r!r!r"rs#r)rrrrrP�Pluginrr!r!r!r"�<module>s


XYZEAZ - Cyber Alpha Wolf © All Rights Reserved