Created
April 6, 2011 07:40
-
-
Save chrismay/905281 to your computer and use it in GitHub Desktop.
list the ZFS datasets on a host and send graphite data on how full each one is.
This file contains 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
#!/opt/csw/bin/ruby | |
# | |
# | |
require 'socket' | |
def normalize_size(size) | |
multiples={'K' => (1024), | |
'M' => (1024 * 1024), | |
'G' => (1024 * 1024 * 1024), | |
'T' => (1024 * 1024 *1024 *1024) | |
} | |
if size.match /([0-9\.]+)([GMKT])?/ | |
multiplier = multiples[$2].to_i | |
if (multiplier == 0) then | |
multiplier =1 | |
end | |
amount = $1.to_f | |
return (amount * multiplier).to_f | |
else | |
raise("can't parse size " + size) | |
end | |
end | |
graphite_host='your-graphite-server-here' | |
graphite_port=2003 | |
s = TCPSocket.open(graphite_host, graphite_port) | |
host=`hostname`.chomp.gsub(/\./,'-'); | |
prefix="servers.#{host}.zfs." | |
now=Time.now().to_i | |
zfs_state=`/usr/sbin/zfs list -H -t filesystem -o name,available,used` | |
overfull = [] | |
zfs_state.each_line do |line| | |
parts = line.split(/\t/) | |
used = normalize_size(parts[2]) | |
size = normalize_size(parts[1]) + used | |
pcfree = ((1 - (used.to_f / size.to_f )) * 100).to_i | |
path=parts[0].gsub(/\//,'-') | |
s.puts( "#{prefix}#{path} #{used} #{now}") | |
end | |
s.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment