from rrdtool import fname database rrd rrd RoundRobinDatabase fname rr

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from rrdtool import *
fname = 'database.rrd'
rrd = RoundRobinDatabase(fname)
#rrd.create(DataSource("in", type=DeriveDST, heartbeat=600, min=0, max=12500000),
#DataSource("out", type=DeriveDST, heartbeat=600, min=0, max=12500000),
#RoundRobinArchive(cf=AverageCF, xff=0.5, steps=1, rows=576),
#RoundRobinArchive(cf=AverageCF, xff=0.5, steps=6, rows=672),
#RoundRobinArchive(cf=AverageCF, xff=0.5, steps=24, rows=732),
#RoundRobinArchive(cf=AverageCF, xff=0.5, steps=144, rows=1460),
#step=300
#)
values=(323132312, 128539593)
template = ("in", "out")
rrd.update(Val(*values), template=template)
#Cdef("out_neg", "out,-1,*"),
period="day"
graph = RoundRobinGraph('eth0-%s.png' % (period))
graph.graph(
Def("in", fname, data_source="in", cf=AverageCF),
Def("out", fname, data_source="out", cf=AverageCF),
Cdef("out_neg", "out,-1,*"),
AREA("in", rrggbb="32CD32", legend="Incoming"),
LINE1("in", rrggbb="336600"),
GPRINT("in", cf=MaxCF, format=r" Max\: %5.1lf %S"),
GPRINT("in", cf=AverageCF, format=r" Avg\: %5.1lf %S"),
GPRINT("in", cf=LastCF, format=r" Current\: %5.1lf %Sbytes/sec\n"),
AREA("out_neg", rrggbb="4169E1", legend="Outgoing"),
LINE1("out_neg", rrggbb="0033CC"),
GPRINT("out", cf=MaxCF, format=r" Max\: %5.1lf %S"),
GPRINT("out", cf=AverageCF, format=r" Avg\: %5.1lf %S"),
GPRINT("out", cf=LastCF, format=r" Current\: %5.1lf %Sbytes/sec\n"),
HRULE("0", rrggbb="000000"),
vertical_label="bytes/sec",
lower_limit=0,
start="-1%s" % (period,),
title='my rrd title',
width=600,
height=80,
lazy=None,
)
values=(423132312, 158539593)
template = ("in", "out")
rrd.update(Val(*values), template=template)
###
How to create an rrd database:
r = RoundRobinDatabase("iostats.rrd")
heartbeat = 1200
r.create(
DataSource("tps", type=GaugeDST, heartbeat=heartbeat),
DataSource("rtps", type=GaugeDST, heartbeat=heartbeat),
DataSource("wtps", type=GaugeDST, heartbeat=heartbeat),
RoundRobinArchive(cf=AverageCF, xff=0.5, steps=1, rows=1200),
RoundRobinArchive(cf=AverageCF, xff=0.5, steps=12, rows=2400),
start=-864000, step=600)
How to update an rrd database:
r = RoundRobinDatabase("iostats.rrd")
r.update(Val(1, 1), template=('rtps', 'wtps'))
r.update(Val(1, 1, timestamp=time.time() - 3600), template=('rtps', 'wtps'))
How to graph:
g = RoundRobinGraph("iostats.png")
g.graph(
Def("tps", "iostats.rrd", data_source="tps", cf=AverageCF),
Def("rtps", "iostats.rrd", data_source="rtps", cf=AverageCF),
Def("wtps", "iostats.rrd", data_source="wtps", cf=AverageCF),
LINE1("tps", rrggbb="ff0000", legend="tps"),
LINE1("rtps", rrggbb="00ff00", legend="rtps"),
LINE1("wtps", rrggbb="0000ff", legend="wtps"),
alt_y_mrtg=None,
width=900,
height=200,
x="HOUR:1:HOUR:2:HOUR:4:0:%H",
title="IO stats",
start=(time.time() - 86400),
end=(time.time() - 3600),
)