963344711b9419d32497acb55ad351340bf4a567
[rrdtool.git] / doc / rrdruby.pod
1 =head1 NAME
2
3 rrdruby - About the RRD Ruby bindings
4
5 =head1 SYNOPSIS
6
7  require "RRD"
8  RRD.create(
9     rrd,
10     "--step", "300",
11     "DS:a:GAUGE:600:U:U",
12     "DS:b:GAUGE:600:U:U",
13     "RRA:AVERAGE:0.5:1:300")
14
15 =head1 DESCRIPTION
16
17 The B<rrdtool> functions are directly callable via the Ruby programming
18 language. This wrapper implementation has been written from the scratch
19 (without  SWIG)
20
21 The API's simply expects string parameters to the functions.  Please refer
22 to the other B<rrdtool> documentation for functions and valid arguments.
23
24 =head1 EXAMPLE
25
26  $: << '/path/to/rrdtool/lib/ruby/1.8/i386-linux'
27  require "RRD" 
28
29  name = "test"
30  rrd = "#{name}.rrd"
31  start = Time.now.to_i
32
33  RRD.create(    
34     rrd,
35     "--start", "#{start - 1}",
36     "--step", "300",
37         "DS:a:GAUGE:600:U:U",
38     "DS:b:GAUGE:600:U:U",
39     "RRA:AVERAGE:0.5:1:300")
40  puts
41
42  puts "updating #{rrd}"
43  start.to_i.step(start.to_i + 300 * 300, 300) { |i|
44     RRD.update(rrd, "#{i}:#{rand(100)}:#{Math.sin(i / 800) * 50 + 50}")
45  }
46  puts
47
48  puts "fetching data from #{rrd}"
49  (fstart, fend, data) = RRD.fetch(rrd, "--start", start.to_s, "--end", 
50       (start + 300 * 300).to_s, "AVERAGE")
51  puts "got #{data.length} data points from #{fstart} to #{fend}"
52  puts
53
54  puts "generating graph #{name}.png"
55  RRD.graph(
56    "#{name}.png",
57     "--title", " RubyRRD Demo", 
58     "--start", "#{start+3600}",
59     "--end", "start + 1000 min",
60     "--interlace", 
61     "--imgformat", "PNG",
62     "--width=450",
63     "DEF:a=#{rrd}:a:AVERAGE",
64     "DEF:b=#{rrd}:b:AVERAGE",
65     "CDEF:line=TIME,2400,%,300,LT,a,UNKN,IF",
66     "AREA:b#00b6e4:beta",
67     "AREA:line#0022e9:alpha",
68     "LINE3:line#ff0000") 
69  puts
70
71 If you use the B<--ruby-site-install> configure option you can drop the $:
72 line since the rrdtool module will be found automatically.
73
74 If rrdtool runs into trouble, it will throw an exception which you might
75 want to catch.
76
77 =head1 SEE ALSO
78
79 rrdcreate, rrdupdate, rrdgraph, rrddump, rrdfetch, rrdtune, rrdlast,
80 rrdxport, rrdinfo
81
82 =head1 AUTHOR
83
84 Loïs Lherbier E<lt>lois.lherbier@covadis.chE<gt>
85
86 Miles Egan E<lt>miles@caddr.comE<gt>