Created
October 6, 2012 05:14
-
-
Save Atalanta/3843980 to your computer and use it in GitHub Desktop.
metrics
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
require 'json' | |
def metrics(values, keys) | |
Hash[keys.zip(values)] | |
end | |
values = %x[free -m].match(/cache:\s+(\d+)\s+(\d+)\n/).captures | |
keys = ["memory-buffers", "memory-cached"] | |
data = metrics(values, keys) | |
values = File.read('/proc/loadavg').match(/^(\d+\.\d{2}) (\d+\.\d{2}) (\d+\.\d{2})/).captures | |
keys = ["load-1", "load-5", "load-15"] | |
data.update(metrics(values, keys)) | |
filesystems = %x[df -P].split("\n").reject { |lines| lines =~ /1024-blocks|tmpfs/ } | |
filesystems.each do |fs| | |
values = fs.match(/^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\%\s+(.+)$/).captures | |
name = values.shift.gsub('/', '-') | |
keys = ["fs#{name}-size", "fs#{name}-used", "fs#{name}-free", "fs#{name}-%-used", "fs#{name}-mountpoint"] | |
data.update(metrics(values, keys)) | |
end | |
puts data.to_json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment