Class: LogStash::Instrument::PeriodicPoller::Os

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/instrument/periodic_poller/os.rb

Constant Summary

Constants inherited from Base

Base::DEFAULT_OPTIONS

Instance Attribute Summary

Attributes inherited from Base

#metric

Instance Method Summary collapse

Methods inherited from Base

#start, #stop, #update

Methods included from Util::Loggable

included, #logger, #slow_logger

Constructor Details

#initialize(metric, options = {}) ⇒ Os

Returns a new instance of Os.



7
8
9
# File 'lib/logstash/instrument/periodic_poller/os.rb', line 7

def initialize(metric, options = {})
  super(metric, options)
end

Instance Method Details

#collectObject



11
12
13
# File 'lib/logstash/instrument/periodic_poller/os.rb', line 11

def collect
  collect_cgroup
end

#collect_cgroupObject



15
16
17
18
19
# File 'lib/logstash/instrument/periodic_poller/os.rb', line 15

def collect_cgroup
  if stats = Cgroup.get
    save_metric([:os], :cgroup, stats)
  end
end

#save_metric(namespace, k, v) ⇒ Object

Recursive function to create the Cgroups values form the created hash



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/logstash/instrument/periodic_poller/os.rb', line 22

def save_metric(namespace, k, v)
  if v.is_a?(Hash)
    v.each do |new_key, new_value|
      n = namespace.dup
      n << k.to_sym
      save_metric(n, new_key, new_value)
    end
  else
    metric.gauge(namespace, k.to_sym, v)
  end
end