Skip to content

Instantly share code, notes, and snippets.

@lazzarello
Created December 12, 2010 00:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lazzarello/737743 to your computer and use it in GitHub Desktop.
Save lazzarello/737743 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby -w
require 'rubygems'
require 'RRD'
rrd = "/var/lib/munin/localdomain/localhost.localdomain-if_wlan0-up-c.rrd"
start = Time.now.to_i
# 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