/[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 2413 - (show annotations) (download)
Fri Aug 12 19:54:57 2011 UTC (10 years, 5 months ago) by templon
File size: 6387 byte(s)
scaling fonts in large versions

1 #! /usr/bin/env python
2 # $Id$
3 # Source: $URL$
4 # J. A. Templon, NIKHEF/PDP 2011
5
6 debug = 0
7
8 import os
9
10 NUMGROUPS=8
11 DATADIR=os.environ['HOME'] + '/ndpfdata/'
12 PLOTDIR=os.environ['HOME'] + '/public_html/'
13 # 8 class qualitative paired color scheme
14
15 colors = [ "#A6CEE3", "#1F77B4", "#B2DF8A", "#33A02C",
16 "#FB9A99", "#E31A1C", "#FDBF6F", "#FF7F00" ]
17
18 colors.reverse()
19
20 # for reference : resolutions of the RRAs
21 ## RRA:AVERAGE:0.5:1:1600 \
22 ## RRA:AVERAGE:0.5:2:1200 \
23 ## RRA:AVERAGE:0.5:10:1800 \
24 ## RRA:AVERAGE:0.5:30:2500 \
25 ## RRA:AVERAGE:0.5:120:1000 \
26 ## RRA:AVERAGE:0.5:1440:3650
27
28 # 1 min x 1600 points = 26,67 hr = 1.11 days
29 # 2 min x 1200 points = 40 hr = 1,67 days
30 # 10 min x 1800 points = 300 hr = 12,5 days
31 # 30 min x 2500 points = 1250 hr = 52,08 days
32 # 120 min x 1000 points = 2000 hr = 83,33 days
33 # 1440 min x 3650 points = 3650 days = 10 years
34
35 plotrangedef = {
36 'hr' : { 'timeargs' : [ '-s', 'n-200min', '-e', 'n' ],
37 'timetag' : 'hr',
38 'avrange' : 24*3600,
39 'avres' : 60,
40 'sizeargs' : { 'small' : [ '--width', '200', '--height', '125' ],
41 'large' : [ '--width', '800', '--height', '500' ]
42 },
43 },
44 'day' : { 'timeargs' : [ '-s', 'n-2000min', '-e', 'n' ],
45 'timetag' : 'day',
46 'avrange' : 24*3600,
47 'avres' : 60,
48 'sizeargs' : { 'small' : [ '--width', '200', '--height', '125' ],
49 'large' : [ '--width', '1000', '--height', '625' ]
50 },
51 },
52 'week' : { 'timeargs' : [ '-s', 'n-288hr', '-e', 'n' ],
53 'timetag' : 'week',
54 'avrange' : 7*24*3600,
55 'avres' : 600,
56 'sizeargs' : { 'small' : [ '--width', '576', '--height', '125' ],
57 'large' : [ '--width', '1728', '--height', '375',
58 '-n', 'DEFAULT:16:']
59 },
60 },
61
62 'month' : { 'timeargs' : [ '-s', 'n-48days', '-e', 'n'],
63 'timetag' : 'month',
64 'avrange' : 31*24*3600,
65 'avres' : 1800,
66 'sizeargs' : { 'small' : [ '--width', '576', '--height', '125' ],
67 'large' : [ '--width', '2304', '--height', '500',
68 '-n', 'DEFAULT:18:',
69 '--x-grid',
70 'HOUR:12:DAY:1:DAY:3:86400:%d-%b'
71 ]
72 },
73 },
74 }
75
76 commonargs = ['--imgformat', 'PNG',
77 '--legend-position=east', '--legend-direction=bottomup']
78
79 import rrdtool
80 import time
81 import glob
82
83 ### function definitions
84
85 def doplot(grouplist, dbtype, psize, timetag, sizeargs, timeargs):
86
87 defs = list()
88 plots = list()
89
90 data_defs = list()
91 plot_defs = list()
92
93 for group in (grouplist + ['total']):
94 data_defs.append('DEF:'+group+'='+DATADIR+group+'.'+dbtype+'.rrd:'+dbtype+':AVERAGE')
95
96 for idx in range(len(grouplist)):
97 group = grouplist[idx]
98 pdefstr = 'AREA' ':' + group + colors[idx] + ':' + group
99 pdefstr = pdefstr + '\\n'
100 if idx > 0:
101 pdefstr = pdefstr + ':STACK'
102 plot_defs.append(pdefstr)
103
104 plot_defs.append('LINE:total#000000:total')
105
106 pargs = [ PLOTDIR + dbtype + '-' + timetag + '-' + psize + '.png'] + \
107 commonargs + ['-l', '0'] + sizeargs[psize] + timeargs + \
108 data_defs + plot_defs
109 rrdtool.graph( *pargs )
110
111 def doplot_wait(grouplist, dbtype, psize, timetag, sizeargs, timeargs):
112
113 defs = list()
114 plots = list()
115
116 data_defs = list()
117 plot_defs = list()
118
119 for group in (grouplist + ['rollover']):
120 data_defs.append('DEF:'+group+'='+DATADIR+group+'.'+dbtype+'.rrd:'+dbtype+':AVERAGE')
121
122 for idx in range(len(grouplist)):
123 group = grouplist[idx]
124 pdefstr = 'LINE3' ':' + group + colors[idx] + ':' + group
125 pdefstr = pdefstr + '\\n'
126 plot_defs.append(pdefstr)
127
128 plot_defs.append('LINE2:rollover#000000:rollover')
129
130 pargs = [ PLOTDIR + dbtype + '-' + timetag + '-' + psize + '.png'] + \
131 ['--slope-mode', '-o'] + \
132 commonargs + sizeargs[psize] + timeargs + \
133 data_defs + plot_defs
134 rrdtool.graph( *pargs )
135
136 def makeplots(prangedef):
137
138 resolu = prangedef['avres']
139
140 # first need to find "top eight" list
141 # base it on running jobs
142
143 now=int(time.mktime(time.localtime()))
144 end = (now / resolu) * resolu
145 start = end - (prangedef['avrange']) + resolu
146
147 ### block finding 'top N' group list ###
148
149 tgroup = dict() # structure tgroup[groupname] = total of hourly average
150
151 running_files = glob.glob(DATADIR+'*.running.rrd')
152 for db in running_files:
153 group = db[len(DATADIR):db.find('.running.rrd')]
154 if group == "total":
155 continue
156 tup = rrdtool.fetch(db,'AVERAGE','-r', repr(resolu),
157 '-s', repr(start), '-e', repr(end))
158 vallist = [0] # start with zero, in case no vals returned, get zero as answer
159 for tup2 in tup[2]:
160 val = tup2[0]
161 if val:
162 vallist.append(val)
163 tgroup[group] = sum(vallist)
164
165 groups_sorted = sorted(tgroup, key=tgroup.get, reverse=False)
166 topgroups=groups_sorted[-NUMGROUPS:]
167
168 if debug:
169 print prangedef['timetag']
170 for g in groups_sorted:
171 print "%10s %12d" % (g, tgroup[g])
172
173 ### end block 'top N' group list ###
174
175 ### block generating plots ###
176
177 for dbtype in ['queued', 'running', 'waittime']:
178 for psize in ['small', 'large']:
179 if dbtype == 'waittime':
180 doplot_wait(topgroups, dbtype, psize, prangedef['timetag'],
181 prangedef['sizeargs'],
182 prangedef['timeargs'],
183 )
184 else:
185 doplot(topgroups, dbtype, psize, prangedef['timetag'],
186 prangedef['sizeargs'],
187 prangedef['timeargs']
188 )
189
190 for k in plotrangedef.keys():
191 makeplots(plotrangedef[k])
192
193 import sys
194 sys.exit(0)

Properties

Name Value
svn:executable *
svn:keywords Id URL

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