class Salus::CollectdRenderer

Public Class Methods

new(opts={}) click to toggle source
Calls superclass method Salus::BaseRenderer::new
# File lib/salus/renderer/collectd.rb, line 3
def initialize(opts={})
  opts[:separator] = opts.fetch(:separator, '/')
  super(opts)
end

Public Instance Methods

render(data) click to toggle source
# File lib/salus/renderer/collectd.rb, line 8
def render(data)
  hostname = ENV.fetch('COLLECTD_HOSTNAME', 'localhost')
  options  = ENV.key?('COLLECTD_INTERVAL') ? "interval=#{ENV['COLLECTD_INTERVAL']} " : ''
  iterate(data) do |name, metric|
    # Text metrics are unsupported
    next if metric.is_a? Salus::Text
    unless metric.timestamp.nil?
      # Effectively all salus metrics are gauges for collectd, with exception to text
      STDOUT.puts "PUTVAL #{hostname}#{@separator}#{name} #{options}#{metric.timestamp.to_i}:#{metric.value.nil? ? 'U' : metric.value}"
    end
  end
end