o
    .i
                     @   sv   U d dl Z d dlZd dlmZmZmZ d dlmZ eeZ	da
ejdB ed< dd Zdefdd	Zd
d Zdd ZdS )    N)REGISTRYCollectorRegistrymultiprocess)init_logger_prometheus_multiproc_dirc                   C   s>   dt jvrt atjt jd< tdtj dS td dS )zFSet up prometheus multiprocessing directory if not already configured.PROMETHEUS_MULTIPROC_DIRz&Created PROMETHEUS_MULTIPROC_DIR at %szFound PROMETHEUS_MULTIPROC_DIR was set by user. This directory must be wiped between vLLM runs or you will find inaccurate metrics. Unset the variable and vLLM will properly handle cleanup.N)	osenvirontempfileTemporaryDirectoryr   nameloggerdebugwarning r   r   W/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/vllm/v1/metrics/prometheus.pysetup_multiprocess_prometheus   s   
r   returnc                  C   s0   t ddurtd t } t|  | S tS )zGet the appropriate prometheus registry based on multiprocessing
    configuration.

    Returns:
        Registry: A prometheus registry
    r   Nz2Using multiprocess registry for prometheus metrics)r   getenvr   r   r   r   MultiProcessCollectorr   )registryr   r   r   get_prometheus_registry'   s   

r   c                  C   s6   t } t| jD ]}t|drd|jv r| | qdS )a  Unregister any existing vLLM collectors from the prometheus registry.

    This is useful for testing and CI/CD where metrics may be registered
    multiple times across test runs.

    Also, in case of multiprocess, we need to unregister the metrics from the
    global registry.
    _namevllmN)r   list_collector_to_nameshasattrr   
unregister)r   	collectorr   r   r   unregister_vllm_metrics7   s   	
r   c               
   C   sn   t } | du rdS zt }t||  td| W dS  ty6 } ztdt	| W Y d}~dS d}~ww )zShutdown prometheus metrics.Nz0Marked Prometheus metrics for process %d as deadz Error during metrics cleanup: %s)
r   r   getpidr   mark_process_deadr   r   	Exceptionerrorstr)pathpider   r   r   shutdown_prometheusG   s   r(   )r   r
   prometheus_clientr   r   r   vllm.loggerr   __name__r   r   r   __annotations__r   r   r   r(   r   r   r   r   <module>   s   
