Class: Fluent::Plugin::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.



403
404
405
406
# File 'lib/fluent/plugin/in_td_monitor_agent.rb', line 403

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

Instance Method Details

#current_total_bytesObject



415
416
417
418
419
420
421
422
# File 'lib/fluent/plugin/in_td_monitor_agent.rb', line 415

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



408
409
410
411
412
413
# File 'lib/fluent/plugin/in_td_monitor_agent.rb', line 408

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