~ubuntu-branches/ubuntu/saucy/rrdtool/saucy-proposed

« back to all changes in this revision

Viewing changes to bindings/lua/test.lua.bottom

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2010-07-22 08:07:01 UTC
  • mfrom: (1.2.8 upstream) (3.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100722080701-k46mgdfz6euxwqsm
Tags: 1.4.3-1ubuntu1
* Merge from debian unstable, Remaining changes:
  - debian/control: Don't build against ruby1.9 as we don't want
    it in main.
* require libdbi >= 0.8.3 to prevent aborts when using dbi datasources

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
local rrd = require 'rrd'
 
3
 
 
4
local name = 'test.rrd'
 
5
local start = 300 * math.floor(os.time() / 300)
 
6
 
 
7
io.write('\n-- Creating ', name, '\n')
 
8
rrd.create(
 
9
    name,
 
10
    '--start', start-1,
 
11
    '--step', '300',
 
12
    'DS:a:GAUGE:600:U:U',
 
13
    'DS:b:GAUGE:600:U:U',
 
14
    'RRA:AVERAGE:0.5:1:300')
 
15
 
 
16
local num_points = 0
 
17
for t=start, start+300*300, 300 do
 
18
  local s = string.format('%d:%d:%f', t,
 
19
                          math.random(100), math.sin(t/800)*50+50)
 
20
  rrd.update(name, s)
 
21
  num_points = num_points + 1
 
22
end
 
23
 
 
24
io.write('rrd file created with ', num_points, ' points, from ', start,
 
25
         ' to ', start+300*300, '\n')
 
26
 
 
27
io.write('\n-- Testing rrd.info\n')
 
28
local info = rrd.info(name)
 
29
for k,v in pairs(info) do
 
30
  io.write(k, '=', v, '\n')
 
31
end
 
32
io.write('\n')
 
33
 
 
34
io.write('-- Testing rrd.fetch\n') 
 
35
io.write('fetching data from ', name, ' - interval: ', start, ' to ',
 
36
         start+300*300, '\n') 
 
37
local fstart, fstep, fnames, fdata =
 
38
  rrd.fetch(name, '--start', start, '--end', start+300*300+10, 'AVERAGE')
 
39
io.write('got ', table.getn(fdata[1]), ' data sources with ', table.getn(fdata),
 
40
         ' data points each.\n')
 
41
 
 
42
io.write('\n-- Printing fetched data\n') 
 
43
io.write('            ')
 
44
for i, n in ipairs(fnames) do
 
45
  io.write(n, '            ')
 
46
end
 
47
io.write('\n')
 
48
for i, v in ipairs(fdata) do
 
49
  local time = fstart + (i-1)*fstep
 
50
  io.write(string.format('%s (%d): ', os.date('%c', time), time))
 
51
  for _, w in ipairs(v) do
 
52
    io.write(string.format('%e ', w))
 
53
  end
 
54
  io.write('\n')
 
55
end
 
56
io.write('\n')
 
57
 
 
58
io.write('\n-- Testing rrd.graphv - creates test.png and returns values\n') 
 
59
local t = rrd.graphv(
 
60
   'test.png',
 
61
   '--title', 'Enjoy Lua RRDtool module!',
 
62
   '--start', start+3600,
 
63
   '--end', 'start + 1000 min',
 
64
   '--interlace',
 
65
   '--imgformat', 'PNG',
 
66
   '--width=450',
 
67
   'DEF:a=' .. name .. ':a:AVERAGE',
 
68
   'DEF:b=' .. name .. ':b:AVERAGE',
 
69
   'CDEF:line=TIME,2400,%,300,LT,a,UNKN,IF',
 
70
   'AREA:b#00b6e4:beta',
 
71
   'AREA:line#0022e9:alpha',
 
72
   'LINE3:line#ff0000',
 
73
   'VDEF:va=a,AVERAGE',
 
74
   'VDEF:vb=b,AVERAGE',
 
75
   'PRINT:va:%5.2lf',
 
76
   'PRINT:vb:%5.2lf')
 
77
 
 
78
io.write('\n-- Returned values:\n') 
 
79
io.write('print[0]: ', t['print[0]'], '\n')
 
80
io.write('print[1]: ', t['print[1]'], '\n')
 
81
for k, v in pairs(t) do
 
82
  if not string.find(k, '^print%[%d+%]') then
 
83
    io.write(k, ': ', v, '\n')
 
84
  end
 
85
end
 
86
io.write('\n')
 
87
 
 
88
io.write('-- The graph "test.png" was created.\n')
 
89
io.write('-- Use your preferred viewer to display it.\n\n')
 
90