
    &`iG                     x    d dl mZ d dlmZmZ 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  G d d	          Zd
S )    )defaultdict)DictList)AutoscalerPrometheusMetrics)InstanceUtil)NodeTypeConfig)NodeType)Instancec                   v    e Zd ZdeddfdZdee         deee	f         fdZ
dee         deee	f         fdZdS )	AutoscalerMetricsReporterprom_metricsreturnNc                     || _         d S N)_prom_metrics)selfr   s     v/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/autoscaler/v2/metrics_reporter.py__init__z"AutoscalerMetricsReporter.__init__   s    )    	instancesnode_type_configsc                    i }|                                 D ]}ddddd||<   |D ]}t          j        |j                  r||j                 dxx         dz  cc<   7t          j        |j                  r||j                 dxx         dz  cc<   l|j        t          j        k    r||j                 dxx         dz  cc<   |j        t          j        k    r||j                 dxx         dz  cc<   |	                                D ]\  }}| j
        j                            | j
        j        |                              |d                    | j
        j                            | j
        j        |                              |d                    | j
        j                            | j
        j        |                              |d                    | j
        j                            |d                    d	S )
a3  
        Record autoscaler metrics for:
            - pending_nodes: Nodes that are launching/pending ray start
            - active_nodes: Active nodes (nodes running ray)
            - recently_failed_nodes: Nodes that are being terminated.
            - stopped_nodes: Nodes that are terminated.
        r   )pendingrunningterminating
terminatedr      r   r   r   )SessionNamer	   N)keysr   is_ray_pendingstatusinstance_typeis_ray_running
IMInstanceTERMINATING
TERMINATEDitemsr   pending_nodeslabelssession_namesetactive_nodesrecently_failed_nodesstopped_nodesinc)r   r   r   status_count_by_typer"   instancestatus_counts          r   report_instancesz*AutoscalerMetricsReporter.report_instances   sK    AC.3355 	 	M 	3 3 // " 	P 	PH*8?;; P$X%;<YGGG1LGGGG,X_== P$X%;<YGGG1LGGGGJ$:::$X%;<]KKKqPKKKKJ$999$X%;<\JJJaOJJJ+?+E+E+G+G 	M 	M'M<,33 .;m 4  c,y)***+22 .;m 3  c,y)***4;; .;m <  c,}-...,00l1KLLLL	M 	Mr   c                 x   t          t                    }t          t                    }d }|D ][}t          j        |j                  r ||||j        d           /t          j        |j                  r ||||j        d           \|                                D ]C\  }}| j        j	        
                    | j        j        |                              |           D|                                D ]C\  }}| j        j        
                    | j        j        |                              |           DdS )z
        Record autoscaler metrics for:
            - pending_resources: Pending resources
            - cluster_resources: Cluster resources (resources running on the cluster)
        c                 z    ||         j         }|                                D ]\  }}| |xx         ||z  z  cc<   d S r   )	resourcesr'   )resource_mapr   	node_typecountnode_resourcesresource_nameresource_values          r   _add_resourceszBAutoscalerMetricsReporter.report_resources.<locals>._add_resourcesM   sa    .y9CN1?1E1E1G1G F F-~]+++~/EE++++F Fr   r   )r   resourceN)r   floatr   r    r!   r"   r#   r'   r   pending_resourcesr)   r*   r+   cluster_resources)	r   r   r   r@   rA   r=   r1   r;   r<   s	            r   report_resourcesz*AutoscalerMetricsReporter.report_resources?   s}    (..'..	F 	F 	F
 " 	 	H*8?;; %'8(:PRS    ,X_== %'8(:PRS   .?-D-D-F-F 	" 	")M>077 .;m 8  c.!!!!->-D-D-F-F 	" 	")M>077 .;m 8  c.!!!!	" 	"r   )__name__
__module____qualname__r   r   r   r$   r   r	   r   r3   rB    r   r   r   r      s        *%@ *T * * * *.M
#.M  . 89.M .M .M .M`%"
#%"  . 89%" %" %" %" %" %"r   r   N)collectionsr   typingr   r   $ray.autoscaler._private.prom_metricsr   )ray.autoscaler.v2.instance_manager.commonr   )ray.autoscaler.v2.instance_manager.configr   ray.autoscaler.v2.schemar	   'ray.core.generated.instance_manager_pb2r
   r$   r   rF   r   r   <module>rN      s    # # # # # #         L L L L L L B B B B B B D D D D D D - - - - - - J J J J J JY" Y" Y" Y" Y" Y" Y" Y" Y" Y"r   