Class: Hallmonitor::Outputters::Influxdb

Inherits:
Hallmonitor::Outputter show all
Defined in:
lib/hallmonitor/outputters/influxdb.rb

Overview

An outputter for InfluxDB

Defined Under Namespace

Classes: EventData

Instance Attribute Summary

Attributes inherited from Hallmonitor::Outputter

#name

Instance Method Summary collapse

Constructor Details

#initialize(influxdb_client, tags = {}, transformer = nil) ⇒ Influxdb

Builds a new Influxdb outputter

Parameters:

  • influxdb_client (InfluxDB::Client)

    client instance to use

  • tags (Hash) (defaults to: {})

    Set of default tags applied to all events output to InfluxDB, will be overridden by tags set by events if they conflict

  • transformer (#transform(Event, EventData)) (defaults to: nil)

    An object that responds to #transform(Event, EventData). If supplied it will be passed the EventData struct that has been built so far and it should return an EventData struct that will be written out to InfluxDB. This allows a hook to modify data before it is written out to InfluxDB

Raises:

  • if influxdb_client does not respond to :write_point (InfluxDB::Client contract)



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/hallmonitor/outputters/influxdb.rb', line 25

def initialize(influxdb_client, tags = {}, transformer = nil)
  unless influxdb_client.respond_to?(:write_point)
    raise 'Supplied InfluxDB Client was not as expected'
  end

  if transformer && !transformer.respond_to?(:transform)
    raise 'Supplied transformer does not respond to :transform'
  end

  super('influxdb')
  @tags = {}.merge(tags)
  @client = influxdb_client || raise('Must supply an InfluxDb client')
  @transformer = transformer
end

Instance Method Details

#process(event) ⇒ Object

Sends events to InfluxDB instance

Parameters:



42
43
44
45
# File 'lib/hallmonitor/outputters/influxdb.rb', line 42

def process(event)
  event_data = build_event_data(event)
  transform_and_write(event, event_data)
end