metric sinks

class metrix.sinks.MSink[source]

Base class for subclasses that are called on a MElement and perform some useful action on it.

class metrix.sinks.MSinkPrinter[source]

Class that’s called on a MElement and prints it to stdout. That’s it! This class is useful in development when experimenting with MCoordinator so users can see stream contents, but is not suitable for production.

>>> from metrix import MElement, MSinkPrinter
>>> msink = MSinkPrinter()
>>> msink(MElement("foo", 1))
MElement(name=foo, value=1, tags=None)
class metrix.sinks.MSinkLogger(name: str = 'metrix.sinks', level: int = 20, msg_fmt_str: str = '%s')[source]

Class that’s called on a MElement and logs it, as-is.

>>> from metrix import MElement, MSinkLogger
>>> me = MElement("foo", 1)
>>> msink = MSinkLogger()
>>> msink(me)
INFO:metrix.sinks:MElement(name=foo, value=1, tags=None)
>>>  msink = MSinkLogger(name="my-logger", level=30, msg_fmt_str="[metric] %s")
WARNING:my-logger:[metric] MElement(name=foo, value=1, tags=None)
Parameters
  • name – Name of the logger to use when logging metric elements.

  • level – Level at which metric elements are logged.

  • msg_fmt_str – Message format string into which metric elements are merged using a string formatting operator. Must contain exactly one “%s” for a given MElement; may contain any other hard-coded text you wish.

logger

logging.Logger

level

int

msg_fmt_str

str

class metrix.sinks.MSinkTSDB(tsdb_client)[source]

Class that’s called on a MElement and sends its data to OpenTSDB via an instantiated TSDB client.

Parameters

tsdb_client – Instantiated TSDB client with a send method, such as potsdb.Client.

tsdb_client

Note

It’s the user’s responsibility to ensure that a suitable TSDB client library is available in the environment where this class is instantiated.