
    g^                        U d dl mZ d dlZd dlmZ d dlmZmZmZm	Z	m
Z
mZ d dlmZmZ erd dlmZ d dlmZ 	 d dlZd dlmZmZ e	d
   Zded<   eee
ee      f   Zdj=                         Zded<   dj=                         Z ded<   i  eee      deee dgz   e dgdZ!ded<   ej                  dk(  re!jE                  dd       dddgdgdZ#ded<   e	d   Z$d!dZ%d"d#dZ&d$dZ'd$d Z(y# e$ rZ ed	      edZ[ww xY w)%    )annotationsN)python_implementation)TYPE_CHECKINGDictIterableLiteralOptionalcast)CallbackOptionsObservation)LiteralString)Logfire)_DEFAULT_CONFIGSystemMetricsInstrumentorz`logfire.instrument_system_metrics()` requires the `opentelemetry-instrumentation-system-metrics` package.
You can install this with:
    pip install 'logfire[system-metrics]')system.cpu.simple_utilizationsystem.cpu.timesystem.cpu.utilizationsystem.memory.usagesystem.memory.utilizationzsystem.swap.usagesystem.swap.utilizationzsystem.disk.iozsystem.disk.operationszsystem.disk.timezsystem.network.dropped.packetszsystem.network.packetszsystem.network.errorszsystem.network.iosystem.network.connectionszsystem.thread_countzprocess.runtime.memoryzprocess.runtime.cpu.timezprocess.runtime.gc_countzprocess.runtime.thread_countprocess.runtime.cpu.utilizationz process.runtime.context_switchesz"process.open_file_descriptor.counta}  type[Literal['system.cpu.simple_utilization', 'system.cpu.time', 'system.cpu.utilization', 'system.memory.usage', 'system.memory.utilization', 'system.swap.usage', 'system.swap.utilization', 'system.disk.io', 'system.disk.operations', 'system.disk.time', 'system.network.dropped.packets', 'system.network.packets', 'system.network.errors', 'system.network.io', 'system.network.connections', 'system.thread_count', 'process.runtime.memory', 'process.runtime.cpu.time', 'process.runtime.gc_count', 'process.runtime.thread_count', 'process.runtime.cpu.utilization', 'process.runtime.context_switches', 'process.open_file_descriptor.count']]
MetricNamez<idle user system irq softirq nice iowait steal interrupt dpczlist[LiteralString]
CPU_FIELDSzDavailable used free active inactive buffers cached shared wired slabMEMORY_FIELDStotalused)r   r   r   r   r   r   ConfigFULL_CONFIGdarwinr   	available)r   r   r   r   BASIC_CONFIG)basicfullNc                R    | dk(  rt         S | dk(  rt        S | i S t        d|        )Nr#   r$   zInvalid base: )r"   r   
ValueError)bases    b/var/www/openai/venv/lib/python3.12/site-packages/logfire/_internal/integrations/system_metrics.pyget_base_configr)   y   s8    w			>$011    c                    i t        |      |xs i }d|v rt        |        d|v rt        |        |d= t        |      }|j	                  | j
                  j                                y )Nr   r   )config)meter_provider)r)   measure_simple_cpu_utilization'measure_process_runtime_cpu_utilizationr   
instrumentr,   get_meter_provider)logfire_instancer,   r'   instrumentors       r(   instrument_system_metricsr4      sp    8%8&,B8F&&0&'78(F2/0@A45,F;L+;+B+B+U+U+WXr*   c                8    dd}| j                  d|gdd       y )Nc              3  P   K   t        t        j                         dz         y wNd   )r   psutilcpu_percent)_optionss    r(   callbackz0measure_simple_cpu_utilization.<locals>.callback   s     &,,.455s   $&r   zBAverage CPU usage across all cores, as a fraction between 0 and 1.1descriptionunitr;   r   returnzIterable[Observation])metric_gauge_callback)r2   r<   s     r(   r.   r.      s*    6 **'	
X	 + r*   c                    t        j                         j                          dfd}| j                  dt	               j                          d|gdd       y )Nc              3  J   K   t        j                         dz         y wr7   )r   r:   )r;   processs    r(   r<   z9measure_process_runtime_cpu_utilization.<locals>.callback   s"      '--/#566s    #zprocess.runtime.z.cpu.utilizationzRuntime CPU utilizationr=   r>   rA   )r9   Processr:   rC   r   lower)r2   r<   rF   s     @r(   r/   r/      s]    nnG 7 **
0288:;;KL	
-	 + r*   )r'   BaserB   r   )Nr#   )r2   r   r,   zConfig | Noner'   rI   )r2   r   ))
__future__r   sysplatformr   typingr   r   r   r   r	   r
   opentelemetry.metricsr   r   typing_extensionsr   logfirer   r9   ,opentelemetry.instrumentation.system_metricsr   r   ImportErroreRuntimeErrorr   __annotations__strr   splitr   r   r   popr"   rI   r)   r4   r.   r/    r*   r(   <module>rZ      s]   " 
 * I I >/L *5   2h 
j(8C=11	2
 #a"f"f"h
 h
 &l%q%q%s" s
6?#%)!((G94!. &xV  <<8 OO0$7 (,%)"- &xf  $%2Y
Y  
	4 	s   C* *C=/	C88C=