
    Xh                         d dl Z d dlmZmZmZmZ ddlmZmZm	Z	 ddl
mZmZmZ 	 d dlZ ej                         Z G d de      Z e       Zy# e$ r dZY w xY w)	    N)CallableIterableOptionalUnion   )CounterMetricFamilyGaugeMetricFamilyMetric)	CollectorCollectorRegistryREGISTRYi   c            
       f    e Zd ZdZdd defdedeg eeef   f   dede	e
   fd	Zd
 Zdee   fdZy)ProcessCollectorz6Collector for Standard Exports such as cpu and memory. c                       y)Nself r       W/var/www/html/myenv/lib/python3.12/site-packages/prometheus_client/process_collector.py<lambda>zProcessCollector.<lambda>   s    r   z/proc	namespacepidprocregistryc                 n   || _         || _        || _        |r|dz   | _        nd| _        d| _        	 t        j                  d      | _        t        | _        d| _        	 | j                         | _        |r|j                  |        y y # t        t        t        t        f$ r Y Xw xY w# t        $ r Y ?w xY w)N	_process_process_g      Y@
SC_CLK_TCKr   )
_namespace_pid_proc_prefix_ticksossysconf
ValueError	TypeErrorAttributeErrorOSError	_PAGESIZE	_pagesize_btime
_boot_timeregister)r   r   r   r   r   s        r   __init__zProcessCollector.__init__   s    
 $	
${2DL%DL	**\2DK # 	//+DK d#  I~w? 		  		s#   B	 B( 	B%$B%(	B43B4c                    t        t        j                  j                  | j                  d      d      5 }|D ]:  }|j                  d      st        |j                         d         c cd d d        S  	 d d d        y # 1 sw Y   y xY w)Nstatrbs   btime r   )openr$   pathjoinr!   
startswithfloatsplit)r   r1   lines      r   r-   zProcessCollector._boot_time0   sp    "'',,tzz62D9 	2T 2??9- a11	2 	22	2 	2 	2s   A?A?4A??Breturnc                    | j                   sg S t        j                  j                  | j                  t        | j                               j                               }g }	 t        t        j                  j                  |d      d      5 }|j                         j                  d      d   j                         }d d d        t        | j                  dz   dt        d               }t        | j                  d	z   d
t        |d         | j                  z        }t        |d         | j                  z  }t        | j                  dz   d|| j                   z         }t        |d         | j                  z  }	t        |d         | j                  z  }
t!        | j                  dz   d|	|
z         }|j#                  ||||g       	 t        t        j                  j                  |d      d      5 }|D ]J  }|j'                  d      st        | j                  dz   dt        |j                         d               } n d d d        t        | j                  dz   dt)        t        j*                  t        j                  j                  |d                        }|j#                  |g       |S # 1 sw Y   xY w# t$        $ r Y w xY w# 1 sw Y   xY w# t$        $ r Y |S w xY w)Nr1   r2      )virtual_memory_byteszVirtual memory size in bytes.   )valueresident_memory_byteszResident memory size in bytes.      start_time_secondsz6Start time of the process since unix epoch in seconds.      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$   r4   r5   r!   strr    stripr3   readr8   r	   r"   r7   r+   r#   r   extendr)   r6   lenlistdir)r   r   resultr1   partsvmemrssstart_time_secs
start_timeutimestimecpurH   r9   rI   rK   s                   r   collectzProcessCollector.collect6   s   {{Iggll4::s499;'7'='='?@	bggll3/6 >$**404::<> %T\\4J%J%DERWXZR[L\^D#DLL3J$JLl*/b	*:T^^*KMC#E"I.<O*4<<:N+N+c1@4;;1NPJ %)$t{{2E%)$t{{2E%dll5H&H&X,1EM;C MM4j#67	bggll3148 F" D'78"3DLL94L4^:?

Q:P#R  )
)B)K),RZZS$8O-P)QSH MM8W-. G> >"  		   		s\   !*K 1J7<DK *K  6K8KA/K  7K<K 	KKKK   	K-,K-N)__name__
__module____qualname____doc__r   rM   r   r   intr   r   r/   r-   r   r
   r\   r   r   r   r   r      sj    @ #%6D$9A	$$r5c?23$ $ $$56	$:2+&) +r   r   )r$   typingr   r   r   r   metrics_corer   r	   r
   r   r   r   r   resourcegetpagesizer*   ImportErrorr   PROCESS_COLLECTORr   r   r   <module>rh      sf    	 6 6 H H < <$$$&IQy Qh %&  <u  Is   A AA