Class: Salus::StdoutRenderer

Inherits:
BaseRenderer show all
Defined in:
lib/salus/renderer/stdout.rb

Instance Method Summary collapse

Methods inherited from BaseRenderer

descendants, inherited, #iterate

Methods included from Logging

#log

Constructor Details

#initialize(opts = {}) ⇒ StdoutRenderer

Returns a new instance of StdoutRenderer.



3
4
5
6
# File 'lib/salus/renderer/stdout.rb', line 3

def initialize(opts={})
  super(opts)
  @precision = opts.fetch(:precision, 2)
end

Instance Method Details

#render(data) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/salus/renderer/stdout.rb', line 8

def render(data)
  iterate(data) do |name, metric|
    value = metric.value
    unless metric.is_a?(Salus::Text)
      value = "%.#{@precision}f" % value unless value.nil?
    end
    STDOUT.puts "[#{Time.at(metric.timestamp)}] #{name} - #{value}" unless metric.timestamp.nil?
  end
end