Calling Rrdtool from Ruby

1 Make sure rrdtool is in your path or change the call to rrdtool to include explicit path
 def gen
      i = rand(90)
      rstr = sprintf "N:%.2f", 40.0 * Math.sin(i)
      rstr
  end
 
  def genMultiple
      i = rand(90)
      rstr = sprintf "N:%0.3f", i
      rstr
  end
 
  create = 0
  update = 0
  rrdFile = "temperature.rrd"
 
  def create
  puts "create"
  cmd = <<EOF
  rrdtool create \
  #{rrdFile} --step 1 \
   DS:temp:GAUGE:10:-100:100 \
   RRA:AVERAGE:0.5:1:10
  EOF
 
  puts cmd
  exec cmd
  end
 
  def update
  puts "update"
  cmd = <<EOF
  rrdtool update \
  #{rrdFile} \
  #{genMultipl}
  EOF
 
  puts cmd
  exec cmd
  end
 def graph
  puts "graph"
  cmd = <<EOF
  rrdtool graph /home/madan/public_html/gr.png \
  DEF:ds0a=temperature.rrd:temp:AVERAGE
  EOF
 
  puts cmd
  exec cmd
  end
 
  # main
  create
  10.times do
      update
      sleep 1
  end
 
  graph

rubyrrd.txt · Last modified: 2014/10/26 01:52 (external edit)
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0