Class: Fluent::Plugin::TDMonitorAgentInput::BandwidthStat
- Inherits:
-
Object
- Object
- Fluent::Plugin::TDMonitorAgentInput::BandwidthStat
- Defined in:
- lib/fluent/plugin/in_td_monitor_agent.rb
Overview
bandwidth used ratio in bytes/s
Instance Method Summary collapse
- #current_total_bytes ⇒ Object
-
#initialize(interval) ⇒ BandwidthStat
constructor
A new instance of BandwidthStat.
- #stats ⇒ Object
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_bytes ⇒ Object
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 |
#stats ⇒ Object
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 |