U
    /eQ                     @  s`   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 erLd dl
mZ G dd deZd	S )
    )annotations)Iterator)TYPE_CHECKING)PrometheusCollector)WorkStealingCounterMetricFamilyc                      s*   e Zd Z fddZddddZ  ZS )WorkStealingMetricCollectorc                   s   t  | d| _d S )Nstealing)super__init__Z	subsystem)selfserver	__class__ R/tmp/pip-unpacked-wheel-g426oqom/distributed/http/scheduler/prometheus/stealing.pyr      s    z$WorkStealingMetricCollector.__init__zIterator[CounterMetricFamily])returnc                 c  s   ddl m} z| jjd }W n tk
r2   Y d S X || dddgd}|| dd	dgd}t|jD ]@\}}|t	|g|j
d |  |t	|g|j
d |  qj|V  |V  d S )
Nr   r   r
   Zrequest_count_totalz6Total number of stealing requests per cost multiplier.Zcost_multiplier)labelsZrequest_cost_totalz4Total cost of stealing requests per cost multiplier.)prometheus_client.corer   r   
extensionsKeyErrorZ
build_name	enumerateZcost_multipliersZ
add_metricstrZmetrics)r   r   r
   Zstealing_request_count_totalZstealing_request_cost_totallevelZ
multiplierr   r   r   collect   s4      z#WorkStealingMetricCollector.collect)__name__
__module____qualname__r   r   __classcell__r   r   r   r   r	      s   r	   N)
__future__r   collections.abcr   typingr   Zdistributed.http.prometheusr   Zdistributed.stealingr   r   r   r	   r   r   r   r   <module>   s   