Skip to content

Commit

Permalink
Merge pull request #22 from xt99/patch-1
Browse files Browse the repository at this point in the history
Added include and ignore options for devices
  • Loading branch information
eheydrick committed Dec 8, 2015
2 parents 4a87d52 + 167ee2c commit 38a207a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions bin/metrics-disk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# USAGE:
#
# NOTES:
# Devices can be specifically included or ignored using -i or -I options:
# e.g. metrics-disk.rb -I [svx]d[a-z][0-9]*
#
# LICENSE:
# Copyright 2012 Sonian, Inc <[email protected]>
Expand Down Expand Up @@ -49,6 +51,18 @@ class DiskGraphite < Sensu::Plugin::Metric::CLI::Graphite
long: '--convert',
default: false

option :ignore_device,
description: 'Ignore devices matching pattern(s)',
short: '-i DEV[,DEV]',
long: '--ignore-device',
proc: proc { |a| a.split(',') }

option :include_device,
description: 'Include only devices matching pattern(s)',
short: '-I DEV[,DEV]',
long: '--include-device',
proc: proc { |a| a.split(',') }

# Main function
def run
# http://www.kernel.org/doc/Documentation/iostats.txt
Expand All @@ -62,6 +76,9 @@ def run
end
next if stats == ['0'].cycle.take(stats.size)

next if config[:ignore_device] && config[:ignore_device].find { |x| dev.match(x) }
next if config[:include_device] && !config[:include_device].find { |x| dev.match(x) }

metrics.size.times { |i| output "#{config[:scheme]}.#{dev}.#{metrics[i]}", stats[i] }
end

Expand Down

0 comments on commit 38a207a

Please sign in to comment.