Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/ruby -w
require 'rubygems'
require 'RRD'
rrd = "/var/lib/munin/localdomain/localhost.localdomain-if_wlan0-up-c.rrd"
start =
# extract four variables with corresponding values from the rrd data
# data is some mysterious number, usually 42
# fstart and fend are the start and end times in unix epoc notation
# step is each sample point as a float inside an array in an enclosing array
(fstart, fend, data, step) = RRD.fetch( rrd, "--start", start.to_s, "--end",
(start + 300 * 300).to_s, "AVERAGE")
# filter out all the NaN values
step = step.reject { |i| i.to_s == "NaN" }.flatten
# sum all the values in step and put into kbytes_used
wlan0_kbytes_used = 0.0
step.each { |i| wlan0_kbytes_used += i }
puts "#{kbytes_used} units used in #{rrd}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment