/[pdpsoft]/nl.nikhef.ndpf.groupviews/trunk/ndpf_gv_plots_common.py
ViewVC logotype

Contents of /nl.nikhef.ndpf.groupviews/trunk/ndpf_gv_plots_common.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3214 - (show annotations) (download) (as text)
Thu Oct 26 12:21:08 2017 UTC (4 years, 8 months ago) by templon
File MIME type: application/x-python
File size: 8587 byte(s)
changes to number of quarters

1 # std groupviews colors
2
3 colors = { 'lightblue' : "#A6CEE3", 'darkblue' : "#1F77B4",
4 'lightgreen' : "#B2DF8A", 'darkgreen' : "#33A02C",
5 'lightred' : "#FB9A99", 'darkred' : "#E31A1C",
6 'lightorange' : "#FDBF6F", 'darkorange' : "#FF7F00",
7 'stdgray' : "#d8d8d8", 'purple' : "#790EAD",
8 'black' : "#000000" }
9
10 colormap = { 0 : 'darkorange',
11 1 : 'lightorange',
12 2 : 'darkred',
13 3 : 'lightred',
14 4 : 'darkgreen',
15 5 : 'lightgreen',
16 6 : 'darkblue',
17 7 : 'lightblue'
18 }
19
20 # for reference : ranges of the RRAs
21 # base step size 60 sec
22 # step 1 : 60 sec x 1600 points : 1600 min : 26,67 hr : 1.11 days
23 # step 2 : 120 sec x 1200 points : 2400 min : 40 hr : 1,67 days
24 # step 10 : 600 sec x 1800 points : 18 000 min : 300 hr : 12,5 days
25 # step 30 : 1800 sec x 2500 points : 75 000 min : 1250 hr : 52.08 days
26 # step 120 : 7200 sec x 1000 points : 120 000 min : 2000 hr : 83.33 days
27 # step 480 : 28800 sec x 1000 points : 480 000 min : 8000 hr : 333.33 days
28 # step 1440 : 86400 sec x 3650 points : 3650 days : 10 years
29
30 # resolutions of RRAs
31
32 # 1 : 60 sec : 1 min
33 # 2 : 120 sec : 2 min
34 # 3 : 600 sec : 10 min
35 # 4 : 1 800 sec : 30 min
36 # 5 : 7 200 sec : 120 min : 2 hr
37 # 6 : 28 800 sec : 480 min : 8 hr
38 # 7 : 86 400 sec : 1440 min : 24 hr : 1 day
39
40 pdefs = {
41 'hour' : {
42 'range' : 24*3600,
43 'res' : 60,
44 'timeargs' : [ '-s', 'n-200min', '-e', 'n' ],
45 'small' : {
46 'width' : 200,
47 'height' : 125,
48 'opts' : ['--x-grid', 'MINUTE:20:HOUR:1:HOUR:1:0:%H:00' ]
49 },
50 'large' : {
51 'width' : 800,
52 'height' : 500,
53 'opts' : [ ],
54 },
55 },
56 'day' : {
57 'range' : 24*3600,
58 'res' : 60,
59 'timeargs' : [ '-s', 'n-2000min', '-e', 'n' ],
60 'small' : {
61 'width' : 200,
62 'height' : 125,
63 'opts' : ['--x-grid', 'HOUR:6:DAY:1:HOUR:12:0:%a %H:00' ]
64 },
65 'large' : {
66 'width' : 1000,
67 'height' : 625,
68 'opts' : [ ],
69 },
70 },
71
72 'week' : {
73 'range' : 7*24*3600,
74 'res' : 600,
75 'timeargs' : [ '-s', 'n-288hr', '-e', 'n' ],
76 'small' : {
77 'width' : 576,
78 'height' : 125,
79 'opts' : [ ]
80 },
81 'large' : {
82 'width' : 1728,
83 'height' : 375,
84 'opts' : ['-n', 'DEFAULT:16' ],
85 },
86 },
87
88 'month' : {
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 'range' : 31*24*3600,
93 'res' : 1800,
94 'timeargs' : [ '-s', 'n-'+repr(576*120)+'min', '-e', 'n'],
95 'small' : {
96 'width' : 576,
97 'height' : 105,
98 'opts' : [ ]
99 },
100 'large' : {
101 'width' : 2304,
102 'height' : 420,
103 'opts' : [ '-n', 'DEFAULT:18:', '--x-grid',
104 'HOUR:12:DAY:1:DAY:3:86400:%d-%b' ]
105 },
106 },
107 'year' : {
108 'range' : 365*24*3600,
109 'res' : 86400,
110 'timeargs' : [ '-s', 'n-'+repr(576*1440)+'min', '-e', 'n'],
111 'small' : {
112 'width' : 576,
113 'height' : 105,
114 'opts' : [ ]
115 },
116 'large' : {
117 'width' : 2304,
118 'height' : 420,
119 'opts' : [ ],
120 },
121 },
122
123 ## # adjusting for nice plot ... now 12/4 of a year
124
125 'alltime' : {
126 'range' : 15*365*24*3600/4,
127 'res' : 86400,
128 'timeargs' : [ '-s', 'n-'+repr(15*365*1440/4)+'min', '-e', 'n'],
129 'small' : {
130 'width' : 576,
131 'height' : 105,
132 'opts' : ['--x-grid', 'MONTH:3:YEAR:1:YEAR:1:31536000:%Y' ]
133 },
134 'large' : {
135 'width' : 2304,
136 'height' : 420,
137 'opts' : [ '--x-grid', 'MONTH:1:YEAR:1:MONTH:3:2592000:%b-%Y']
138 }
139 }
140 }
141
142 import rrdtool
143 import time
144
145 ### function definitions
146
147 def getfracs(groupsdict, totaldb, range, resolu):
148
149 now=int(time.mktime(time.localtime()))
150 end = (now / resolu) * resolu
151 start = end - range + resolu # adding resolu avoids worry about off by one?
152 # first do total capacity (need for dividing into each component result)
153
154 tup = rrdtool.fetch(totaldb[1],'AVERAGE','-r', repr(resolu),
155 '-s', repr(start), '-e', repr(end))
156 vallist = [0] # start with zero, in case no vals returned, get zero as answer
157 for tup2 in tup[2]:
158 val = tup2[0]
159 if val:
160 vallist.append(val)
161
162 # put numbers in meaningful units now. after summing vallist,
163 # result is an
164 # sum over the time range, of data averages over "resolu"
165 # ... native resolution is in minutes, so multiplying by
166 # (resolu / 60) puts the answer in core-minutes; dividing by
167 # the number of minutes in the range gives the average number
168 # of cores occupied, over the range
169
170 totval = sum(vallist) * (resolu / 60) / ( (end-start) / 60. )
171
172 ### now find same for each component
173
174 tgroup = dict() # structure tgroup[groupname] = averages over interval
175
176 for group in groupsdict:
177 tup = rrdtool.fetch(groupsdict[group][1],'AVERAGE','-r', repr(resolu),
178 '-s', repr(start), '-e', repr(end))
179 vallist = [0] # start with zero, in case no vals returned, get zero as answer
180 for tup2 in tup[2]:
181 val = tup2[0]
182 if val:
183 vallist.append(val)
184
185 tgroup[group] = sum(vallist) * (resolu / 60) / ( (end-start) / 60. )
186
187 pgroup = dict() # percentages over interval
188 if totval == 0.0 : return
189 for g in tgroup.keys():
190 pgroup[g] = 100*tgroup[g]/totval
191
192 return (tgroup, pgroup)
193
194 def getqueued(groupsdict, range, resolu):
195
196 now=int(time.mktime(time.localtime()))
197 end = (now / resolu) * resolu
198 start = end - range + resolu # adding resolu avoids worry about off by one?
199
200 tgroup = dict() # structure tgroup[groupname] = averages over interval
201
202 for group in groupsdict:
203 tup = rrdtool.fetch(groupsdict[group][1],'AVERAGE','-r', repr(resolu),
204 '-s', repr(start), '-e', repr(end))
205 vallist = [0] # start with zero, in case no vals returned, get zero as answer
206 for tup2 in tup[2]:
207 val = tup2[0]
208 if val:
209 vallist.append(val)
210
211 # put numbers in meaningful units now. after summing vallist,
212 # result is an
213 # sum over the time range, of data averages over "resolu"
214 # ... native resolution is in minutes, so multiplying by
215 # (resolu / 60) puts the answer in core-minutes; dividing by
216 # the number of minutes in the range gives the average number
217 # of cores occupied, over the range
218
219 tgroup[group] = sum(vallist) * (resolu / 60) / ( (end-start) / 60. )
220
221 return tgroup
222
223 class Plot:
224 def __init__(self):
225 self.bands = list()
226 self.lines = None # optional
227 self.labels = None # optional
228 self.colors = list()
229 self.datafile = dict()
230 self.size = None
231 self.opts = None
232 self.range = None
233 def generate(self, file=None):
234 data_defs = list()
235 for group in self.bands + self.lines:
236 data_defs.append('DEF:%s=%s:%s:AVERAGE' % (group, self.datafile[group][1], self.datafile[group][0]))
237
238 plot_defs = list()
239 if not self.labels:
240 self.labels = dict()
241 for g in self.bands + self.lines:
242 self.labels[g] = g
243 for g in self.bands:
244 plot_defs.append('AREA:%s%s:%s\\n:STACK' % (g, self.colors[g], self.labels[g]))
245 for g in self.lines:
246 plot_defs.append('LINE:%s%s:%s\\n' % (g, self.colors[g], self.labels[g]))
247
248 dbtype = 'run'
249 timetag = 'tst'
250 ranktype = 'tstrank'
251 psize = 'tstp'
252 pargs = [ self.plotfile ] + \
253 ['--imgformat', 'PNG', '--legend-position=east', \
254 '--legend-direction=bottomup', '-l', '0'] + \
255 ['--width', str(self.width), '--height', str(self.height) ] + \
256 self.opts + self.timeargs + [data_defs + plot_defs]
257
258
259 rrdtool.graph( *pargs )

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