/[pdpsoft]/nl.nikhef.ndpf.groupviews/branches/RB-2.1.0/ndpf-gv-mkplots
ViewVC logotype

Contents of /nl.nikhef.ndpf.groupviews/branches/RB-2.1.0/ndpf-gv-mkplots

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2422 - (show annotations) (download)
Fri Sep 9 18:28:23 2011 UTC (10 years, 8 months ago) by templon
File size: 7738 byte(s)
modified to print usage information with optional argument.

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 'month' : { 'timeargs' : [ '-s', 'n-'+repr(576*120)+'min', '-e', 'n'],
87 'timetag' : 'month',
88 'avrange' : 31*24*3600,
89 'avres' : 1800,
90 'sizeargs' : { 'small' : [ '--width', '576', '--height', '105'],
91 'large' : [ '--width', '2304', '--height', '420',
92 '-n', 'DEFAULT:18:',
93 '--x-grid',
94 'HOUR:12:DAY:1:DAY:3:86400:%d-%b'
95 ]
96 },
97 },
98 }
99
100 commonargs = ['--imgformat', 'PNG',
101 '--legend-position=east', '--legend-direction=bottomup']
102
103 import rrdtool
104 import time
105 import glob
106
107 ### function definitions
108
109 def doplot(grouplist, dbtype, psize, timetag, sizeargs, timeargs):
110
111 defs = list()
112 plots = list()
113
114 data_defs = list()
115 plot_defs = list()
116
117 for group in (grouplist + ['total']):
118 data_defs.append('DEF:'+group+'='+DATADIR+group+'.'+dbtype+'.rrd:'+dbtype+':AVERAGE')
119
120 for idx in range(len(grouplist)):
121 group = grouplist[idx]
122 pdefstr = 'AREA' ':' + group + colors[idx] + ':' + group
123 pdefstr = pdefstr + '\\n'
124 if idx > 0:
125 pdefstr = pdefstr + ':STACK'
126 plot_defs.append(pdefstr)
127
128 plot_defs.append('LINE:total#000000:total')
129
130 pargs = [ PLOTDIR + dbtype + '-' + timetag + '-' + psize + '.png'] + \
131 commonargs + ['-l', '0'] + sizeargs[psize] + timeargs + \
132 data_defs + plot_defs
133 rrdtool.graph( *pargs )
134
135 def doplot_wait(grouplist, dbtype, psize, timetag, sizeargs, timeargs):
136
137 defs = list()
138 plots = list()
139
140 data_defs = list()
141 plot_defs = list()
142
143 for group in (grouplist + ['rollover']):
144 data_defs.append('DEF:'+group+'='+DATADIR+group+'.'+dbtype+'.rrd:'+dbtype+':AVERAGE')
145
146 for idx in range(len(grouplist)):
147 group = grouplist[idx]
148 pdefstr = 'LINE3' ':' + group + colors[idx] + ':' + group
149 pdefstr = pdefstr + '\\n'
150 plot_defs.append(pdefstr)
151
152 plot_defs.append('LINE2:rollover#000000:rollover')
153
154 pargs = [ PLOTDIR + dbtype + '-' + timetag + '-' + psize + '.png'] + \
155 ['--slope-mode', '-o'] + \
156 commonargs + sizeargs[psize] + timeargs + \
157 data_defs + plot_defs
158 rrdtool.graph( *pargs )
159
160 def makeplots(prangedef):
161
162 resolu = prangedef['avres']
163
164 # first need to find "top eight" list
165 # base it on running jobs
166
167 now=int(time.mktime(time.localtime()))
168 end = (now / resolu) * resolu
169 start = end - (prangedef['avrange']) + resolu
170
171 ### block finding 'top N' group list ###
172
173 tgroup = dict() # structure tgroup[groupname] = total of hourly average
174
175 running_files = glob.glob(DATADIR+'*.running.rrd')
176 for db in running_files:
177 group = db[len(DATADIR):db.find('.running.rrd')]
178 if group == "total":
179 continue
180 tup = rrdtool.fetch(db,'AVERAGE','-r', repr(resolu),
181 '-s', repr(start), '-e', repr(end))
182 vallist = [0] # start with zero, in case no vals returned, get zero as answer
183 for tup2 in tup[2]:
184 val = tup2[0]
185 if val:
186 vallist.append(val)
187 tgroup[group] = sum(vallist)
188
189 groups_sorted = sorted(tgroup, key=tgroup.get, reverse=False)
190 topgroups=groups_sorted[-NUMGROUPS:]
191
192 if opts.rankonly:
193 print "Ranks for", prangedef['timetag'], " resolution is", resolu
194 for g in reversed(groups_sorted):
195 if tgroup[g] > 0:
196 print "%10s %12d" % (g, tgroup[g])
197 return
198
199 ### end block 'top N' group list ###
200
201 ### block generating plots ###
202
203 for dbtype in ['queued', 'running', 'waittime']:
204 for psize in ['small', 'large']:
205 if dbtype == 'waittime':
206 doplot_wait(topgroups, dbtype, psize, prangedef['timetag'],
207 prangedef['sizeargs'],
208 prangedef['timeargs'],
209 )
210 else:
211 doplot(topgroups, dbtype, psize, prangedef['timetag'],
212 prangedef['sizeargs'],
213 prangedef['timeargs']
214 )
215
216 for k in plotrangedef.keys():
217 makeplots(plotrangedef[k])
218
219 import sys
220 sys.exit(0)

Properties

Name Value
svn:executable *
svn:keywords Id URL

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