Class: Fluent::TDMonitorAgentInput::BandwidthStat

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

Overview

bandwidth used ratio in bytes/s

Instance Method Summary collapse

Constructor Details

#initialize(interval) ⇒ BandwidthStat

Returns a new instance of BandwidthStat.



406
407
408
409
# File 'lib/fluent/plugin/in_td_monitor_agent.rb', line 406

def initialize(interval)
  @interval = interval
  @bytes_cache = current_total_bytes
end

Instance Method Details

#current_total_bytesObject



418
419
420
421
422
423
424
425
# File 'lib/fluent/plugin/in_td_monitor_agent.rb', line 418

def current_total_bytes
  network_bytes = `grep eth0: /proc/net/dev`.lstrip[5..-1].strip.split(/\s+/)
  received_bytes = network_bytes[0].to_i
  transmitted_bytes = network_bytes[8].to_i
  received_bytes + transmitted_bytes
rescue => e
  0
end

#statsObject



411
412
413
414
415
416
# File 'lib/fluent/plugin/in_td_monitor_agent.rb', line 411

def stats
  res = {}
  last_bytes, @bytes_cache = @bytes_cache, current_total_bytes
  res['ratio'] = (@bytes_cache - last_bytes) / @interval
  res
end