Class: Bosh::Monitor::Plugins::Tsdb

Inherits:
Base
  • Object
show all
Defined in:
lib/bosh/monitor/plugins/tsdb.rb

Instance Attribute Summary

Attributes inherited from Base

#event_kinds, #logger, #options

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Bosh::Monitor::Plugins::Base

Instance Method Details

#process(event) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bosh/monitor/plugins/tsdb.rb', line 20

def process(event)
  if @tsdb.nil?
    @logger.error("Cannot deliver event, TSDB connection is not initialized")
    return false
  end

  return false if event.is_a? Bosh::Monitor::Events::Alert

  metrics = event.metrics

  if !metrics.kind_of?(Enumerable)
    raise PluginError, "Invalid event metrics: Enumerable expected, #{metrics.class} given"
  end

  metrics.each do |metric|
    tags = metric.tags.merge({deployment: event.deployment})
    @tsdb.send_metric(metric.name, metric.timestamp, metric.value, tags)
  end

  true
end

#runObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/bosh/monitor/plugins/tsdb.rb', line 9

def run
  unless EM.reactor_running?
    logger.error("TSDB delivery agent can only be started when event loop is running")
    return false
  end

  host = options["host"]
  port = options["port"]
  @tsdb = EM.connect(host, port, Bhm::TsdbConnection, host, port)
end

#validate_optionsObject



5
6
7
# File 'lib/bosh/monitor/plugins/tsdb.rb', line 5

def validate_options
  !!(options.kind_of?(Hash) && options["host"] && options["port"])
end