libgs.monitoring.Monitor.monitor

Monitor.monitor(point=None, *args, **kwargs)[source]

Creates a decorator that can be applied to any function to add it to be monitored.

It will do two things:

  1. Convert the function to a generator in which the function call is run in an executor, so that any call to the generators next() function will return immeditately and not hold up execution. If the function has not finished the generator will return None. If it has completed, it will return the value as well as a timestamp and any potential exception in the format required for the monitoring loop.
  2. Add the function to the Monitor class polling schedule.

The decorator can create multiple monitor points from a single callable (that returns a tuple) by specifying point as a tuple.

Please see register_monitor() for the full list of the remaining arguments that can be applied. *args and **kwargs can be anything accepted by register_monitor() except name, gen or dependents.

Example

register 3 monitoring points from a function that retuns random values at an interval of once every 10 seconds, grouped under the heading Test:

>>> @mon.monitor(point=("Point 1", "Point 2", "Point 3"), dt=10, parent="Test")
>>> def monitoring_function():
>>>    return random.random(), random.random(), random.random()
Parameters:
  • point – The name of the monitor point. If omitted it will use the function name. Can also be a tuple if function monitors several variables.
  • **kwargs (*args,) – Also accepts all the arguments of register_monitor()
Returns:

Decorator