
    i                         d dl mZ d dlZ	 d dlmZ n# e$ r  ed          w xY w ej        e          Z G d de	          Z
dS )    )chainN)scaleszTThe scales library is required for metrics support: https://pypi.org/project/scales/c                       e Zd ZdZdZ	 dZ	 dZ	 dZ	 dZ	 dZ		 dZ
	 dZ	 dZ	 dZ	 dZ	 dZd Zd Zd Zd Zd Zd	 Zd
 Zd Zd Zd ZdS )Metricsz
    A collection of timers and counters for various performance metrics.

    Timer metrics are represented as floating point seconds.
    Nr   c                    t                               d           d                    t          | j                            | _        t          xj        dz  c_        t          j        | j        t          j	        d          t          j
        d          t          j
        d          t          j
        d          t          j
        d          t          j
        d	          t          j
        d
          t          j
        d          t          j        dfd          t          j        dfd          t          j        dfd                    | _        dt          j        j        vr.t          j        j        | j                 t          j        j        d<   | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        d S )NzStarting metric capturezcassandra-{0}   request_timerconnection_errorswrite_timeoutsread_timeoutsunavailablesother_errorsretriesignoresknown_hostsc                  P    t           j                                                  S N)lenmetadata	all_hostscluster_proxys   c/Users/user/workspace/sujinbaek/cqa-test-app/venv/lib/python3.11/site-packages/cassandra/metrics.py<lambda>z"Metrics.__init__.<locals>.<lambda>   s    M2<<>>??     connected_toc                  ~    t          t          t          j        d  j        D                                           S )Nc              3   H   K   | ]}|j                                         V  d S r   )_poolskeys.0ss     r   	<genexpr>z5Metrics.__init__.<locals>.<lambda>.<locals>.<genexpr>   s,      3d3dAHMMOO3d3d3d3d3d3dr   )r   setr   from_iterablesessionsr   s   r   r   z"Metrics.__init__.<locals>.<lambda>   s4    C 33d3d]Mc3d3d3d d deeff r   open_connectionsc                  @    t          d  j        D                       S )Nc              3   v   K   | ]4}t          d  |j                                        D                       V  5dS )c              3   $   K   | ]}|j         V  d S r   )
open_count)r"   ps     r   r$   z?Metrics.__init__.<locals>.<lambda>.<locals>.<genexpr>.<genexpr>   s$      HHHHHHHHr   N)sumr   valuesr!   s     r   r$   z5Metrics.__init__.<locals>.<lambda>.<locals>.<genexpr>   sE      iiQCHHahoo6G6GHHHHHiiiiiir   )r.   r'   r   s   r   r   z"Metrics.__init__.<locals>.<lambda>   s"    iiR_Rhiiiii r   	cassandra)logdebugformatstr_stats_counter
stats_namer   r   
collectionPmfStatIntStatStatstats_Statsr	   r
   r   r   r   r   r   r   r   r   r(   )selfr   s    `r   __init__zMetrics.__init__x   s   		+,,,)00T5H1I1IJJ!#&tN?++N.//N+,,N?++N>**N>**N9%%N9%% K????A AKffffh hK*iiiik kl l
( fm111/5}/B4?/SFM,!Z5!%!="j7!Z5 J3 J3z)z):1 J3 $
 ;r   c                 0    | j         xj        dz  c_        d S Nr   )r;   r
   r=   s    r   on_connection_errorzMetrics.on_connection_error   s    
$$)$$$$r   c                 0    | j         xj        dz  c_        d S r@   )r;   r   rA   s    r   on_write_timeoutzMetrics.on_write_timeout   s    
!!Q&!!!!r   c                 0    | j         xj        dz  c_        d S r@   )r;   r   rA   s    r   on_read_timeoutzMetrics.on_read_timeout   s    
  A%    r   c                 0    | j         xj        dz  c_        d S r@   )r;   r   rA   s    r   on_unavailablezMetrics.on_unavailable       
1$r   c                 0    | j         xj        dz  c_        d S r@   )r;   r   rA   s    r   on_other_errorzMetrics.on_other_error   rI   r   c                 0    | j         xj        dz  c_        d S r@   )r;   r   rA   s    r   	on_ignorezMetrics.on_ignore       
ar   c                 0    | j         xj        dz  c_        d S r@   )r;   r   rA   s    r   on_retryzMetrics.on_retry   rN   r   c                 >    t          j                    | j                 S )zJ
        Returns the metrics for the registered cluster instance.
        )r   getStatsr6   rA   s    r   	get_statszMetrics.get_stats   s       11r   c                 0   | j         |k    rdS |t          j        j        v r"t	          d                    |                    t          j        j        | j                  }t          j        j        | j         = || _         |t          j        j        | j         <   dS )z
        Set the metrics stats name.
        The stats_name is a string used to access the metrics through scales: scales.getStats()[<stats_name>]
        Default is 'cassandra-<num>'.
        Nz"{0}" already exists in stats.)r6   r   r<   r;   
ValueErrorr3   )r=   r6   r;   s      r   set_stats_namezMetrics.set_stats_name   s     ?j((F,,,=DDZPPQQQ#DO4M0$/4DO,,,r   )__name__
__module____qualname____doc__r	   r
   r   r   r   r   r   r   r   r   r(   r5   r>   rB   rD   rF   rH   rK   rM   rP   rS   rV    r   r   r   r      sB         M" 
 N
 M
 L L G
 G
 K L
 
 N&< &< &<P* * *' ' '& & &% % %% % %          2 2 25 5 5 5 5r   r   )	itertoolsr   logginggreplinr   ImportError	getLoggerrW   r1   objectr   r[   r   r   <module>rb      s   "       , , , ,
+	+, , ,,
 g!!m5 m5 m5 m5 m5f m5 m5 m5 m5 m5s    $