/[pdpsoft]/nl.nikhef.ndpf.groupviews/trunk/ndpf-gv-mkplots
ViewVC logotype

Contents of /nl.nikhef.ndpf.groupviews/trunk/ndpf-gv-mkplots

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3061 - (show annotations) (download)
Wed Jul 20 10:31:10 2016 UTC (5 years, 11 months ago) by templon
File size: 13355 byte(s)
Summary: change PLOTDIR to point to NDPF web space, not my home dir

1 #! /usr/bin/env python
2 # $Id$
3 # Source: $URL$
4 # J. A. Templon, NIKHEF/PDP 2011
5
6 import optparse
7
8 p = optparse.OptionParser(description="Program to make rrdtool plots " + \
9 "of job running jobs by unix group")
10
11 # p.add_option("-r",action="store",dest="minsize",default='0',help="minimum size of dirs considered; can use suffixes k,M,G for multiples of 1000**{1,2,3} bytes")
12 # p.add_option("--qdel",action="store_true",dest="deljobs",help="delete jobs for which TMPDIR is larger than MINSIZE",default=False)
13
14 p.add_option("--rank-only",action="store_true",dest="rankonly",
15 help="don't plot, just print ranking of groups",default=False)
16
17 debug = 0
18
19 opts, args = p.parse_args()
20
21 import os
22
23 DATADIR=os.environ['HOME'] + '/ndpfdata/'
24 PLOTDIR='/www/grid/stats/groupviews/mcpool/'
25
26 # 8 class qualitative paired color scheme
27
28 colors = [ "#A6CEE3", "#1F77B4", "#B2DF8A", "#33A02C",
29 "#FB9A99", "#E31A1C", "#FDBF6F", "#FF7F00" ]
30
31 colors.reverse()
32
33 # for reference : ranges of the RRAs
34 # base step size 60 sec
35 # step 1 : 60 sec x 1600 points : 1600 min : 26,67 hr : 1.11 days
36 # step 2 : 120 sec x 1200 points : 2400 min : 40 hr : 1,67 days
37 # step 10 : 600 sec x 1800 points : 18 000 min : 300 hr : 12,5 days
38 # step 30 : 1800 sec x 2500 points : 75 000 min : 1250 hr : 52.08 days
39 # step 120 : 7200 sec x 1000 points : 120 000 min : 2000 hr : 83.33 days
40 # step 480 : 28800 sec x 1000 points : 480 000 min : 8000 hr : 333.33 days
41 # step 1440 : 86400 sec x 3650 points : 3650 days : 10 years
42
43 # resolutions of RRAs
44
45 # 1 : 60 sec : 1 min
46 # 2 : 120 sec : 2 min
47 # 3 : 600 sec : 10 min
48 # 4 : 1 800 sec : 30 min
49 # 5 : 7 200 sec : 120 min : 2 hr
50 # 6 : 28 800 sec : 480 min : 8 hr
51 # 7 : 86 400 sec : 1440 min : 24 hr : 1 day
52
53 plotrangedef = {
54 'hr' : { 'timeargs' : [ '-s', 'n-200min', '-e', 'n' ],
55 'timetag' : 'hr',
56 'avrange' : 24*3600,
57 'avres' : 60,
58 'sizeargs' : { 'small' : [ '--width', '200', '--height', '125',
59 '--x-grid',
60 'MINUTE:20:HOUR:1:HOUR:1:0:%H:00'
61 ],
62 'large' : [ '--width', '800', '--height', '500' ]
63 },
64 'numgroups' : 6,
65 },
66 'day' : { 'timeargs' : [ '-s', 'n-2000min', '-e', 'n' ],
67 'timetag' : 'day',
68 'avrange' : 24*3600,
69 'avres' : 60,
70 'sizeargs' : { 'small' : [ '--width', '200', '--height', '125',
71 '--x-grid',
72 'HOUR:6:DAY:1:HOUR:12:0:%a %H:00'
73 ],
74 'large' : [ '--width', '1000', '--height', '625' ]
75 },
76 'numgroups' : 6,
77 },
78 'week' : { 'timeargs' : [ '-s', 'n-288hr', '-e', 'n' ],
79 'timetag' : 'week',
80 'avrange' : 7*24*3600,
81 'avres' : 600,
82 'sizeargs' : { 'small' : [ '--width', '576', '--height', '125' ],
83 'large' : [ '--width', '1728', '--height', '375',
84 '-n', 'DEFAULT:16:']
85 },
86 'numgroups' : 6,
87 },
88
89 # note the construction "repr(576*n)" here --- this is because the plot is
90 # (a multiple of) 576 pixels, and 120 min is one of the RRAs, so choosing
91 # a lower limit of 576*120 gives us a plot with one pixel per RRA bin.
92
93 'month' : { 'timeargs' : [ '-s', 'n-'+repr(576*120)+'min', '-e', 'n'],
94 'timetag' : 'month',
95 'avrange' : 31*24*3600,
96 'avres' : 1800,
97 'sizeargs' : { 'small' : [ '--width', '576', '--height', '105'],
98 'large' : [ '--width', '2304', '--height', '420',
99 '-n', 'DEFAULT:18:',
100 '--x-grid',
101 'HOUR:12:DAY:1:DAY:3:86400:%d-%b'
102 ]
103 },
104 'numgroups' : 8,
105 },
106
107 'year' : { 'timeargs' : [ '-s', 'n-'+repr(576*1440)+'min', '-e', 'n'],
108 'timetag' : 'year',
109 'avrange' : 365*24*3600,
110 'avres' : 86400,
111 'sizeargs' : { 'small' : [ '--width', '576', '--height', '105'],
112 'large' : [ '--width', '2304', '--height', '420']
113 },
114 'numgroups' : 8,
115 },
116
117 # adjusting for nice plot ... now 15/4 of a year
118
119 'alltime' : { 'timeargs' : [ '-s', 'n-'+repr(21*365*1440/4)+'min', '-e', 'n'],
120 'timetag' : 'alltime',
121 'avrange' : 21*365*24*3600/4,
122 'avres' : 86400,
123 'sizeargs' : { 'small' : [ '--width', '576', '--height', '105',
124 '--x-grid',
125 'MONTH:3:YEAR:1:YEAR:1:31536000:%Y'
126 ],
127 'large' : [ '--width', '2304', '--height', '420',
128 '--x-grid',
129 'MONTH:1:YEAR:1:MONTH:3:2592000:%b-%Y'
130 ]
131 },
132 'numgroups' : 8,
133 },
134
135
136 }
137
138 commonargs = ['--imgformat', 'PNG',
139 '--legend-position=east', '--legend-direction=bottomup']
140
141 import rrdtool
142 import time
143 import glob
144
145 ### function definitions
146
147 def doplot(glist, dbtype, psize, timetag, sizeargs, timeargs, pcents, ranktype):
148
149 grouplist = glist[:]
150 defs = list()
151 plots = list()
152
153 data_defs = list()
154 plot_defs = list()
155
156 gcolors = dict()
157
158 for idx in range(len(grouplist)):
159 gcolors[grouplist[idx]] = colors[idx]
160
161 if ranktype == 'bottom':
162 if 'unused' in grouplist:
163 grouplist.remove('unused')
164 grouplist.insert(0,'unused')
165 if 'offline' in grouplist:
166 grouplist.remove('offline')
167 grouplist.insert(0,'offline')
168
169 if dbtype == 'queued':
170 if 'unused' in grouplist: grouplist.remove('unused')
171 if 'offline' in grouplist: grouplist.remove('offline')
172
173 if ranktype == 'top':
174 for group in (grouplist + ['total']):
175 data_defs.append('DEF:'+group+'='+DATADIR+group+'.'+dbtype+'.rrd:'+dbtype+':AVERAGE')
176 otherstring = 'CDEF:other=total,'
177 for group in grouplist:
178 otherstring += group + ','
179 otherstring += (len(grouplist)-1) * '+,' + '-'
180
181 # print otherstring
182 data_defs.append(otherstring)
183 elif ranktype == 'bottom':
184 for group in grouplist:
185 data_defs.append('DEF:'+group+'='+DATADIR+group+'.'+dbtype+'.rrd:'+dbtype+':AVERAGE')
186 else:
187 print 'Unknown ranktype detected:', ranktype
188 sys.exit(2)
189
190 sumshown = 0
191 for idx in range(len(grouplist)):
192 group = grouplist[idx]
193 if group == 'unused':
194 acolor = '#d8d8d8'
195 elif group == "offline":
196 acolor = "#790ead"
197 else:
198 acolor = gcolors[group]
199 pdefstr = 'AREA' ':' + group + acolor + ':' + "%8s" % (group)
200 if pcents:
201 pdefstr = pdefstr + ' (' + "%4.1f" % (pcents[group]) + ')'
202 sumshown += float(pcents[group])
203 pdefstr = pdefstr + '\\n'
204 pdefstr = pdefstr + ':STACK'
205 plot_defs.append(pdefstr)
206
207 if ranktype == 'top':
208 pdefstr = 'AREA' ':' + 'other' + '#794044' + ':' + ' other'
209 if pcents:
210 pdefstr = pdefstr + ' (' + "%4.1f" % (100 - sumshown) + ')'
211 pdefstr = pdefstr + '\\n'
212 plot_defs.insert(0,pdefstr)
213 plot_defs.append("LINE:total#000000") # :total")
214
215 pargs = [ PLOTDIR + dbtype + '-' + timetag + '-' + ranktype + '-' + \
216 psize + '.png'] + commonargs + ['-l', '0'] + sizeargs[psize] + \
217 timeargs + data_defs + plot_defs
218 rrdtool.graph( *pargs )
219
220 def doplot_wait(glist, dbtype, psize, timetag, sizeargs, timeargs, ranktype):
221
222 grouplist = glist[:]
223 defs = list()
224 plots = list()
225
226 data_defs = list()
227 plot_defs = list()
228
229 if dbtype == 'waittime':
230 if 'unused' in grouplist: grouplist.remove('unused')
231 if 'offline' in grouplist: grouplist.remove('offline')
232
233 for group in (grouplist + ['rollover','lastroll']):
234 data_defs.append('DEF:'+group+'='+DATADIR+group+'.'+dbtype+'.rrd:'+dbtype+':AVERAGE')
235
236 for idx in range(len(grouplist)):
237 group = grouplist[idx]
238 if group == 'unused':
239 acolor = '#d8d8d8'
240 elif group == "offline":
241 acolor = "#790ead"
242 else:
243 acolor = colors[idx]
244 pdefstr = 'LINE3' ':' + group + acolor + ':' + group
245 pdefstr = pdefstr + '\\n'
246 plot_defs.append(pdefstr)
247
248 plot_defs.append('LINE2:rollover#660198')
249 plot_defs.append('LINE2:lastroll#000000')
250
251 pargs = [ PLOTDIR + dbtype + '-' + timetag + '-' + ranktype + '-' + \
252 psize + '.png'] + ['--slope-mode', '-o'] + commonargs + \
253 sizeargs[psize] + timeargs + data_defs + plot_defs
254 rrdtool.graph( *pargs )
255
256 def makeplots(prangedef):
257
258 resolu = prangedef['avres']
259 NUMGROUPS = prangedef['numgroups']
260
261 # first need to find "top eight" list
262 # base it on running jobs
263
264 now=int(time.mktime(time.localtime()))
265 end = (now / resolu) * resolu
266 start = end - (prangedef['avrange']) + resolu
267
268 ### block finding 'top N' group list ###
269
270 tgroup = dict() # structure tgroup[groupname] = total of hourly average
271
272 running_files = glob.glob(DATADIR+'*.running.rrd')
273 for db in running_files:
274 group = db[len(DATADIR):db.find('.running.rrd')]
275 tup = rrdtool.fetch(db,'AVERAGE','-r', repr(resolu),
276 '-s', repr(start), '-e', repr(end))
277 vallist = [0] # start with zero, in case no vals returned, get zero as answer
278 for tup2 in tup[2]:
279 val = tup2[0]
280 if val:
281 vallist.append(val)
282
283 # put numbers in meaningful units now. result returned is an
284 # integration over the time range, of averages over "resolu"
285 # ... native resolution is in minutes, so multiplying by
286 # (resolu / 60) puts the answer in core-minutes; dividing by
287 # the number of minutes in the range gives the average number
288 # of cores occupied, over the range
289
290 if group == "total":
291 totval = sum(vallist) * (resolu / 60) / ( (end-start) / 60. )
292 else:
293 tgroup[group] = sum(vallist) * (resolu / 60) / ( (end-start) / 60. )
294
295 pgroup = dict()
296 for g in tgroup.keys():
297 pgroup[g] = 100*tgroup[g]/totval
298
299 ### start block 'top N' and 'next N' group list ###
300
301 groups_sorted = sorted(tgroup, key=tgroup.get, reverse=False) # increasing useage towards end of list
302
303 topgroups = groups_sorted[ -NUMGROUPS: ]
304 bottgroups = groups_sorted[-2*NUMGROUPS:-NUMGROUPS]
305
306 for glist in [topgroups, bottgroups]:
307 if 'unused' in glist:
308 glist.remove('unused')
309 glist.append('unused') # makes it always appear at top of plot (except see offline)
310 if 'offline' in glist:
311 glist.remove('offline')
312 glist.append('offline') # makes it always appear at top of plot
313
314 if opts.rankonly and prangedef['timetag'] != 'hr' :
315 print "Ranked average running jobs over period", prangedef['timetag']
316 print "%10s %12d" % ('total', totval)
317 rank = 0
318 for g in reversed(groups_sorted):
319 if tgroup[g] > 0:
320 rank += 1
321 print "%2d. %10s %9.4f %9.4f%%" % (rank, g, tgroup[g], pgroup[g])
322 return
323
324 ### end block 'top N' group list ###
325
326 ### block generating plots ###
327
328
329 for dbtype in ['queued', 'running', 'waittime']:
330
331 ### this is a bit of a hack : we only want pgroups for when it's
332 ### a 'running' database and we don't want it for timetag hour.
333 ### fix this up here
334
335 if dbtype == 'running' and prangedef['timetag'] != 'hr':
336 percents = pgroup
337 else:
338 percents = None
339 for grps in [ ('top', topgroups), ('bottom', bottgroups) ]:
340 for psize in ['small', 'large']:
341 if dbtype == 'waittime':
342 doplot_wait(grps[1], dbtype, psize, prangedef['timetag'],
343 prangedef['sizeargs'],
344 prangedef['timeargs'], grps[0]
345 )
346 else:
347 doplot(grps[1], dbtype, psize, prangedef['timetag'],
348 prangedef['sizeargs'],
349 prangedef['timeargs'],
350 percents, grps[0]
351 )
352
353 for k in ['hr', 'day', 'week', 'month', 'year', 'alltime']: # plotrangedef.keys():
354 makeplots(plotrangedef[k])
355
356 import sys
357 sys.exit(0)

Properties

Name Value
svn:executable *
svn:keywords Id URL

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28