Sha256: bb2e8f11aeab240943ec5bb6ffc27344f1afb0c38dff71ec8214655e9e0a82d7
Contents?: true
Size: 1.22 KB
Versions: 4
Compression:
Stored size: 1.22 KB
Contents
module Salus class BaseRenderer include Logging def self.inherited(subclass) @@descendants ||= [] @@descendants << subclass end def self.descendants @@descendants || [] end def initialize(opts={}) @separator = opts.fetch(:separator, '.') @allow_mute = opts.fetch(:allow_mute, false) end def render(data) # Implement renderer raise "Unimplemented" end def iterate(node, prefix="", &block) case node when Hash node.each do |name, item| iterate(item, join_name(prefix, name), &block) end when Salus::Group node.each(@allow_mute) do |name, metric| iterate(metric, join_name(prefix, name), &block) end if node.has_subgroups? node.groups.each do |name, group| iterate(group, join_name(prefix, name), &block) end end when Salus::Metric block.call(prefix, node) unless node.expired? else log WARN, "Unknown node type #{node.class}" end end protected def join_name(prefix, name) prefix + (prefix.empty? ? '' : @separator) + name end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
salus-0.2.1 | lib/salus/renderer/base.rb |
salus-0.2.0 | lib/salus/renderer/base.rb |
salus-0.1.3 | lib/salus/renderer/base.rb |
salus-0.1.2 | lib/salus/renderer/base.rb |