
    Ch                     @    S SK r S SKrS SKJr  S SKJr   " S S5      rg)    N)QuotaViolationError)KafkaMetricc                   n    \ rS rSrSrS rS r\S 5       r\S 5       r	SS jr
S	 rSS
 jrSS jrS rSrg)Sensor   a  
A sensor applies a continuous sequence of numerical values
to a set of associated metrics. For example a sensor on
message size would record a sequence of message sizes using
the `record(double)` api and would maintain a set
of metrics about request sizes such as the average or max.
c                 <   U(       d  [        S5      e[        R                  " 5       U l        Xl        X l        U=(       d    / U l        / U l        / U l        X@l	        US-  U l
        [        R                  " 5       S-  U l        U R                  [        5       5        g )Nzname must be non-empty  )
ValueError	threadingRLock_lock	_registry_name_parents_metrics_stats_config#_inactive_sensor_expiration_time_mstime_last_record_time_check_forestset)selfregistrynameparentsconfig'inactive_sensor_expiration_time_secondss         bC:\Suresh\moveshuttle\MDcreated\moveengine\venv\Lib\site-packages\aiokafka/metrics/stats/sensor.py__init__Sensor.__init__   s~     566__&
!
23d: 	0 "&t!335!    c                     X;   a  [        SU R                   S35      eUR                  U 5        U R                   H  nUR	                  U5        M     g)z<Validate that this sensor doesn't end up referencing itself.z Circular dependency in sensors: z is its own parent.N)r
   r   addr   r   )r   sensorsparents      r   r   Sensor._check_forest#   sO    ?2499+=PQ  	DmmF  ) $r"   c                     U R                   $ )za
The name this sensor is registered with.
This name will be unique among all registered sensors.
)r   r   s    r   r   Sensor.name-   s     zzr"   c                 ,    [        U R                  5      $ N)tupler   r)   s    r   metricsSensor.metrics5   s    T]]##r"   Nc                 Z   Uc  [         R                   " 5       S-  nX l        U R                     U R                   H  nUR	                  U R
                  X5        M!     U R                  U5        SSS5        U R                   H  nUR	                  X5        M     g! , (       d  f       N3= f)aP  
Record a value at a known time.
Arguments:
    value (double): The value we are recording
    time_ms (int): A POSIX timestamp in milliseconds.
        Default: The time when record() is evaluated (now)

Raises:
    QuotaViolationException: if recording this value moves a
        metric beyond its configured maximum or minimum bound
Nr	   )r   r   r   r   recordr   _check_quotasr   )r   valuetime_msstatr&   s        r   r1   Sensor.record9   s}     ?iikD(G!(ZZDLL%9 $w'	 
 mmFMM%) $ Zs   AB
B*c                 p   U R                    H  nUR                  (       d  M  UR                  R                  (       d  M3  UR                  U5      nUR                  R                  R	                  U5      (       a  Mp  [        SUR                  X2R                  R                  R                  4-  5      e   g)zP
Check if we have violated our quota for any metric that
has a configured quota
z.'%s' violated quota. Actual: %d, Threshold: %dN)r   r   quotar3   is_acceptabler   metric_namebound)r   r4   metricr3   s       r   r2   Sensor._check_quotasP   s    
 mmF}}}!4!4!4W-}}**88??-,!--umm6I6I6O6OPQ 	 $r"   c                 `   U(       d  [        S5      eU R                  R                  U5        UR                  5        Hm  n[	        UR
                  UR                  U=(       d    U R                  5      nU R                  R                  U5        U R                  R                  U5        Mo     g)aG  
Register a compound statistic with this sensor which
yields multiple measurable quantities (like a histogram)

Arguments:
    stat (AbstractCompoundStat): The stat to register
    config (MetricConfig): The configuration for this stat.
        If None then the stat will use the default configuration
        for this sensor.
zcompound stat must be non-emptyN)r
   r   appendstatsr   r   r5   r   r   register_metricr   )r   compound_statr   named_measurabler<   s        r   add_compoundSensor.add_compound_   s     >??=) - 3 3 5  %%'7'<'<f>TF NN**62MM  ( !6r"   c                 0   U R                      [        XU=(       d    U R                  5      nU R                  R	                  U5        U R
                  R                  U5        U R                  R                  U5        SSS5        g! , (       d  f       g= f)a  
Register a metric with this sensor

Arguments:
    metric_name (MetricName): The name of the metric
    stat (AbstractMeasurableStat): The statistic to keep
    config (MetricConfig): A special configuration for this metric.
        If None use the sensor default configuration.
N)r   r   r   r   rA   r   r?   r   )r   r:   r5   r   r<   s        r   r$   
Sensor.addt   s`     ZZ F4JdllKFNN**62MM  (KKt$	 ZZs   A1B
Bc                 f    [         R                   " 5       S-  U R                  -
  U R                  :  $ )zF
Return True if the Sensor is eligible for removal due to inactivity.
r	   )r   r   r   r)   s    r   has_expiredSensor.has_expired   s0    
 IIK$!7!77445 	5r"   )	r   r   r   r   r   r   r   r   r   )g      ?Nr,   )__name__
__module____qualname____firstlineno____doc__r    r   propertyr   r.   r1   r2   rD   r$   rI   __static_attributes__ r"   r   r   r      sR    "$*   $ $*.)*% 5r"   r   )r   r   aiokafka.errorsr   aiokafka.metrics.kafka_metricr   r   rR   r"   r   <module>rU      s      / 5B5 B5r"   