~eddlZddlZddlmZddlmZGddZGddeZGdd eZGd d eZGd d eZ y)N) format_delta)format_percentc0eZdZdZddZdZdZdZdZy) Timerzp A timer keeps track of the number of seconds passed during it's lifetime and since the last reset. Nc|xstj|_|j|_|j|_yN)time _create_time_creation_time _last_time)self create_times 7/usr/lib/python3/dist-packages/landscape/lib/monitor.py__init__zTimer.__init__s1'4499"//1--c"|jSr)r r s rr z Timer.times  ""rc<|j|jz Sr)r r rs r since_startzTimer.since_starts  "T%8%888rc<|j|jz Srr r rs r since_resetzTimer.since_resets  "T__44rc.|j|_yrrrs rresetz Timer.resets++-rr) __name__ __module__ __qualname____doc__rr rrrrrrrs  . #95.rrc:eZdZdZdfd ZdZfdZdZxZS)Monitora A monitor tracks the number of pings it received during it's lifetime and since the last reset. The component being monitored is responsible for calling C{ping()} everytime a monitored activity occurs. It should register a reactor event that logs statistics from this monitor every N seconds. Essentially, monitors are just statistics checkers that components can use to monitor themselves. cPt||||_d|_d|_y)Nrr)superr event_namecount total_count)r r%r __class__s rrzMonitor.__init__+s) [1$ rcX|xjdz c_|xjdz c_y)N)r&r'rs rpingz Monitor.ping1s  a  Arc0t|d|_y)Nr)r$rr&r r(s rrz Monitor.reset5s   rc tjd|j|jt |j |j y)Nz%%d %s events occurred in the last %s.)logginginfor&r%rrrrs rlogz Monitor.log9s; 3 JJ OO ))+ ,  rr) rrrrrr+rr1 __classcell__r(s@rr!r! s rr!c6eZdZdZ dfd ZfdZdZxZS) BurstMonitorz A burst monitor tracks the volume pings it receives. It goes into warn mode when too many pings are received in a short period of time. cRt|||||_||_g|_yNr#)r$rrepeat_interval maximum_count _last_times)r r8r9r%rr(s rrzBurstMonitor.__init__Js/ =.*rc8t||j}|jj ||jd|z |j kDs%t |j|jdzkDr|jjdyy)Nrr*) r$r+r r:appendr8lenr9pop)r nowr(s rr+zBurstMonitor.pingVs  iik $   Q # %(<(< <4##$t'9'9A'==     #>rc|jsy|j|jdz }||jkxr%t|j|jdzk\S)NFrr*)r:r r8r=r9)r deltas rwarnzBurstMonitor.warn`s` d..q11 D(( ( @D$$%););a)?? rr)rrrrrr+rBr2r3s@rr5r5Cs $ rr5cReZdZdZ dfd ZedZedZdZdZ xZ S)CoverageMonitora A coverage monitor tracks the volume of pings received since the last reset. It has normal and warn states that are determined by calculating the number of expected pings since the last reset. If the actual number of pings falls below the minimum required percent the monitor goes into warn mode. The component being monitored should register a reactor event that logs statistics from this monitor every N seconds. cDt|||||_||_yr7)r$rr8 min_percent)r r8rFr%rr(s rrzCoverageMonitor.__init__us/  #   /&rcf |jt|jz S#t$rYywxYw)Ng?)r&floatexpected_countZeroDivisionErrorrs rpercentzCoverageMonitor.percents3 ::d&9&9 :: :   s !$ 00cNt|j|jz Sr)intrr8rs rrIzCoverageMonitor.expected_counts!4##%(<(<<==rc ld}|jr|jr|jdz}tj}|j rtj }|d|j |j|jt|t|j|jy)Ngdz9%d of %d expected %s events (%s) occurred in the last %s.) rKrIr/r0rBwarningr&r%rrrr)r rKr1s rr1zCoverageMonitor.logs <>&rrDcLeZdZdZ dfd ZedZfdZdZdZ xZ S)FrequencyMonitoraz A frequency monitor tracks the number of pings received during a fixed period of time. It has normal and warn states; a warn state is triggered when the minimum expected pings were not received during the specified interval. The component being monitored should register a reactor event that checks the warn state of this monitor every N seconds. cnt|||||_||_|j |_yr7)r$rr8 min_frequencyr _last_count)r r8rVr%rr(s rrzFrequencyMonitor.__init__s@  #   /*,,.rcZ|j|jz }||jzSr)r rWr8)r since_pings rrIzFrequencyMonitor.expected_counts,&&(4+;+;; T1111rcLt||j|_yr)r$r+r rWr-s rr+zFrequencyMonitor.pings  ,,.rc |jrJtjd|j|j|j t |j|jy)NzAOnly %d of %d minimum expected %s events occurred in the last %s.) rBr/rPr&rIr%rr8rrs rr1zFrequencyMonitor.logsL 99; OO+ ##T112   rc|jrP|jrD|j|jz |jk\r|j|jkryy)NTF)r8rVr rWr&rs rrBzFrequencyMonitor.warnsM   D$6$6!!#d&6&66$:N:NN**t111rr) rrrrrrRrIr+r1rBr2r3s@rrTrTs5 /22/ rrT) r/r landscape.lib.formatrrrr!r5rDrTrrrr^sN -/..0 e F$ 7$ N=g=@4w4r