Created
December 12, 2010 00:28
-
-
Save lazzarello/737743 to your computer and use it in GitHub Desktop.
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
#!/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