Well, sometimes one wonders why people write tools that wheight a megabyte, when it’s easy to stick together one or two tools with a script and have the same thing.

Here’s a ruby script that generates a ping latency graph (target is google):

#!/usr/bin/ruby
#
# based on
#   http://oss.oetiker.ch/rrdtool/prog/rrdruby.en.html example
# with help of the tutorial
#   http://oss.oetiker.ch/rrdtool/tut/rrdtutorial.en.html
# and the docu
#   http://oss.oetiker.ch/rrdtool/doc/rrdcreate.en.html
# 
# placed in the public domain by Tomáš Pospíšek

require "RRD"

$rrd    = `mktemp /tmp/tmp.XXXXXXXX`.chomp
$grafik = `mktemp /tmp/tmp.XXXXXXXX`.chomp
$start  = 0

def now()
  Time.now.to_i
end

def create()
  $start=now()
  RRD.create(
    $rrd,
    "--start", "#{$start - 1}",
    "--step", "#{1}",       # every 1s
    "DS:pinglatency:GAUGE:10:0:200", # 10s of missing data are OK, min=0, max=200 (ping time)
    "RRA:AVERAGE:0.5:1:#{60*30}") # 60 seconds * 30 minutes
  puts "RRD database created #{$rrd} at #{$start}"
  puts "Your graph is at #{$grafik}"
end

def ping_latency
   `ping -c 1 -n -w 1 google.com` =~ /.* time=(\d+)/
  # 64 bytes from 74.125.43.147: icmp_seq=1 ttl=52 time=31.6 ms
  return $1
end

def update()
  puts "updating #{$rrd} with #{now()}:#{ping_latency()}"
  RRD.update($rrd, "#{now()}:#{ping_latency()}")
end

def generate_gfx()
  # puts "generating graph #{$grafik}"
  RRD.graph(
   "#{$grafik}",
    "--title", " Ping latency to Google",
month: "2010/06"
year: "2010"
    "--x-grid", "SECOND:10:MINUTE:1:MINUTE:2:0:%X",
    "--start", $start.to_s,
#    "--end", # -> now
    "--interlace",
    "--imgformat", "PNG",
    "--width=450",
    "DEF:pinglatency=#{$rrd}:pinglatency:AVERAGE",
    "AREA:pinglatency#00b6e4:ms")
end

#main
create()
while(true)
  update()
  generate_gfx()
  sleep 1
end

It generates a graph like this: