Class: Fluent::TDMonitorAgentInput::CpuStat
- Inherits:
-
Object
- Object
- Fluent::TDMonitorAgentInput::CpuStat
- 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
-
#initialize ⇒ CpuStat
constructor
A new instance of CpuStat.
- #stats ⇒ Object
Constructor Details
#initialize ⇒ CpuStat
Returns a new instance of CpuStat.
293 294 295 |
# File 'lib/fluent/plugin/in_td_monitor_agent.rb', line 293 def initialize @stats = cpu_stats end |
Instance Method Details
#stats ⇒ Object
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/fluent/plugin/in_td_monitor_agent.rb', line 300 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 |