class Snmp2mkr::Collector
Attributes
host[R]
host_manager[R]
logger[R]
metrics_state_holder[R]
mib[R]
sender_queue[R]
Public Class Methods
new(host, metrics_state_holder:, host_manager:, sender_queue: nil, logger: Logger.new(File::NULL), mib: Mib.default)
click to toggle source
# File lib/snmp2mkr/collector.rb, line 10 def initialize(host, metrics_state_holder:, host_manager:, sender_queue: nil, logger: Logger.new(File::NULL), mib: Mib.default) @host = host @metrics_state_holder = metrics_state_holder @host_manager = host_manager @sender_queue = sender_queue @logger = logger @mib = mib end
Public Instance Methods
inspect()
click to toggle source
# File lib/snmp2mkr/collector.rb, line 19 def inspect "#<#{self.class}:#{'%x' % __id__}, #{host.name.inspect}>" end
perform!()
click to toggle source
# File lib/snmp2mkr/collector.rb, line 29 def perform! metric_values = vhosts.flat_map do |vhost| vhost.metrics.map do |metric| val = metric.evaluate(snmp_values[metric.oid.to_s], state_holder: metrics_state_holder, time: snmp_time) next if val.nil? {vhost: vhost, host: host, name: metric.safe_name, value: val, time: snmp_time} end.compact end SendRequests::Metrics.new(metric_values).tap do |req| sender_queue << req end rescue ClosedQueueError => e logger.warn "#{e.inspect} (during shutdown?)" end
snmp_time()
click to toggle source
# File lib/snmp2mkr/collector.rb, line 44 def snmp_time snmp_values; @snmp_time end
snmp_values()
click to toggle source
# File lib/snmp2mkr/collector.rb, line 48 def snmp_values @snmp_values ||= begin @snmp_time = Time.now host.snmp do |snmp| oids = vhosts.flat_map(&:metrics).map(&:oid).map(&:to_s).uniq snmp.get(oids).map do |vb| [vb.oid.to_s, vb] end.to_h end end end
vhosts()
click to toggle source
# File lib/snmp2mkr/collector.rb, line 25 def vhosts host_manager.vhosts(host) end