statistician module¶
-
class
AlertParam(short_median=12, long_median=120, threshold=1.5, time_resolution=10)[source]¶ Stores the parameters used in the alert detection process.
short_medianandlong_medianare the size of the windows for the moving averages.An alert will be raised if
short_outflow_average > long_outflow_average * threshold.Warning
The unit base of
short_medianandlong_medianistime_resolution, that means thatlong_median=2withtime_resolution=10will calculate an outflow average on the last2 * 10 = 20seconds.
-
class
QueueWriter(output_queue, parse=True, pace10=1, factor=2)[source]¶ Bases:
threading.ThreadUsed to fill the Statistician queue, to simulate a fast reading and compare the reading speed with or without parsing.
Note
pace10 is the pace for 100ms, ie
10*pace10entries are put in the queue every second.
-
class
Statistician(input_queue, sleeping_time=0.1, parse=False, alert_param=<statistician.AlertParam instance>)[source]¶ Bases:
threading.ThreadThis thread object is responsible for the statistics maintenance, it has a
Statisticsobject to store them and raise the alerts.It possesses the alert parameters.
Read lines are ‘thread-safely’ received thanks to an
input_queue. They should be parsed by default, but this can be changed with theparseparameter.Variables: should_run (bool) – If False, the thread will shortly end stop its operation. Used to cleanly end the program. Note
Alerts are checked every
AlertParam.time_resolution.
-
class
Statistics[source]¶ Object used by the statistician as its “notebook”. This is were the stats are saved.
It calls the Displayer if an alert should be raised or shut down. It is called when the stats should be printed.
Variables: - section (dictionary) – The keys are the hit sections, values are the number of hits for each section.
- total_bytes (int) – Sum of the bytes sent.
- total_hits (int) – Total number of hits.
- should_run (bool) – If False, the thread will shortly end stop its operation. Used to cleanly end the program.
- long_term_bytes_buffer (int) – Stores the sum of bytes sent during a certain time, then is appended to the long_term_bytes list and reseted.
- long_term_bytes (list of int) – List that stores the evolution of the number of sent bytes, used to compute moving average.
- alert_raised (bool) – True if an alert has been raised and not shut down.
Note
The use of
statistics.lockmakes this object thread-safe.Warning
number_of_hits,total_bytesandtotal_hitsare used for the printed stats, ‘total’ is in fact ‘total since the last display’.-
emergency(alert_param)[source]¶ Returns a dictionary with the alert parameters if there is one. Called by
update_long_term