Created
March 7, 2014 18:31
-
-
Save thehar/9417100 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env /opt/sensu/embedded/bin/ruby | |
| require 'rubygems' if RUBY_VERSION < '1.9.0' | |
| require 'sensu-plugin/metric/cli' | |
| require 'socket' | |
| class DiskGraphite < Sensu::Plugin::Metric::CLI::Graphite | |
| option :scheme, | |
| :description => "Metric naming scheme, text to prepend to metric", | |
| :short => "-s SCHEME", | |
| :long => "--scheme SCHEME", | |
| :default => "#{Socket.gethostname}.disk" | |
| def run | |
| # http://www.kernel.org/doc/Documentation/iostats.txt | |
| metrics = [ | |
| 'reads', 'readsMerged', 'sectorsRead', 'readTime', | |
| 'writes', 'writesMerged', 'sectorsWritten', 'writeTime', | |
| 'ioInProgress', 'ioTime', 'ioTimeWeighted' | |
| ] | |
| File.open("/proc/diskstats", "r").each_line do |line| | |
| stats = line.strip.split(/\s+/) | |
| major, minor, dev = stats.shift(3) | |
| next if stats == ['0'].cycle.take(stats.size) | |
| metrics.size.times { |i| output "#{config[:scheme]}.#{dev}.#{metrics[i]}", stats[i] } | |
| end | |
| ok | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment