herostools.actor.statemachine

# State Machine for HEROs

This keeps a cache of the last known state of a datasource and allows to query this cache via a HTTP metrics endpoint. This is especially useful for scraping from prometheus or influxdb.

  • {observable}_time {return_value.time}

  • {observable}_value {return_value.value} if unit is not ‘None’ a label {unit=’{{return_value.unit}}’} is attached

  • {observable}_raw_value {return_value.raw_value} if unit is not ‘None’ a label {unit=’{{return_value.raw_unit}}’} is attached

A predefined set of labels is attached to the metrics. Observable names are cleaned to match metric names [a-z0-9_]

trailing _ and repetitions _ are removed.

Attributes

Classes

HERODatasourceStateMachine

A class that can observe and handle the data emitted by one or more datasource HEROs.

Module Contents

herostools.actor.statemachine.no_metric
herostools.actor.statemachine.minify_metric
herostools.actor.statemachine.allowed_types
class herostools.actor.statemachine.HERODatasourceStateMachine(loop, *args, http_port: int = 9090, bind_address: str = 'localhost', metrics_endpoint='/metrics', object_selector: str = '*', labels: dict = {}, **kwargs)[source]

Bases: heros.DatasourceObserver

A class that can observe and handle the data emitted by one or more datasource HEROs. In particular, this class provides an efficient way to listen to the data emitted by all datasource HEROs in the realm. By not instantiating the HEROs themselves but just subscribing to the topics for the datasource, this reduces the pressure on the backing zenoh network. If, however, only the data of a few HEROs should be observed, it might make more sense to just instantiate the according RemoteHEROs and connect a callback to their observable_data signal.

Parameters:
  • object_selector – selector to specify which objects to observe. This becomes part of a zenoh selector and thus

  • realm. (can be anything that makes sense in the selector. Defaults to * to observe all HEROs in the)

cache
_http_port = 9090
_bind_address = 'localhost'
_metrics_endpoint = '/metrics'
_global_labels
async _http_handle_metrics(request)[source]
async _start_webserver()[source]
_metric_name(key)[source]

create a clean name for a metric without special characters matching [a-z0-9_].

_unit_name(unit)[source]

cleans units to not contain special characters

_update(source_name, data)[source]

update the values in the cache for source_name

_convert_to_metrics(dsrs: heros.datasource.types.DatasourceReturnSet, prefix=None)[source]
get_cache()[source]
clear()[source]
herostools.actor.statemachine.loop