Class: Fluent::Plugin::TDMonitorAgentInput::CpuStat

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/in_td_monitor_agent.rb

Overview

TODO: Get fluentd’s process usage of CPU and Memory

Constant Summary collapse

CPU_KEYS =
%W(user nice system idle iowait irq sirq)
USE_CPU_KEYS =
[0, 2]

Instance Method Summary collapse

Constructor Details

#initializeCpuStat

Returns a new instance of CpuStat.



294
295
296
# File 'lib/fluent/plugin/in_td_monitor_agent.rb', line 294

def initialize
  @stats = cpu_stats
end

Instance Method Details

#statsObject



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/fluent/plugin/in_td_monitor_agent.rb', line 301

def stats
  res = {}

  stats = cpu_stats
  diff  = @stats.map.with_index { |stat, i| stats[i] - stat }
  total = diff.inject(0) { |sum, n| sum + n }
  total = 1 if total.zero?

  diff.each_with_index { |stat, i|
    if USE_CPU_KEYS.include?(i)
      res[CPU_KEYS[i]] = stat.to_f / total * 100
    end
  }
  @stats = stats
  res['loadavg1'] = loadavg_stats

  res
end