/[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 2396 - (show annotations) (download)
Mon Aug 8 10:37:29 2011 UTC (11 years, 2 months ago) by templon
File size: 5472 byte(s)
remove old code.

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

Properties

Name Value
svn:executable *
svn:keywords Id URL

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