Skip to content

Instantly share code, notes, and snippets.

@thehar
Created March 7, 2014 18:31
Show Gist options
  • Select an option

  • Save thehar/9417100 to your computer and use it in GitHub Desktop.

Select an option

Save thehar/9417100 to your computer and use it in GitHub Desktop.
#!/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