/[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 3131 - (show annotations) (download)
Tue Oct 25 10:18:12 2016 UTC (5 years, 2 months ago) by templon
File size: 13734 byte(s)
dbupdate: move time computation to better match delays in returning torque
data.
mkplots: cosmetic changes for color stability when offline/unused on plots

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/ndpf/'
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 skipgroup = 0
159 if ranktype == 'bottom':
160 if 'unused' in grouplist:
161 grouplist.remove('unused')
162 grouplist.insert(0,'unused')
163 if 'offline' in grouplist:
164 grouplist.remove('offline')
165 grouplist.insert(0,'offline')
166 else:
167 if 'unused' in grouplist:
168 skipgroup += 1
169 if 'offline' in grouplist:
170 skipgroup += 1
171
172 print grouplist
173 for idx in range(len(grouplist)):
174 thisgrp = grouplist[idx]
175 if thisgrp == 'unused':
176 gcolors[thisgrp] = '#d8d8d8'
177 elif thisgrp == "offline":
178 gcolors[thisgrp] = "#790ead"
179 else:
180 gcolors[thisgrp] = colors[idx+skipgroup]
181
182 if dbtype == 'queued':
183 if 'unused' in grouplist: grouplist.remove('unused')
184 if 'offline' in grouplist: grouplist.remove('offline')
185
186 if ranktype == 'top':
187 for group in (grouplist + ['total']):
188 data_defs.append('DEF:'+group+'='+DATADIR+group+'.'+dbtype+'.rrd:'+dbtype+':AVERAGE')
189 otherstring = 'CDEF:other=total,'
190 for group in grouplist:
191 otherstring += group + ','
192 otherstring += (len(grouplist)-1) * '+,' + '-'
193
194 # print otherstring
195 data_defs.append(otherstring)
196 elif ranktype == 'bottom':
197 for group in grouplist:
198 data_defs.append('DEF:'+group+'='+DATADIR+group+'.'+dbtype+'.rrd:'+dbtype+':AVERAGE')
199 else:
200 print 'Unknown ranktype detected:', ranktype
201 sys.exit(2)
202
203 sumshown = 0
204 for idx in range(len(grouplist)):
205 group = grouplist[idx]
206 acolor = gcolors[group]
207 pdefstr = 'AREA' ':' + group + acolor + ':' + "%8s" % (group)
208 if pcents:
209 pdefstr = pdefstr + ' (' + "%4.1f" % (pcents[group]) + ')'
210 sumshown += float(pcents[group])
211 pdefstr = pdefstr + '\\n'
212 pdefstr = pdefstr + ':STACK'
213 plot_defs.append(pdefstr)
214
215 if ranktype == 'top':
216 pdefstr = 'AREA' ':' + 'other' + '#794044' + ':' + ' other'
217 if pcents:
218 pdefstr = pdefstr + ' (' + "%4.1f" % (100 - sumshown) + ')'
219 pdefstr = pdefstr + '\\n'
220 plot_defs.insert(0,pdefstr)
221 plot_defs.append("LINE:total#000000") # :total")
222
223 pargs = [ PLOTDIR + dbtype + '-' + timetag + '-' + ranktype + '-' + \
224 psize + '.png'] + commonargs + ['-l', '0'] + sizeargs[psize] + \
225 timeargs + data_defs + plot_defs
226 rrdtool.graph( *pargs )
227
228 def doplot_wait(glist, dbtype, psize, timetag, sizeargs, timeargs, ranktype):
229
230 grouplist = glist[:]
231 defs = list()
232 plots = list()
233
234 data_defs = list()
235 plot_defs = list()
236
237 skipgroup = 0
238 if dbtype == 'waittime':
239 if 'unused' in grouplist:
240 grouplist.remove('unused')
241 skipgroup += 1
242 if 'offline' in grouplist:
243 grouplist.remove('offline')
244 skipgroup += 1
245
246 for group in (grouplist + ['rollover','lastroll']):
247 data_defs.append('DEF:'+group+'='+DATADIR+group+'.'+dbtype+'.rrd:'+dbtype+':AVERAGE')
248
249 for idx in range(len(grouplist)):
250 group = grouplist[idx]
251 if group == 'unused':
252 acolor = '#d8d8d8'
253 skipgroup += 1
254 elif group == "offline":
255 acolor = "#790ead"
256 skipgroup += 1
257 else:
258 acolor = colors[idx+skipgroup]
259 pdefstr = 'LINE3' ':' + group + acolor + ':' + group
260 pdefstr = pdefstr + '\\n'
261 plot_defs.append(pdefstr)
262
263 plot_defs.append('LINE2:rollover#660198')
264 plot_defs.append('LINE2:lastroll#000000')
265
266 pargs = [ PLOTDIR + dbtype + '-' + timetag + '-' + ranktype + '-' + \
267 psize + '.png'] + ['--slope-mode', '-o'] + commonargs + \
268 sizeargs[psize] + timeargs + data_defs + plot_defs
269 rrdtool.graph( *pargs )
270
271 def makeplots(prangedef):
272
273 resolu = prangedef['avres']
274 NUMGROUPS = prangedef['numgroups']
275
276 # first need to find "top eight" list
277 # base it on running jobs
278
279 now=int(time.mktime(time.localtime()))
280 end = (now / resolu) * resolu
281 start = end - (prangedef['avrange']) + resolu
282
283 ### block finding 'top N' group list ###
284
285 tgroup = dict() # structure tgroup[groupname] = total of hourly average
286
287 running_files = glob.glob(DATADIR+'*.running.rrd')
288 for db in running_files:
289 group = db[len(DATADIR):db.find('.running.rrd')]
290 tup = rrdtool.fetch(db,'AVERAGE','-r', repr(resolu),
291 '-s', repr(start), '-e', repr(end))
292 vallist = [0] # start with zero, in case no vals returned, get zero as answer
293 for tup2 in tup[2]:
294 val = tup2[0]
295 if val:
296 vallist.append(val)
297
298 # put numbers in meaningful units now. result returned is an
299 # integration over the time range, of averages over "resolu"
300 # ... native resolution is in minutes, so multiplying by
301 # (resolu / 60) puts the answer in core-minutes; dividing by
302 # the number of minutes in the range gives the average number
303 # of cores occupied, over the range
304
305 if group == "total":
306 totval = sum(vallist) * (resolu / 60) / ( (end-start) / 60. )
307 else:
308 tgroup[group] = sum(vallist) * (resolu / 60) / ( (end-start) / 60. )
309
310 pgroup = dict()
311 for g in tgroup.keys():
312 pgroup[g] = 100*tgroup[g]/totval
313
314 ### start block 'top N' and 'next N' group list ###
315
316 groups_sorted = sorted(tgroup, key=tgroup.get, reverse=False) # increasing useage towards end of list
317
318 topgroups = groups_sorted[ -NUMGROUPS: ]
319 bottgroups = groups_sorted[-2*NUMGROUPS:-NUMGROUPS]
320
321 for glist in [topgroups, bottgroups]:
322 if 'unused' in glist:
323 glist.remove('unused')
324 glist.append('unused') # makes it always appear at top of plot (except see offline)
325 if 'offline' in glist:
326 glist.remove('offline')
327 glist.append('offline') # makes it always appear at top of plot
328
329 if opts.rankonly and prangedef['timetag'] != 'hr' :
330 print "Ranked average running jobs over period", prangedef['timetag']
331 print "%10s %12d" % ('total', totval)
332 rank = 0
333 for g in reversed(groups_sorted):
334 if tgroup[g] > 0:
335 rank += 1
336 print "%2d. %10s %9.4f %9.4f%%" % (rank, g, tgroup[g], pgroup[g])
337 return
338
339 ### end block 'top N' group list ###
340
341 ### block generating plots ###
342
343
344 for dbtype in ['queued', 'running', 'waittime']:
345
346 ### this is a bit of a hack : we only want pgroups for when it's
347 ### a 'running' database and we don't want it for timetag hour.
348 ### fix this up here
349
350 if dbtype == 'running' and prangedef['timetag'] != 'hr':
351 percents = pgroup
352 else:
353 percents = None
354 for grps in [ ('top', topgroups), ('bottom', bottgroups) ]:
355 for psize in ['small', 'large']:
356 if dbtype == 'waittime':
357 doplot_wait(grps[1], dbtype, psize, prangedef['timetag'],
358 prangedef['sizeargs'],
359 prangedef['timeargs'], grps[0]
360 )
361 else:
362 doplot(grps[1], dbtype, psize, prangedef['timetag'],
363 prangedef['sizeargs'],
364 prangedef['timeargs'],
365 percents, grps[0]
366 )
367
368 for k in ['hr', 'day', 'week', 'month', 'year', 'alltime']: # plotrangedef.keys():
369 makeplots(plotrangedef[k])
370
371 import sys
372 sys.exit(0)

Properties

Name Value
svn:executable *
svn:keywords Id URL

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