Class: MetricsInflux::Module::ProcLoadavg
- Defined in:
- lib/metrics_influx/module/procloadavg.rb
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
-
#initialize(config, params = {}) ⇒ ProcLoadavg
constructor
A new instance of ProcLoadavg.
- #sample ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(config, params = {}) ⇒ ProcLoadavg
Returns a new instance of ProcLoadavg.
7 8 9 10 |
# File 'lib/metrics_influx/module/procloadavg.rb', line 7 def initialize(config, params = {}) @config = config @params = params end |
Instance Method Details
#sample ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/metrics_influx/module/procloadavg.rb', line 12 def sample time_now = Time.now.to_i line = File.readlines('/proc/loadavg').first (avg_1min, avg_5min, avg_15min, procs, last_pid) = line.chomp.split(/\s+/, 5) (thread_run, thread_total) = procs.split(/\//, 2) { time: time_now, load_avg1min: avg_1min.to_f, load_avg5min: avg_5min.to_f, load_avg15min: avg_15min.to_f, entities_run: thread_run.to_i, entities_total: thread_total.to_i } end |