Class: Bipbip::Plugin::Network

Inherits:
Bipbip::Plugin show all
Defined in:
lib/bipbip/plugin/network.rb

Instance Attribute Summary

Attributes inherited from Bipbip::Plugin

#config, #frequency, #metric_group, #name, #tags

Instance Method Summary collapse

Methods inherited from Bipbip::Plugin

factory, factory_from_plugin, #initialize, #metrics_names, #run, #source_identifier

Methods included from InterruptibleSleep

#interrupt_sleep, #interruptible_sleep

Constructor Details

This class inherits a constructor from Bipbip::Plugin

Instance Method Details

#metrics_schemaObject



3
4
5
6
7
8
9
10
11
# File 'lib/bipbip/plugin/network.rb', line 3

def metrics_schema
  [
    { name: 'connections_total', type: 'gauge', unit: 'Connections' },
    { name: 'rx_errors', type: 'counter', unit: 'Errors' },
    { name: 'rx_dropped', type: 'counter', unit: 'Packets' },
    { name: 'tx_errors', type: 'counter', unit: 'Errors' },
    { name: 'tx_dropped', type: 'counter', unit: 'Packets' }
  ]
end

#monitorObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bipbip/plugin/network.rb', line 13

def monitor
  tcp_summary = `ss -s | grep '^TCP:'`
  tcp_counters = /^TCP:\s+(\d+) \(estab (\d+), closed (\d+), orphaned (\d+), synrecv (\d+), timewait (\d+)\/(\d+)\), ports (\d+)$/.match(tcp_summary)
  raise "Cannot match ss-output `#{tcp_summary}`" unless tcp_counters
  {
    'connections_total' => tcp_counters[1].to_i,
    'rx_errors' => _statistics_sum('rx_errors'),
    'rx_dropped' => _statistics_sum('rx_dropped'),
    'tx_errors' => _statistics_sum('tx_errors'),
    'tx_dropped' => _statistics_sum('tx_dropped')
  }
end