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