/[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 2663 - (show annotations) (download)
Thu Aug 1 15:00:10 2013 UTC (9 years, 1 month ago) by templon
File size: 12733 byte(s)
add support for 'bottom' groups.

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 NUMGROUPS=8
24 DATADIR=os.environ['HOME'] + '/ndpfdata/'
25 PLOTDIR=os.environ['HOME'] + '/public_html/'
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 },
65 'day' : { 'timeargs' : [ '-s', 'n-2000min', '-e', 'n' ],
66 'timetag' : 'day',
67 'avrange' : 24*3600,
68 'avres' : 60,
69 'sizeargs' : { 'small' : [ '--width', '200', '--height', '125',
70 '--x-grid',
71 'HOUR:6:DAY:1:HOUR:12:0:%a %H:00'
72 ],
73 'large' : [ '--width', '1000', '--height', '625' ]
74 },
75 },
76 'week' : { 'timeargs' : [ '-s', 'n-288hr', '-e', 'n' ],
77 'timetag' : 'week',
78 'avrange' : 7*24*3600,
79 'avres' : 600,
80 'sizeargs' : { 'small' : [ '--width', '576', '--height', '125' ],
81 'large' : [ '--width', '1728', '--height', '375',
82 '-n', 'DEFAULT:16:']
83 },
84 },
85
86 # note the construction "repr(576*n)" here --- this is because the plot is
87 # (a multiple of) 576 pixels, and 120 min is one of the RRAs, so choosing
88 # a lower limit of 576*120 gives us a plot with one pixel per RRA bin.
89
90 'month' : { 'timeargs' : [ '-s', 'n-'+repr(576*120)+'min', '-e', 'n'],
91 'timetag' : 'month',
92 'avrange' : 31*24*3600,
93 'avres' : 1800,
94 'sizeargs' : { 'small' : [ '--width', '576', '--height', '105'],
95 'large' : [ '--width', '2304', '--height', '420',
96 '-n', 'DEFAULT:18:',
97 '--x-grid',
98 'HOUR:12:DAY:1:DAY:3:86400:%d-%b'
99 ]
100 },
101 },
102
103 'year' : { 'timeargs' : [ '-s', 'n-'+repr(576*1440)+'min', '-e', 'n'],
104 'timetag' : 'year',
105 'avrange' : 365*24*3600,
106 'avres' : 86400,
107 'sizeargs' : { 'small' : [ '--width', '576', '--height', '105'],
108 'large' : [ '--width', '2304', '--height', '420']
109 },
110 },
111
112 # adjusting for nice plot ... now 9/4 of a year
113
114 'alltime' : { 'timeargs' : [ '-s', 'n-'+repr(9*365*1440/4)+'min', '-e', 'n'],
115 'timetag' : 'alltime',
116 'avrange' : 9*365*24*3600/4,
117 'avres' : 86400,
118 'sizeargs' : { 'small' : [ '--width', '576', '--height', '105',
119 '--x-grid',
120 'MONTH:3:YEAR:1:YEAR:1:31536000:%Y'
121 ],
122 'large' : [ '--width', '2304', '--height', '420',
123 '--x-grid',
124 'MONTH:1:YEAR:1:MONTH:3:2592000:%b-%Y'
125 ]
126 },
127 },
128
129
130 }
131
132 commonargs = ['--imgformat', 'PNG',
133 '--legend-position=east', '--legend-direction=bottomup']
134
135 import rrdtool
136 import time
137 import glob
138
139 ### function definitions
140
141 def doplot(glist, dbtype, psize, timetag, sizeargs, timeargs, pcents, ranktype):
142
143 grouplist = glist[:]
144 defs = list()
145 plots = list()
146
147 data_defs = list()
148 plot_defs = list()
149
150 if dbtype == 'queued':
151 if 'unused' in grouplist: grouplist.remove('unused')
152 if 'offline' in grouplist: grouplist.remove('offline')
153
154 if ranktype == 'top':
155 for group in (grouplist + ['total']):
156 data_defs.append('DEF:'+group+'='+DATADIR+group+'.'+dbtype+'.rrd:'+dbtype+':AVERAGE')
157 otherstring = 'CDEF:other=total,'
158 for group in grouplist:
159 otherstring += group + ','
160 otherstring += (len(grouplist)-1) * '+,' + '-'
161
162 # print otherstring
163 data_defs.append(otherstring)
164 elif ranktype == 'bottom':
165 for group in grouplist:
166 data_defs.append('DEF:'+group+'='+DATADIR+group+'.'+dbtype+'.rrd:'+dbtype+':AVERAGE')
167 else:
168 print 'Unknown ranktype detected:', ranktype
169 sys.exit(2)
170
171 sumshown = 0
172 for idx in range(len(grouplist)):
173 group = grouplist[idx]
174 if group == 'unused':
175 acolor = '#858885'
176 elif group == "offline":
177 acolor = "#790ead"
178 else:
179 acolor = colors[idx]
180 pdefstr = 'AREA' ':' + group + acolor + ':' + group
181 if pcents:
182 pdefstr = pdefstr + ' (' + "%4.1f" % (pcents[group]) + ')'
183 sumshown += float(pcents[group])
184 pdefstr = pdefstr + '\\n'
185 pdefstr = pdefstr + ':STACK'
186 plot_defs.append(pdefstr)
187
188 if ranktype == 'top':
189 pdefstr = 'AREA' ':' + 'other' + '#794044' + ':' + 'other'
190 if pcents:
191 pdefstr = pdefstr + ' (' + "%4.1f" % (100 - sumshown) + ')'
192 pdefstr = pdefstr + '\\n'
193 plot_defs.insert(0,pdefstr)
194 plot_defs.append("LINE:total#000000") # :total")
195
196 pargs = [ PLOTDIR + dbtype + '-' + timetag + '-' + ranktype + '-' + \
197 psize + '.png'] + commonargs + ['-l', '0'] + sizeargs[psize] + \
198 timeargs + data_defs + plot_defs
199 rrdtool.graph( *pargs )
200
201 def doplot_wait(glist, dbtype, psize, timetag, sizeargs, timeargs, ranktype):
202
203 grouplist = glist[:]
204 defs = list()
205 plots = list()
206
207 data_defs = list()
208 plot_defs = list()
209
210 if dbtype == 'waittime':
211 if 'unused' in grouplist: grouplist.remove('unused')
212 if 'offline' in grouplist: grouplist.remove('offline')
213
214 for group in (grouplist + ['rollover','lastroll']):
215 data_defs.append('DEF:'+group+'='+DATADIR+group+'.'+dbtype+'.rrd:'+dbtype+':AVERAGE')
216
217 for idx in range(len(grouplist)):
218 group = grouplist[idx]
219 if group == 'unused':
220 acolor = '#858885'
221 elif group == "offline":
222 acolor = "#790ead"
223 else:
224 acolor = colors[idx]
225 pdefstr = 'LINE3' ':' + group + acolor + ':' + group
226 pdefstr = pdefstr + '\\n'
227 plot_defs.append(pdefstr)
228
229 plot_defs.append('LINE2:rollover#660198')
230 plot_defs.append('LINE2:lastroll#000000')
231
232 pargs = [ PLOTDIR + dbtype + '-' + timetag + '-' + ranktype + '-' + \
233 psize + '.png'] + ['--slope-mode', '-o'] + commonargs + \
234 sizeargs[psize] + timeargs + data_defs + plot_defs
235 rrdtool.graph( *pargs )
236
237 def makeplots(prangedef):
238
239 resolu = prangedef['avres']
240
241 # first need to find "top eight" list
242 # base it on running jobs
243
244 now=int(time.mktime(time.localtime()))
245 end = (now / resolu) * resolu
246 start = end - (prangedef['avrange']) + resolu
247
248 ### block finding 'top N' group list ###
249
250 tgroup = dict() # structure tgroup[groupname] = total of hourly average
251
252 running_files = glob.glob(DATADIR+'*.running.rrd')
253 for db in running_files:
254 group = db[len(DATADIR):db.find('.running.rrd')]
255 tup = rrdtool.fetch(db,'AVERAGE','-r', repr(resolu),
256 '-s', repr(start), '-e', repr(end))
257 vallist = [0] # start with zero, in case no vals returned, get zero as answer
258 for tup2 in tup[2]:
259 val = tup2[0]
260 if val:
261 vallist.append(val)
262
263 # put numbers in meaningful units now. result returned is an
264 # integration over the time range, of averages over "resolu"
265 # ... native resolution is in minutes, so multiplying by
266 # (resolu / 60) puts the answer in core-minutes; dividing by
267 # the number of minutes in the range gives the average number
268 # of cores occupied, over the range
269
270 if group == "total":
271 totval = sum(vallist) * (resolu / 60) / ( (end-start) / 60. )
272 else:
273 tgroup[group] = sum(vallist) * (resolu / 60) / ( (end-start) / 60. )
274
275 pgroup = dict()
276 for g in tgroup.keys():
277 pgroup[g] = 100*tgroup[g]/totval
278
279 ### start block 'top N' and 'next N' group list ###
280
281 groups_sorted = sorted(tgroup, key=tgroup.get, reverse=False) # increasing useage towards end of list
282
283 topgroups = groups_sorted[ -NUMGROUPS: ]
284 bottgroups = groups_sorted[-2*NUMGROUPS:-NUMGROUPS]
285
286 for glist in [topgroups, bottgroups]:
287 if 'unused' in glist:
288 glist.remove('unused')
289 glist.append('unused') # makes it always appear at top of plot (except see offline)
290 if 'offline' in glist:
291 glist.remove('offline')
292 glist.append('offline') # makes it always appear at top of plot
293
294 if opts.rankonly and prangedef['timetag'] != 'hr' :
295 print "Ranked average running jobs over period", prangedef['timetag']
296 print "%10s %12d" % ('total', totval)
297 rank = 0
298 for g in reversed(groups_sorted):
299 if tgroup[g] > 0:
300 rank += 1
301 print "%2d. %10s %9.4f %9.4f%%" % (rank, g, tgroup[g], pgroup[g])
302 return
303
304 ### end block 'top N' group list ###
305
306 ### block generating plots ###
307
308
309 for dbtype in ['queued', 'running', 'waittime']:
310
311 ### this is a bit of a hack : we only want pgroups for when it's
312 ### a 'running' database and we don't want it for timetag hour.
313 ### fix this up here
314
315 if dbtype == 'running' and prangedef['timetag'] != 'hr':
316 percents = pgroup
317 else:
318 percents = None
319 for grps in [ ('top', topgroups), ('bottom', bottgroups) ]:
320 for psize in ['small', 'large']:
321 if dbtype == 'waittime':
322 doplot_wait(grps[1], dbtype, psize, prangedef['timetag'],
323 prangedef['sizeargs'],
324 prangedef['timeargs'], grps[0]
325 )
326 else:
327 doplot(grps[1], dbtype, psize, prangedef['timetag'],
328 prangedef['sizeargs'],
329 prangedef['timeargs'],
330 percents, grps[0]
331 )
332
333 for k in ['hr', 'day', 'week', 'month', 'year', 'alltime']: # plotrangedef.keys():
334 makeplots(plotrangedef[k])
335
336 import sys
337 sys.exit(0)

Properties

Name Value
svn:executable *
svn:keywords Id URL

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