author | Tero Marttila <terom@fixme.fi> |
Tue, 25 Jan 2011 01:28:06 +0200 | |
changeset 32 | 47e977c23ba2 |
parent 28 | 89a4d9879171 |
permissions | -rw-r--r-- |
5 | 1 |
import rrd |
2 |
import time |
|
3 |
||
4 |
""" |
|
5 |
RRDTool graph output |
|
6 |
""" |
|
7 |
||
8 |
def timestamp () : |
|
9 |
return time.strftime("%Y/%m/%d %H:%M:%S %Z") |
|
10 |
||
11 |
def common_opts () : |
|
12 |
""" |
|
13 |
Common options for all views |
|
14 |
""" |
|
15 |
||
16 |
return dict( |
|
17 |
# output |
|
18 |
imgformat = "PNG", |
|
19 |
# lazy = True, |
|
20 |
||
21 |
color = [ |
|
22 |
# disable border |
|
23 |
# border = 0, |
|
24 |
"SHADEA#ffffff00", |
|
25 |
"SHADEB#ffffff00", |
|
26 |
||
27 |
# keep background transparent |
|
28 |
"BACK#ffffff00", |
|
29 |
"SHADEB#ffffff00", |
|
30 |
], |
|
31 |
||
32 |
# labels |
|
33 |
vertical_label = "bits/s", |
|
34 |
units = "si", |
|
35 |
||
36 |
# use logarithmic scaling |
|
37 |
logarithmic = True, |
|
38 |
||
39 |
# smooth out lines |
|
40 |
slope_mode = True, |
|
41 |
) |
|
42 |
||
43 |
def overview_opts () : |
|
44 |
""" |
|
32
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
45 |
Graph statements for a single-source overview graph |
5 | 46 |
""" |
47 |
||
48 |
return dict( |
|
49 |
width = 600, |
|
50 |
height = 50, |
|
51 |
), [ |
|
32
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
52 |
"CDEF:all=in0,out0,+", |
7
804243b0bcb9
add sum max/avg/min to overview graphs
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
53 |
|
804243b0bcb9
add sum max/avg/min to overview graphs
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
54 |
"VDEF:max=all,MAXIMUM", |
804243b0bcb9
add sum max/avg/min to overview graphs
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
55 |
"VDEF:avg=all,AVERAGE", |
804243b0bcb9
add sum max/avg/min to overview graphs
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
56 |
"VDEF:min=all,MINIMUM", |
804243b0bcb9
add sum max/avg/min to overview graphs
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
57 |
|
32
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
58 |
"LINE1:in0#0000FF:In", |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
59 |
"LINE1:out0#00CC00:Out", |
7
804243b0bcb9
add sum max/avg/min to overview graphs
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
60 |
|
804243b0bcb9
add sum max/avg/min to overview graphs
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
61 |
"GPRINT:max:%6.2lf %Sbps max", |
804243b0bcb9
add sum max/avg/min to overview graphs
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
62 |
"GPRINT:avg:%6.2lf %Sbps avg", |
804243b0bcb9
add sum max/avg/min to overview graphs
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
63 |
"GPRINT:min:%6.2lf %Sbps min\\l", |
5 | 64 |
] |
65 |
||
66 |
def detail_opts () : |
|
67 |
""" |
|
32
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
68 |
Common options for a single-source detail graph |
5 | 69 |
""" |
70 |
||
71 |
return dict( |
|
72 |
# dimensions |
|
73 |
width = 600, |
|
74 |
height = 200, |
|
75 |
), [ |
|
76 |
# values |
|
32
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
77 |
'VDEF:in_max=in0,MAXIMUM', |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
78 |
'VDEF:in_avg=in0,AVERAGE', |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
79 |
'VDEF:in_min=in0,MINIMUM', |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
80 |
'VDEF:in_cur=in0,LAST', |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
81 |
'VDEF:out_max=out0,MAXIMUM', |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
82 |
'VDEF:out_avg=out0,AVERAGE', |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
83 |
'VDEF:out_min=out0,MINIMUM', |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
84 |
'VDEF:out_cur=out0,LAST', |
5 | 85 |
|
86 |
# legend/graph |
|
87 |
"COMMENT:%4s" % "", |
|
88 |
"COMMENT:%11s" % "Maximum", |
|
89 |
"COMMENT:%11s" % "Average", |
|
28
89a4d9879171
Add 'Current' column to detail view
Tero Marttila <terom@fixme.fi>
parents:
17
diff
changeset
|
90 |
"COMMENT:%11s" % "Minimum", |
89a4d9879171
Add 'Current' column to detail view
Tero Marttila <terom@fixme.fi>
parents:
17
diff
changeset
|
91 |
"COMMENT:%11s\\l" % "Current", |
5 | 92 |
|
32
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
93 |
"LINE1:in0#0000FF:%4s" % "In", |
5 | 94 |
'GPRINT:in_max:%6.2lf %Sbps', |
95 |
'GPRINT:in_avg:%6.2lf %Sbps', |
|
28
89a4d9879171
Add 'Current' column to detail view
Tero Marttila <terom@fixme.fi>
parents:
17
diff
changeset
|
96 |
'GPRINT:in_min:%6.2lf %Sbps', |
89a4d9879171
Add 'Current' column to detail view
Tero Marttila <terom@fixme.fi>
parents:
17
diff
changeset
|
97 |
'GPRINT:in_cur:%6.2lf %Sbps\\l', |
5 | 98 |
|
32
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
99 |
"LINE1:out0#00CC00:%4s" % "Out", |
5 | 100 |
'GPRINT:out_max:%6.2lf %Sbps', |
101 |
'GPRINT:out_avg:%6.2lf %Sbps', |
|
28
89a4d9879171
Add 'Current' column to detail view
Tero Marttila <terom@fixme.fi>
parents:
17
diff
changeset
|
102 |
'GPRINT:out_min:%6.2lf %Sbps', |
89a4d9879171
Add 'Current' column to detail view
Tero Marttila <terom@fixme.fi>
parents:
17
diff
changeset
|
103 |
'GPRINT:out_cur:%6.2lf %Sbps\\l', |
5 | 104 |
|
105 |
# mark |
|
106 |
"COMMENT:Generated %s\\r" % timestamp().replace(':', '\\:'), |
|
107 |
] |
|
108 |
||
32
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
109 |
# set of line colors used for a multi-source graph, in rgb hex form (no prefix) |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
110 |
MULTI_COLORS = ( |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
111 |
'00cc00', |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
112 |
'0000ff', |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
113 |
'cc0000', |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
114 |
) |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
115 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
116 |
def multi_graph_source_defs (idx, name, color) : |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
117 |
""" |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
118 |
Render graph and legend summary for a single source in a multi-source graph. |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
119 |
""" |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
120 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
121 |
params = dict( |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
122 |
idx = idx, name = name, color = color |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
123 |
) |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
124 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
125 |
return [stmt.format(**params) for stmt in ( |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
126 |
"CDEF:all{idx}=in{idx},out{idx},+", |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
127 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
128 |
"VDEF:max{idx}=all{idx},MAXIMUM", |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
129 |
"VDEF:avg{idx}=all{idx},AVERAGE", |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
130 |
"VDEF:cur{idx}=all{idx},LAST", |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
131 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
132 |
"LINE1:all{idx}#{color}: ", |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
133 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
134 |
"GPRINT:max{idx}:%6.2lf %Sbps", |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
135 |
"GPRINT:avg{idx}:%6.2lf %Sbps", |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
136 |
"GPRINT:cur{idx}:%6.2lf %Sbps", |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
137 |
"COMMENT:\t{name}\\l", |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
138 |
)] |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
139 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
140 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
141 |
def multi_graph (sources) : |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
142 |
""" |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
143 |
Graph definition for a multi-source overview graph. |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
144 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
145 |
Uses combined in/out totals, giving a single line per source. |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
146 |
""" |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
147 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
148 |
# defs for each source |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
149 |
sources_defs = [multi_graph_source_defs(idx, name, color) for (idx, name), color in zip(sources, MULTI_COLORS)] |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
150 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
151 |
return dict( |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
152 |
# dimensions |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
153 |
width = 600, |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
154 |
height = 200, |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
155 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
156 |
), [ |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
157 |
# legend header |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
158 |
"COMMENT: ", |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
159 |
"COMMENT:%11s" % "Maximum", |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
160 |
"COMMENT:%11s" % "Average", |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
161 |
"COMMENT:%11s" % "Current", |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
162 |
"COMMENT:\t%s\\l" % "", |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
163 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
164 |
] + [ |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
165 |
# each source |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
166 |
stmt for defs in sources_defs for stmt in defs |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
167 |
] |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
168 |
|
5 | 169 |
STYLE_DEFS = { |
170 |
'overview': overview_opts, |
|
171 |
'detail': detail_opts, |
|
172 |
} |
|
173 |
||
32
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
174 |
def hourly_opts (title) : |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
175 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
176 |
return dict( |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
177 |
# labels |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
178 |
x_grid = None, |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
179 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
180 |
# general info |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
181 |
title = "Hourly %s" % (title, ), |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
182 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
183 |
# interval |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
184 |
start = "-1h", |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
185 |
) |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
186 |
|
5 | 187 |
def daily_opts (title) : |
188 |
""" |
|
189 |
Common options for the 'daily' view |
|
190 |
""" |
|
191 |
||
192 |
return dict( |
|
193 |
# labels |
|
194 |
x_grid = "MINUTE:15:HOUR:1:HOUR:4:0:%H:%M", |
|
195 |
||
196 |
# general info |
|
197 |
title = "Daily %s" % (title, ), |
|
198 |
||
199 |
# interval |
|
200 |
start = "-24h", |
|
201 |
) |
|
202 |
||
203 |
def weekly_opts (title) : |
|
204 |
return dict( |
|
205 |
# labels |
|
206 |
# x_grid = "MINUTE:15:HOUR:1:HOUR:4:0:%H:%M", |
|
207 |
||
208 |
# general info |
|
209 |
title = "Weekly %s" % (title, ), |
|
210 |
||
211 |
# interval |
|
212 |
start = "-7d", |
|
213 |
) |
|
214 |
||
215 |
def yearly_opts (title) : |
|
216 |
return dict( |
|
217 |
# labels |
|
218 |
# x_grid = "MINUTE:15:HOUR:1:HOUR:4:0:%H:%M", |
|
219 |
||
220 |
# general info |
|
221 |
title = "Yearly %s" % (title, ), |
|
222 |
||
223 |
# interval |
|
224 |
start = "-1y", |
|
225 |
) |
|
226 |
||
227 |
||
228 |
INTERVAL_DEFS = { |
|
32
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
229 |
'hourly': hourly_opts, |
5 | 230 |
'daily': daily_opts, |
231 |
'weekly': weekly_opts, |
|
232 |
'yearly': yearly_opts, |
|
233 |
} |
|
234 |
||
32
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
235 |
def data_defs (idx, rrd, ds_in, ds_out, bytes=True, cf='AVERAGE') : |
5 | 236 |
""" |
32
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
237 |
Generate the DEF/CDEF statements for the in{idx}/out{idx} data sources for the given RRD and DS names. |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
238 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
239 |
If bytes is given, convert the value into bits. |
5 | 240 |
""" |
241 |
||
32
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
242 |
params = dict( |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
243 |
ds_in=ds_in, ds_out=ds_out, cf=cf, |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
244 |
idx=idx, rrd=rrd, |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
245 |
) |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
246 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
247 |
if bytes : |
5 | 248 |
# data sources, bytes/s |
32
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
249 |
yield 'DEF:in_raw{idx}={rrd}:{ds_in}:{cf}'.format(**params) |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
250 |
yield 'DEF:out_raw{idx}={rrd}:{ds_out}:{cf}'.format(**params) |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
251 |
|
5 | 252 |
# data, bits/s |
32
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
253 |
yield 'CDEF:in{idx}=in_raw{idx},8,*'.format(**params) |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
254 |
yield 'CDEF:out{idx}=out_raw{idx},8,*'.format(**params) |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
255 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
256 |
else : |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
257 |
# data sources, bits/s |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
258 |
yield 'DEF:in{idx}={rrd}:{ds_in}:{cf}'.format(**params) |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
259 |
yield 'DEF:out{idx}={rrd}:{ds_out}:{cf}'.format(**params) |
5 | 260 |
|
261 |
||
32
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
262 |
def mrtg_data (idx, rrd) : |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
263 |
""" |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
264 |
Generate the in{idx}/out{idx} data sources fro the given MRTG rrd. |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
265 |
""" |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
266 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
267 |
return data_defs(idx, rrd, 'ds0', 'ds1') |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
268 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
269 |
def collectd_data (idx, rrd) : |
17
a1608b66be45
add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
270 |
""" |
a1608b66be45
add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
271 |
Data sources for if_octets from a collectd rrd |
a1608b66be45
add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
272 |
""" |
32
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
273 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
274 |
return data_defs(idx, rrd, 'rx', 'tx') |
17
a1608b66be45
add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
275 |
|
32
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
276 |
def pmacct_data (idx, rrd) : |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
277 |
""" |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
278 |
Data sources for in/out bytes from a pmacct rrd |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
279 |
""" |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
280 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
281 |
return data_defs(idx, rrd, 'in', 'out') |
17
a1608b66be45
add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
282 |
|
32
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
283 |
def graph_single (style, interval, title, data_func, rrd_path, out_path) : |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
284 |
""" |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
285 |
Render graph. |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
286 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
287 |
Returns a (width, height, print_lines, graph_file) tuple. |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
288 |
""" |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
289 |
|
5 | 290 |
style_opts, style_vars = STYLE_DEFS[style]() |
291 |
interval_opts = INTERVAL_DEFS[interval](title) |
|
292 |
||
293 |
opts = rrd.merge_opts(common_opts(), style_opts, interval_opts) |
|
32
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
294 |
data = list(data_func(0, rrd_path)) + style_vars |
5 | 295 |
|
296 |
return rrd.graph(out_path, *data, **opts) |
|
17
a1608b66be45
add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
297 |
|
32
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
298 |
def graph_multi (interval, title, rrd_list, data_func, out) : |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
299 |
""" |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
300 |
Render a multi-source graph. |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
301 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
302 |
interval - the name of the time interval to use |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
303 |
title - graph title |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
304 |
rrd_list - sequence of (rrd, name) tuples for each source to draw |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
305 |
data_func - the data source definition to use |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
306 |
out - output path for graph |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
307 |
""" |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
308 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
309 |
# data sources |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
310 |
data_defs = [stmt for idx, (path, name) in enumerate(rrd_list) for stmt in data_func(idx, path)] |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
311 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
312 |
# options |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
313 |
graph_opts, graph_defs = multi_graph([(idx, name) for idx, (path, name) in enumerate(rrd_list)]) |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
314 |
interval_opts = INTERVAL_DEFS[interval](title) |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
315 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
316 |
# combine |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
317 |
opts = rrd.merge_opts(common_opts(), graph_opts, interval_opts) |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
318 |
defs = data_defs + graph_defs |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
319 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
320 |
# graph |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
321 |
return rrd.graph(out, *defs, **opts) |
5 | 322 |
|
17
a1608b66be45
add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
323 |
def mrtg (style, interval, title, rrd_path, out_path) : |
a1608b66be45
add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
324 |
return _graph(style, interval, title, mrtg_data, rrd_path, out_path) |
a1608b66be45
add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
325 |
|
a1608b66be45
add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
326 |
def collectd_ifoctets (style, interval, title, rrd_path, out_path) : |
a1608b66be45
add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
327 |
return _graph(style, interval, title, collectd_data, rrd_path, out_path) |
a1608b66be45
add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
328 |
|
32
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
329 |
def pmacct_bytes (style, interval, title, rrd_path, out_path) : |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
330 |
return _graph(style, interval, title, pmacct_data, rrd_path, out_path) |
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
331 |
|
47e977c23ba2
implement rendering of pmacct rrd graphs, and a dir/top.png feature
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
332 |