a
    ܌xd                     @   s   d dl Z d dlmZmZmZ ddlmZmZmZ ddl	m
Z
mZmZ zd dlZe ZW n eyn   dZY n0 G dd de
Ze ZdS )	    N)CallableIterableUnion   )CounterMetricFamilyGaugeMetricFamilyMetric)	CollectorCollectorRegistryREGISTRYi   c                   @   s\   e Zd ZdZddd defeeg eeef f ee	dddZ
d	d
 Zee dddZdS )ProcessCollectorz6Collector for Standard Exports such as cpu and memory. c                   C   s   dS )Nself r   r   r   [/var/www/html/Ranjet/env/lib/python3.9/site-packages/prometheus_client/process_collector.py<lambda>       zProcessCollector.<lambda>z/proc)	namespacepidprocregistryc                 C   s   || _ || _|| _|r"|d | _nd| _d| _ztd| _W n ttt	t
fyX   Y n0 t| _d| _z|  | _W n t
y   Y n0 |r||  d S )NZ	_process_Zprocess_g      Y@
SC_CLK_TCKr   )Z
_namespace_pid_proc_prefix_ticksossysconf
ValueError	TypeErrorAttributeErrorOSError	_PAGESIZE	_pagesize_btime
_boot_timeregister)r   r   r   r   r   r   r   r   __init__   s&    zProcessCollector.__init__c                 C   sp   t tj| jddF}|D ]0}|drt| d   W  d    S qW d    n1 sb0    Y  d S )Nstatrbs   btime r   )openr   pathjoinr   
startswithfloatsplit)r   r(   liner   r   r   r%   0   s    
zProcessCollector._boot_time)returnc              
   C   s  | j s
g S tj| jt|   }g }zttj|dd&}|	 
dd 
 }W d    n1 sn0    Y  t| jd dt|d d}t| jd	 d
t|d | j d}t|d | j }t| jd d|| j  d}t|d | j }	t|d | j }
t| jd d|	|
 d}|||||g W n tyF   Y n0 zttj|ddN}|D ]8}|drdt| jd dt|
 d d} qqdW d    n1 s0    Y  t| jd dtttj|d}|||g W n ty   Y n0 |S )Nr(   r)      )Zvirtual_memory_byteszVirtual memory size in bytes.   )valueZresident_memory_byteszResident memory size in bytes.      Zstart_time_secondsz6Start time of the process since unix epoch in seconds.      Zcpu_seconds_totalz0Total user and system CPU time spent in seconds.limitss   Max open filemax_fdsz(Maximum number of open file descriptors.   open_fdsz Number of open file descriptors.fd)r$   r   r+   r,   r   strr   stripr*   readr/   r   r   r.   r#   r   r   extendr!   r-   lenlistdir)r   r   resultr(   partsZvmemZrssZstart_time_secs
start_timeutimeZstimecpur:   r0   r;   r=   r   r   r   collect6   sX    4



*
zProcessCollector.collectN)__name__
__module____qualname____doc__r   r?   r   r   intr
   r'   r%   r   r   rJ   r   r   r   r   r      s   r   )r   typingr   r   r   Zmetrics_corer   r   r   r   r	   r
   r   resourceZgetpagesizer"   ImportErrorr   ZPROCESS_COLLECTORr   r   r   r   <module>   s   
T