libgs.monitoring.Monitor

class libgs.monitoring.Monitor(workers=10, tick=0.5, tick_cb=<function <lambda>>, default_dt=10)[source]

Class to provide functionality for monitoring.

The monitor class works by spawning a threadpool in which it will call a number of user-defined monitoring functions. Every tick, it will check the list of monitoring functions to find the ones that are due and then invoke them in the threadpool. It then immediately proceeds to the next tick.

In other words, monitoring functions are free to do whatever they want, including to block for a while since while it is running the Monitor class will just proceed with executing other monitoring functions (up to the limit of the workers in the threadpool).

Monitoring functions are added to the class instance preferably using the monitor() decorator.

It is possible to add callbacks to monitor points that are invoked every time the value is updated.

It is also possible to add a single tick callback when creating the Monitor object. Take care when doing this as it is invoked at the end of every tick, and the next tick will not execute before it completes. Therefore care should be taken to ensure tick callbacks return very fast.

This restriction does not apply to monitor callbacks as they are executed in the Threadpool with the call to the monitor function and will therefore not hold up the Monitor overall.

Parameters:
  • workers – Maximum number of simultaneouse threads to spawn in the ThreadPool
  • tick – The delay between successive runs of the monitor loop. Should be fairly small (< 1 sec).
  • tick_cb – A callback that can be invoked at the end of every tick.
  • default_dt – Default dt to apply to monitor generators (if dt not specified explicitly)

Methods

add_callback(callable) Add a callable to be invoked every time a value is polled.
callback() Decorator that can be applied to a function to automatically add it to the monitor
itertree([parent]) Iterator that will iterate through the full tree of monitor points, or alternatively just a specific branch by specifying the parent of that branch.
keys() Just include this since dicts etc all use keys to describe the access keys.
monitor([point]) Creates a decorator that can be applied to any function to add it to be monitored.
names()
returns:list of monitor names
register_monitor(name, gen[, dt, parent, …]) This is a low level function to register a monitor generator with the monitor class.
register_parent(name[, parent]) A parent monitor is not really a monitor.
start([subprocess]) Start polling loop.
stop() Stop the polling loop.
to_gen_in_executor(fn, point_names, *args, …) This decorator will take any function and turn it into a generator appropriately formatted for adding using register_monitor().

Attributes

alertcode The current worst alert level.

Inherited from base class