Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
metrics
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
Something went wrong with that request. Please try again.