Sink

class metricq.Sink(*args, add_uuid=True, **kwargs)

A base class intended to be subclassed to create user-defined Sinks.

See Building a MetricQ Sink for an introduction how to implement a Sink.

Parameters:
add_uuid : bool (default: True)

whether to append a randomly generated UUID to this Sink’s Token. This is useful to distinguish different instances of the same Sink.

await connect()

Connect to the MetricQ network

Return type:

None

abstractmethod await on_data(metric, timestamp, value)

A Callback that is invoked for every data point received for any of the metrics this client is subscribed to.

User-defined Sinks need to override this method to handle incoming data points.

Parameters:
metric : str

name of the metric for which a new data point arrived

timestamp : Timestamp

timepoint at which this metric was measured

value : float

value of the metric at time of measurement

Return type:

None

await subscribe(metrics, expires=None, metadata=None, **kwargs)

Subscribe to a list of metrics.

Parameters:
metrics : Iterable[str]

names of the metrics to subscribe to

expires : int | float | NoneUnion[int, float, None] (default: None)

queue expiration time in seconds

metadata : bool | NoneOptional[bool] (default: None)

whether to return metric metadata in the response, defaults to True as per the RPC spec

Return type:

dict[str, Any]

Returns:

rpc response


class metricq.DurableSink(*args, **kwargs)

A base class for user-defined Sinks that uses a configuration. General Sink implementations are transient and therefore do not register as unique agents with a configuration. This implementation does call the sink.register RPC and receives a configuration in response that is passed to the config rpc handler.

See Sink for the general API.

Constructor arguments are passed to Sink. However, add_uuid is not supported and always False.