Masterpiece Influx Time Series Plugin — masterpiece documentation

# Masterpiece Influx Time Series Plugin

## Description

InfluxDB V3 time series database.

class masterpiece_influx.Influx(name='influx', host=None, token=None, org=None, database=None)

  Bases: `TimeSeries`

  InfluxDB V3 implementation of a time series database for MasterPiece.

  This class provides an interface for interacting with an InfluxDB V3 time series database. The host, token, org, and database attributes are inherited from the TimeSeries superclass and can be initialized through the configuration system or overridden via constructor parameters.

  host

    Hostname of the InfluxDB server.

    Type:

      str

  token

    Authentication token for InfluxDB.

    Type:

      str

  org

    Organization name for InfluxDB.

    Type:

      str

  database

    Database name for InfluxDB.

    Type:

      str

  influx_client

    The client instance used for database operations.

    Type:

      InfluxDBClient3

  Example

  Creating a custom instance with specific parameters:

      db = Influx(
          host="example.com",
          token="my-token",
          org="my-org",
          database="my-db"
      )

  acquire_time_spent()

    Reads off the average time the thread has spent in its update() method since the last call, and resets the statistics for the next measurement cycle. This method can be used for monitoring healtiness of the thread.

    Returns:

      elapsed seconds.

    Return type:

      elapsed (float)

  classmethod classattrs_from_dict(attributes)

    Set only the class’s own attributes from a dictionary.

    Return type:

      `None`

  classmethod classattrs_to_dict()

    Convert the class’s own attributes to a dictionary, excluding inherited and private ones.

    Return type:

      `dict`[`str`, `Any`]

  copy()

    Create and return a copy of the current object.

    This method serializes the current object to a dictionary using the to_dict method, creates a new instance of the object’s class, and populates it with the serialized data using the from_dict method.

    This method uses class identifier based instantiation (see factory method pattern) to create a new instance of the object, and ‘to_dict’ and ‘from_dict’ methods to initialize object’s state.

    Return type:

      `MasterPiece`

    Returns:

      A new instance of the object’s class with the same state as the original object.

    Example:

        clone_of_john = john.copy()

  database: str = ''
  debug(msg, details='')

    Logs the given debug message to the application log.

    Parameters:

      - msg (str) – The information message to be logged.

      - details (str) – Additional detailed information for the message to be logged

    Return type:

      `None`

  do(action, context)

    Execute the given action to the object, by calling the provided action.

    Parameters:

      - action (Callable[["MasterPiece", dict[str, Any]], bool]) – A callable that takes

      - (node

      - boolean. (context) and returns a)

      - context (dict[str, Any]) – Any context data that the action may use.

    Return type:

      `bool`

    Returns:

      The return value from the executed action.

  error(msg, details='')

    Logs the given error message to the application log.

    Parameters:

      - msg (str) – The message to be logged.

      - details (str) – Additional detailed information for the message to be logged

    Return type:

      `None`

  classmethod factory()

    Fetch the dictionary holding class names and associated classes.

    Returns:

      with class names and associated classes

    Return type:

      factory

  classmethod find_class(class_id)

    Create an instance of the class corresponding to the given class identifier.

    Parameters:

      - class_id (str) – Identifier of the class to instantiate.

      - *args – Optional arguments to pass to the class constructor.

    Returns:

      An instance of the class corresponding to the given class identifier.

    Return type:

      MasterPiece

  from_dict(data_dict)
    Return type:

      `None`

  classmethod get_class_id()

    Return the class id of the class. Each class has an unique name that can be used for instantiating the class via `Object.instantiate()` method.

    Parameters:

      cls (class) – class

    Returns:

      unique class identifier through which the class can be instantiated by factory method pattern.

    Return type:

      id (str)

  classmethod has_class_method_directly(method_name)

    Check if the method is defined directly in the class (not inherited).

    Return type:

      `bool`

  host: str = ''
  info(msg, details='')

    Logs the given information message to the application log.

    Parameters:

      - msg (str) – The information message to be logged.

      - details (str) – Additional detailed information for the message to be logged

    Return type:

      `None`

  classmethod init_class(clazz)

    Initialize class. Registers the class into the class factory .

    Parameters:

      clazz (class) – class to be initialized

    Return type:

      `None`

  classmethod instantiate(class_id, *args)

    Create an instance of the class corresponding to the given class identifier.

    Parameters:

      - class_id (str) – Identifier of the class to instantiate.

      - *args (`Any`) – Optional arguments to pass to the class constructor.

    Returns:

      An instance of the class corresponding to the given class identifier.

    Return type:

      MasterPiece

  classmethod log_debug(msg, details='')

    Logs the given debug message to the application log.

    Parameters:

      - msg (str) – The message to be logged.

      - details (str) – Additional detailed information for the message to be logged

    Return type:

      `None`

  classmethod log_error(msg, details='')

    Logs the given message to the application log.

    Parameters:

      - msg (str) – The message to be logged.

      - details (str) – Additional detailed information for the message to be logged

    Return type:

      `None`

  classmethod log_info(msg, details='')

    Logs the given message to the application log.

    Parameters:

      - msg (str) – The message to be logged.

      - details (str) – Additional detailed information for the message to be logged

    Return type:

      `None`

  classmethod log_warning(msg, details='')

    Logs the given debug message to the application log.

    Parameters:

      - msg (str) – The message to be logged.

      - details (str) – Additional detailed information for the message to be logged

    Return type:

      `None`

  make_url()

    Generate the URL for the composite, including all children.

    Return type:

      `URL`

  measurement(measurement)
    Return type:

      `Measurement`

  org: str = ''
  property parent: MasterPiece | None
  read_dict(measurement, start_time, end_time=None, tags=None, fields=None)
    Return type:

      `list`[`dict`[`str`, `Any`]]

  read_last_value(measurement, tags=None, fields=None)
    Return type:

      `dict`[`str`, `Any`]

  read_point(measurement, start_time, end_time=None, tags=None, fields=None)
    Return type:

      `list`[`Any`]

  classmethod register()

    Register the class.

    Called immediately upon class initialization, right before the class attributes are loaded from the class specific configuration files.

    Subclasses can extend this with custom register functionality:

        class MyMasterPiece(MasterPiece):

            @classmethod
            def register(cls):
                super().register()  # Don't forget
                cls._custom_field = True

    Return type:

      `None`

  resolve_url(url)

    Find a MasterPiece in the hierarchy matching the URL.

    Return type:

      `Optional`[`MasterPiece`]

  root()

    Fetch the root object

    Returns:

      root object

    Return type:

      MasterPiece

  run()

    Run the masterpiece. Dispatches the call to payload object and returns the control to the caller.

    Return type:

      `None`

  run_forever()

    Run the payload forever. This method will return only when violently terminated. If the object does not have playload object, or it is not instance of ‘MasterPiece’ class then returns immediately and this method has no effect.

    Return type:

      `None`

  classmethod set_log(l)

    Set logger.

    Parameters:

      l (logger) – logger object

    Return type:

      `None`

  shutdown()

    Shutdown the payload object. If the payload object is None, or is not instance of MasterPiece, then the call has no effect.

    Return type:

      `None`

  to_dict()
    Return type:

      `dict`[`str`, `Any`]

  token: str = ''
  update_metrics(elapsed)

    Updates the number of update() methods calld, and time spent in the method. This method is called internally from the update() method.

    Parameters:

      elapsed (float) – elapsed seconds.

    Return type:

      `None`

  warning(msg, details='')

    Logs the given warning message to the application log.

    Parameters:

      - msg (str) – The message to be logged.

      - details (str) – Additional detailed information for the message to be logged

    Return type:

      `None`

  write(point)
    Return type:

      `None`

  write_dict(name, tags, fields, ts)
    Return type:

      `None`

class masterpiece_influx.InfluxMeasurement(measurement_name, tags=None, fields=None, timestamp=None)

  Bases: `Point`, `Measurement`

  Concrete implementation of the Measurement class for InfluxDB. Supports both dictionary-based and fluent interface initialization.

  field(field, value)

    Add a field to the measurement and return self for method chaining.

    Return type:

      `InfluxMeasurement`

  from_dict(data)

    Populate the InfluxMeasurement from a dictionary.

    Return type:

      `InfluxMeasurement`

  static measurement(measurement)

    Create a new Point with specified measurement name.

  classmethod set_str_rep(rep_function)

    Set the string representation for all Points.

  tag(tag, value)

    Add a tag to the measurement and return self for method chaining.

    Return type:

      `InfluxMeasurement`

  time(timestamp)

    Set the timestamp for the measurement and return self for method chaining.

    Return type:

      `InfluxMeasurement`

  to_dict()

    Convert the InfluxMeasurement to a dictionary.

    Return type:

      `Dict`[`str`, `Any`]

  to_line_protocol(precision=None)

    Create LineProtocol.

  validate()

    Validate the measurement data. - Ensure it has at least one field (InfluxDB requires fields). - Validate that tags and fields are dictionaries.

    Return type:

      `bool`

  property write_precision

    Get precision.