1
2
3 """Produces a set of graphs of NEW/BYHAND/DEFERRED
4
5 @contact: Debian FTPMaster <ftpmaster@debian.org>
6 @copyright: 2011 Paul Wise <pabs@debian.org>
7 """
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import colorsys
24 import os
25 import sys
26
27 import apt_pkg
28 import rrdtool
29
30 from daklib import utils
31
32 Cnf = None
33 default_names = ["byhand", "new", "deferred"]
34
35
36
37
39 print(
40 """Usage: dak graph
41 Graphs the number of packages in queue directories (usually new and byhand).
42
43 -h, --help show this help and exit.
44 -r, --rrd=key Directory where rrd files to be updated are stored
45 -x, --extra-rrd=key File containing extra options to rrdtool graphing
46 -i, --images=key Directory where image graphs to be updated are stored
47 -n, --names=key A comma separated list of rrd files to be scanned
48
49 """
50 )
51 sys.exit(exit_code)
52
53
54
55
56
62
63
65 colours = [0] * 16
66 for i in range(0, 16):
67 colours[i] = colorsys.hsv_to_rgb(i / 16.0, 1.0, 0.5 + i / 32.0)
68 colours[i] = "".join("%02X" % int(c * 255) for c in colours[i])
69 return colours
70
71
72 colours = deferred_colours()
73
74
75 -def graph_deferred(
76 rrd_dir, image_dir, name, extra_args, graph, title, start, year_lines=False
77 ):
78 image_file = os.path.join(image_dir, "%s-%s.png" % (name, graph))
79 rrd_file = os.path.join(rrd_dir, "%s.rrd" % name)
80 rrd_args = [image_file, "--start", start]
81 rrd_args += (
82 (
83 """
84 --end
85 now
86 --width
87 600
88 --height
89 150
90 --vertical-label
91 changes
92 --title
93 %s changes count for the last %s
94 --lower-limit
95 0
96 -E
97 """
98 % (name.upper(), title)
99 )
100 .strip()
101 .split("\n")
102 )
103
104 if year_lines:
105 rrd_args += ["--x-grid", "MONTH:1:YEAR:1:YEAR:1:31536000:%Y"]
106
107 for i in range(0, 16):
108 rrd_args += (
109 (
110 """
111 DEF:d%i=%s:day%i:AVERAGE
112 AREA:d%i#%s:%i-day changes count:STACK
113 VDEF:ld%i=d%i,LAST
114 VDEF:mind%i=d%i,MINIMUM
115 VDEF:maxd%i=d%i,MAXIMUM
116 VDEF:avgd%i=d%i,AVERAGE
117 GPRINT:ld%i:cur\\: %%.0lf
118 GPRINT:mind%i:min\\: %%.0lf
119 GPRINT:maxd%i:max\\: %%.0lf
120 GPRINT:avgd%i:avg\\: %%.0lf\\j
121 """
122 % ((i, rrd_file, i, i, colours[i]) + (i,) * 13)
123 )
124 .strip()
125 .split("\n")
126 )
127
128 rrd_args += extra_args
129 try:
130 rrdtool.graph(*rrd_args)
131 except rrdtool.error as e:
132 print(
133 ("warning: graph: rrdtool error, skipping %s-%s.png: %s" % (name, graph, e))
134 )
135
136
137 -def graph_normal(
138 rrd_dir, image_dir, name, extra_args, graph, title, start, year_lines=False
139 ):
140 image_file = os.path.join(image_dir, "%s-%s.png" % (name, graph))
141 rrd_file = os.path.join(rrd_dir, "%s.rrd" % name)
142 rrd_args = [image_file, "--start", start]
143 rrd_args += (
144 (
145 """
146 --end
147 now
148 --width
149 600
150 --height
151 150
152 --vertical-label
153 packages
154 --title
155 %s package count for the last %s
156 --lower-limit
157 0
158 -E
159 """
160 % (name.upper(), title)
161 )
162 .strip()
163 .split("\n")
164 )
165
166 if year_lines:
167 rrd_args += ["--x-grid", "MONTH:1:YEAR:1:YEAR:1:31536000:%Y"]
168
169 rrd_args += (
170 (
171 """
172 DEF:ds1=%s:ds1:AVERAGE
173 LINE2:ds1#D9382B:changes count
174 VDEF:lds1=ds1,LAST
175 VDEF:minds1=ds1,MINIMUM
176 VDEF:maxds1=ds1,MAXIMUM
177 VDEF:avgds1=ds1,AVERAGE
178 GPRINT:lds1:cur\\: %%.0lf
179 GPRINT:minds1:min\\: %%.0lf
180 GPRINT:maxds1:max\\: %%.0lf
181 GPRINT:avgds1:avg\\: %%.0lf\\j
182 DEF:ds0=%s:ds0:AVERAGE
183 VDEF:lds0=ds0,LAST
184 VDEF:minds0=ds0,MINIMUM
185 VDEF:maxds0=ds0,MAXIMUM
186 VDEF:avgds0=ds0,AVERAGE
187 LINE2:ds0#3069DA:src pkg count
188 GPRINT:lds0:cur\\: %%.0lf
189 GPRINT:minds0:min\\: %%.0lf
190 GPRINT:maxds0:max\\: %%.0lf
191 GPRINT:avgds0:avg\\: %%.0lf\\j
192 """
193 % (rrd_file, rrd_file)
194 )
195 .strip()
196 .split("\n")
197 )
198
199 rrd_args += extra_args
200 try:
201 rrdtool.graph(*rrd_args)
202 except rrdtool.error as e:
203 print(
204 ("warning: graph: rrdtool error, skipping %s-%s.png: %s" % (name, graph, e))
205 )
206
207
208
209
210
212 global Cnf
213
214 Cnf = utils.get_conf()
215 Arguments = [
216 ("h", "help", "Graph::Options::Help"),
217 ("x", "extra-rrd", "Graph::Options::Extra-Rrd", "HasArg"),
218 ("r", "rrd", "Graph::Options::Rrd", "HasArg"),
219 ("i", "images", "Graph::Options::Images", "HasArg"),
220 ("n", "names", "Graph::Options::Names", "HasArg"),
221 ]
222 for i in ["help"]:
223 key = "Graph::Options::%s" % i
224 if key not in Cnf:
225 Cnf[key] = ""
226
227 apt_pkg.parse_commandline(Cnf, Arguments, sys.argv)
228
229 Options = Cnf.subtree("Graph::Options")
230 if Options["Help"]:
231 usage()
232
233 names = []
234
235 if "Graph::Options::Names" in Cnf:
236 for i in Cnf["Graph::Options::Names"].split(","):
237 names.append(i)
238 elif "Graph::Names" in Cnf:
239 names = Cnf.value_list("Graph::Names")
240 else:
241 names = default_names
242
243 extra_rrdtool_args = []
244
245 if "Graph::Options::Extra-Rrd" in Cnf:
246 for i in Cnf["Graph::Options::Extra-Rrd"].split(","):
247 with open(i) as f:
248 extra_rrdtool_args.extend(f.read().strip().split("\n"))
249 elif "Graph::Extra-Rrd" in Cnf:
250 for i in Cnf.value_list("Graph::Extra-Rrd"):
251 with open(i) as f:
252 extra_rrdtool_args.extend(f.read().strip().split("\n"))
253
254 if "Graph::Options::Rrd" in Cnf:
255 rrd_dir = Cnf["Graph::Options::Rrd"]
256 elif "Dir::Rrd" in Cnf:
257 rrd_dir = Cnf["Dir::Rrd"]
258 else:
259 print("No directory to read RRD files from\n", file=sys.stderr)
260 sys.exit(1)
261
262 if "Graph::Options::Images" in Cnf:
263 image_dir = Cnf["Graph::Options::Images"]
264 else:
265 print("No directory to write graph images to\n", file=sys.stderr)
266 sys.exit(1)
267
268 for name in names:
269 stdargs = [rrd_dir, image_dir, name, extra_rrdtool_args]
270 graph(*(stdargs + ["day", "day", "now-1d"]))
271 graph(*(stdargs + ["week", "week", "now-1w"]))
272 graph(*(stdargs + ["month", "month", "now-1m"]))
273 graph(*(stdargs + ["year", "year", "now-1y"]))
274 graph(*(stdargs + ["5years", "5 years", "now-5y", True]))
275 graph(*(stdargs + ["10years", "10 years", "now-10y", True]))
276
277
278
279
280
281 if __name__ == "__main__":
282 main()
283