vaping.plugins

Classes


EmitBase

EmitBase(vaping.plugins.PluginBase)

Base class for emit plugins, used for sending data

expects method emit() to be defined

Methods

__init__

def __init__(self, config, ctx)

Arguments

  • config (dict)
  • ctx: vaping context

emit

def emit(self, message)

accept message to emit


FileProbe

FileProbe(vaping.plugins.ProbeBase)

Probes a file and emits everytime a new line is read

Config

  • path (str): path to file
  • backlog (int=0): number of bytes to read from backlog
  • max_lines (int=1000): maximum number of lines to read during probe

Instanced Attributes

These attributes / properties will be available on instances of the class

  • backlog (int): number of bytes to read from backlog
  • fh (filehandler): file handler for opened file (only available if path is set)
  • max_lines (int): maximum number of liens to read during probe
  • path (str): path to file

Methods

__init__

def __init__(self, config, ctx, emit=None)

Arguments

  • config (dict)
  • ctx: vaping context

_run

def _run(self)

Greenlet._run(self)

Subclasses may override this method to take any number of arguments and keyword arguments.

.. versionadded:: 1.1a3 Previously, if no callable object was passed to the constructor, the spawned greenlet would later fail with an AttributeError.


probe

def probe(self)

Probe the file for new lines


process_line

def process_line(self, line, data)

override this - parse your line in here


process_messages

def process_messages(self, messages)

override this - process your messages before they are emitted


process_probe

def process_probe(self, data)

override this - assign your data values here


validate_file_handler

def validate_file_handler(self)

Here we validate that our filehandler is pointing to an existing file.

If it doesnt, because file has been deleted, we close the filehander and try to reopen


PluginBase

PluginBase(gevent._greenlet.Greenlet)

Base plugin interface

Calls self.init() prefork while loading all modules, init() should not do anything active, any files opened may be closed when it forks.

Plugins should prefer init() to __init__() to ensure the class is completely done initializing.

Calls self.on_start() and self.on_stop() before and after running in case any connections need to be created or cleaned up.

Instanced Attributes

These attributes / properties will be available on instances of the class

  • config (dict): plugin config
  • groups (@property): dict - group configurations keyed by name
  • log (@property): logger instance for plugin type
  • vaping: reference to the main vaping object

Methods

__init__

def __init__(self, config, ctx)

Arguments

  • config (dict)
  • ctx: vaping context

_run

def _run(self)

Greenlet._run(self)

Subclasses may override this method to take any number of arguments and keyword arguments.

.. versionadded:: 1.1a3 Previously, if no callable object was passed to the constructor, the spawned greenlet would later fail with an AttributeError.


init

def init(self)

called after the plugin is initialized, plugin may define this for any other initialization code


new_message

def new_message(self)

creates and returns new message dict, setting type, source, ts, data

data is initialized to an empty array

Returns

message (dict)


on_start

def on_start(self)

called when the daemon is starting


on_stop

def on_stop(self)

called when the daemon is stopping


popen

def popen(self, args, **kwargs)

creates a subprocess with passed args

Returns

Popen instance


ProbeBase

ProbeBase(vaping.plugins.PluginBase)

Base class for probe plugin, used for getting data

expects method probe() to be defined

Methods

__init__

def __init__(self, config, ctx, emit=None)

Arguments

  • config (dict)
  • ctx: vaping context

_run

def _run(self)

Greenlet._run(self)

Subclasses may override this method to take any number of arguments and keyword arguments.

.. versionadded:: 1.1a3 Previously, if no callable object was passed to the constructor, the spawned greenlet would later fail with an AttributeError.


emit_all

def emit_all(self)

emit and remove all emissions in the queue


init

def init(self)

called after the plugin is initialized, plugin may define this for any other initialization code


probe

def probe(self)

probe for data, return a list of dicts


queue_emission

def queue_emission(self, msg)

queue an emission of a message for all output plugins

Arguments

  • msg (dict): dict containing type, source, ts and data keys

send_emission

def send_emission(self)

emit and remove the first emission in the queue


TimeSeriesDB

TimeSeriesDB(vaping.plugins.EmitBase)

Base interface for timeseries db storage plugins

Config

  • filename (str): database file name template
  • field (str): fieeld name to read the value from

Instanced Attributes

These attributes / properties will be available on instances of the class

  • field (str): fieeld name to read the value from
  • filename (str): database file name template

Methods

__init__

def __init__(self, config, ctx)

Arguments

  • config (dict)
  • ctx: vaping context

create

def create(self, filename)

Create database

Arguments

  • filename (str): database filename

emit

def emit(self, message)

emit to database

Arguments

  • message (dict): vaping message dict

filename_formatters

def filename_formatters(self, data, row)

Returns a dict containing the various filename formatter values

Values are gotten from the vaping data message as well as the currently processed row in the message

Arguments

  • data (dict): vaping message
  • row (dict): vaping message data row

Returns

formatter variables (dict)


format_filename

def format_filename(self, data, row)

Returns a formatted filename using the template stored in self.filename

Arguments

  • data (dict): vaping message
  • row (dict): vaping message data row

Returns

formatted version of self.filename (str)


get

def get(self, filename, from_time, to_time)

Retrieve data from database for the specified timespan

Arguments

  • filename (str): database filename
  • from_time (int): epoch timestamp start
  • to_time (int): epoch timestamp end

update

def update(self, filename, time, value)

Update database

Arguments

  • filename (str): database filename
  • time (int): epoch timestamp
  • value (mixed)

TimedProbe

TimedProbe(vaping.plugins.ProbeBase)

Probe class that calls probe every config defined interval

Methods

__init__

def __init__(self, config, ctx, emit=None)

Arguments

  • config (dict)
  • ctx: vaping context

_run

def _run(self)

Greenlet._run(self)

Subclasses may override this method to take any number of arguments and keyword arguments.

.. versionadded:: 1.1a3 Previously, if no callable object was passed to the constructor, the spawned greenlet would later fail with an AttributeError.