class Bosh::Monitor::Plugins::Graphite
Public Instance Methods
process(event)
click to toggle source
# File lib/bosh/monitor/plugins/graphite.rb, line 19 def process(event) if (event.is_a? Bosh::Monitor::Events::Heartbeat) && event.node_id metrics = event.metrics unless metrics.kind_of?(Enumerable) raise PluginError, "Invalid event metrics: Enumerable expected, #{metrics.class} given" end metrics.each do |metric| metric_name = get_metric_name(event, metric) metric_timestamp = get_metric_timestamp(metric.timestamp) metric_value = metric.value @connection.send_metric(metric_name, metric_value, metric_timestamp) end end end
run()
click to toggle source
# File lib/bosh/monitor/plugins/graphite.rb, line 8 def run unless EM.reactor_running? logger.error("Graphite delivery agent can only be started when event loop is running") return false end host = options["host"] port = options["port"] @connection = EM.connect(host, port, Bhm::GraphiteConnection, host, port) end
validate_options()
click to toggle source
# File lib/bosh/monitor/plugins/graphite.rb, line 4 def validate_options !!(options.kind_of?(Hash) && options["host"] && options["port"]) end
Private Instance Methods
get_metric_name(heartbeat, metric)
click to toggle source
# File lib/bosh/monitor/plugins/graphite.rb, line 39 def get_metric_name heartbeat, metric [get_metric_prefix(heartbeat), metric.name.to_s.gsub('.', '_')].join '.' end
get_metric_prefix(heartbeat)
click to toggle source
# File lib/bosh/monitor/plugins/graphite.rb, line 43 def get_metric_prefix(heartbeat) deployment = heartbeat.deployment job = heartbeat.job id = heartbeat.node_id agent_id = heartbeat.agent_id if options["prefix"] [options["prefix"], deployment, job, id, agent_id].join '.' else [deployment, job, id, agent_id].join '.' end end
get_metric_timestamp(ts)
click to toggle source
# File lib/bosh/monitor/plugins/graphite.rb, line 55 def get_metric_timestamp(ts) if ts && is_epoch?(ts) return ts end Time.now.to_i end
is_epoch?(ts)
click to toggle source
# File lib/bosh/monitor/plugins/graphite.rb, line 63 def is_epoch?(ts) /^1[0-9]{9}$/.match(ts.to_s) end