Skip to content

Commit

Permalink
Adding option to only include interfaces whose operational status is up
Browse files Browse the repository at this point in the history
  • Loading branch information
johannagnarsson authored and majormoses committed Aug 7, 2018
1 parent c642122 commit 5f067f6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bin/metrics-net.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ class LinuxPacketMetrics < Sensu::Plugin::Metric::CLI::Graphite
long: '--include-device',
proc: proc { |a| a.split(',') }

option :only_up,
description: 'Include only devices whose interface status is up',
short: '-u',
long: '--only-up'

def run
timestamp = Time.now.to_i

Expand All @@ -83,6 +88,7 @@ def run

next if config[:ignore_device] && config[:ignore_device].find { |x| iface.match(x) }
next if config[:include_device] && !config[:include_device].find { |x| iface.match(x) }
next if config[:only_up] && File.open(iface_path + '/operstate').read.strip != 'up'

tx_pkts = File.open(iface_path + '/statistics/tx_packets').read.strip
rx_pkts = File.open(iface_path + '/statistics/rx_packets').read.strip
Expand Down

0 comments on commit 5f067f6

Please sign in to comment.