cobald.monitor.format_line module

class cobald.monitor.format_line.LineProtocolFormatter(tags: Optional[Union[Dict[str, Any], Set[str]]] = None, resolution: Optional[float] = None)[source]

Bases: Formatter

Formatter that emits data as InfluxDB Line Protocol

  • tags – record data to use as tags

  • resolution – resolution of timestamps in seconds

The tags act as a whitelist for record keys if they are an iterable. When a dictionary is supplied, its values act as default values if the key is not in a record.

The resolution allows summarising data by downsampling the timestamps to the given resolution, e.g. for a resolution of 10 you can expect timestamps 10, 20, 30, … If resolution is None the timestamp is omitted from the Line Protocol and Telegraf will take care on setting the current timestamp.

format(record: LogRecord) str[source]

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

cobald.monitor.format_line.escape_field(field: T) T[source]
cobald.monitor.format_line.escape_key(key: str) str[source]
cobald.monitor.format_line.line_protocol(name, tags: Optional[dict] = None, fields: Optional[dict] = None, timestamp: Optional[float] = None) str[source]

Format a report as per InfluxDB line protocol

  • name – name of the report

  • tags – tags identifying the specific report

  • fields – measurements of the report

  • timestamp – when the measurement was taken, in seconds since the epoch