o
    iO                     @  sv   d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
mZ ddlmZ dddZG dd dejjZdS )    )annotationsN)web)CONTENT_TYPE_LATESTCollectorRegistrygenerate_latestmultiprocess   )utils_requestaiohttp.web_request.Requestreturnweb.Responsec                   sB   ddd}t  }|d |I d H }tj|ttt|ddS )Nr   bytesc                  S  s,   dt jv rtdd} t|  t| S t S )NPROMETHEUS_MULTIPROC_DIRT)auto_describe)osenvironr   r   MultiProcessCollectorr   )registry r   f/var/www/html/livekit_bhavya/venv/lib/python3.10/site-packages/livekit/agents/telemetry/http_server.py_get_metrics   s
   


zmetrics.<locals>._get_metrics)zContent-TypezContent-Length)bodyheaders)r   r   )asyncioget_running_looprun_in_executorr   Responser   strlen)r
   r   loopdatar   r   r   metrics   s   
r"   c                      s   e Zd Zd fd	d
Z  ZS )
HttpServerhostr   portintr    asyncio.AbstractEventLoopr   Nonec                   s*   t  ||| | jtdtg d S )Nz/metrics)super__init___app
add_routesr   getr"   )selfr$   r%   r    	__class__r   r   r*   '   s   zHttpServer.__init__)r$   r   r%   r&   r    r'   r   r(   )__name__
__module____qualname__r*   __classcell__r   r   r/   r   r#   &   s    r#   )r
   r   r   r   )
__future__r   r   r   aiohttp.web_requestaiohttpr   prometheus_clientr   r   r   r    r	   r"   http_serverr#   r   r   r   r   <module>   s    
