6
6
from dashboard import blueprint , config
7
7
from dashboard .database import FunctionCall
8
8
from dashboard .database .endpoint import get_endpoint_column , get_endpoint_results , get_monitor_rule , \
9
- get_last_accessed_times , get_line_results , get_all_measurement_per_column
10
- from dashboard .database .function_calls import get_times
9
+ get_last_accessed_times , get_line_results , get_all_measurement_per_column , get_num_requests , \
10
+ get_endpoint_column_user_sorted
11
+ from dashboard .database .function_calls import get_times , get_data_per_version , get_versions , get_reqs_endpoint_day , \
12
+ get_endpoints , get_data_per_endpoint
11
13
from dashboard .security import secure
12
14
13
15
import plotly
17
19
@blueprint .route ('/measurements' )
18
20
@secure
19
21
def measurements ():
20
- t = get_times ()
21
- la = get_last_accessed_times ()
22
- return render_template ('measurements.html' , link = config .link , curr = 2 , times = t , access = la , session = session )
22
+ return render_template ('measurements.html' , link = config .link , curr = 2 , times = get_times (),
23
+ access = get_last_accessed_times (), session = session ,
24
+ heatmap = get_heatmap (end = None ), etpv = get_boxplot_per_version (), rpepd = get_stacked_bar (),
25
+ etpe = get_boxplot_per_endpoint ())
26
+
27
+
28
+ def get_boxplot_per_version ():
29
+ """
30
+ Creates a graph with the execution times per version
31
+ :return:
32
+ """
33
+ versions = [str (v .version ) for v in get_versions ()]
34
+
35
+ data = []
36
+ for v in versions :
37
+ values = [c .execution_time for c in get_data_per_version (v )]
38
+ data .append (go .Box (x = values , name = v ))
39
+
40
+ layout = go .Layout (
41
+ autosize = False ,
42
+ width = 900 ,
43
+ height = 350 + 40 * len (versions ),
44
+ plot_bgcolor = 'rgba(249,249,249,1)' ,
45
+ showlegend = False ,
46
+ title = 'Execution time for every version' ,
47
+ xaxis = dict (title = 'Execution time (ms)' ),
48
+ yaxis = dict (title = 'Version' )
49
+ )
50
+ return plotly .offline .plot (go .Figure (data = data , layout = layout ), output_type = 'div' , show_link = False )
51
+
52
+
53
+ def get_boxplot_per_endpoint ():
54
+ """
55
+ Creates a graph with the execution times per endpoint
56
+ :return:
57
+ """
58
+ endpoints = [str (e .endpoint ) for e in get_endpoints ()]
59
+
60
+ data = []
61
+ for e in endpoints :
62
+ values = [c .execution_time for c in get_data_per_endpoint (e )]
63
+ if len (e ) > 16 :
64
+ e = '...' + e [- 14 :]
65
+ data .append (go .Box (x = values , name = e ))
66
+
67
+ layout = go .Layout (
68
+ autosize = False ,
69
+ width = 900 ,
70
+ height = 350 + 40 * len (endpoints ),
71
+ plot_bgcolor = 'rgba(249,249,249,1)' ,
72
+ showlegend = False ,
73
+ title = 'Execution time for every endpoint' ,
74
+ xaxis = dict (title = 'Execution time (ms)' ),
75
+ yaxis = dict (tickangle = - 45 )
76
+ )
77
+ return plotly .offline .plot (go .Figure (data = data , layout = layout ), output_type = 'div' , show_link = False )
23
78
24
79
25
80
def formatter (ms ):
@@ -28,7 +83,7 @@ def formatter(ms):
28
83
:param ms: the number of ms
29
84
:return: a string representing the same amount, but now represented in seconds and ms.
30
85
"""
31
- sec = math .floor (ms / 1000 )
86
+ sec = math .floor (ms / 1000 )
32
87
ms = round (ms % 1000 , 2 )
33
88
if sec == 0 :
34
89
return '{0}ms' .format (ms )
@@ -81,6 +136,33 @@ def get_graphs_per_hour(end):
81
136
return graph1 .render_data_uri (), graph2 .render_data_uri ()
82
137
83
138
139
+ def get_stacked_bar ():
140
+ data = get_reqs_endpoint_day ()
141
+ graph = pygal .graph .horizontalstackedbar .HorizontalStackedBar (legend_at_bottom = True , height = 100 + len (data ) * 7 )
142
+ graph .title = 'Number of requests per endpoint per day'
143
+ graph .x_labels = []
144
+ endpoints = []
145
+ for d in data :
146
+ if d .newTime not in graph .x_labels :
147
+ graph .x_labels .append (d .newTime )
148
+ if d .endpoint not in endpoints :
149
+ endpoints .append (d .endpoint )
150
+
151
+ for e in endpoints :
152
+ lst = []
153
+ for t in graph .x_labels :
154
+ found = False
155
+ for d in data :
156
+ if e == d .endpoint and t == d .newTime :
157
+ found = True
158
+ lst .append (d .cnt )
159
+ if not found :
160
+ lst .append (0 )
161
+ graph .add (e , lst )
162
+
163
+ return graph .render_data_uri ()
164
+
165
+
84
166
def get_dot_charts (end , versions ):
85
167
"""
86
168
Function that builds two dot charts:
@@ -148,33 +230,85 @@ def get_boxplots(end, versions):
148
230
width = 900 ,
149
231
height = 350 + 40 * len (versions ),
150
232
plot_bgcolor = 'rgba(249,249,249,1)' ,
151
- showlegend = False
233
+ showlegend = False ,
234
+ title = 'Execution time for every version' ,
235
+ xaxis = dict (title = 'Execution time (ms)' ),
236
+ yaxis = dict (title = 'Version' )
152
237
)
153
238
graph1 = plotly .offline .plot (go .Figure (data = data , layout = layout ), output_type = 'div' , show_link = False )
154
239
155
- # boxplot: execution time per versions
156
- users = [str (c .group_by ) for c in get_endpoint_column (endpoint = end , column = FunctionCall .group_by )]
157
-
240
+ users = [str (c .group_by ) for c in get_endpoint_column_user_sorted (endpoint = end , column = FunctionCall .group_by )]
158
241
data = []
159
242
for u in users :
160
243
values = [str (c .execution_time ) for c in
161
244
get_all_measurement_per_column (endpoint = end , column = FunctionCall .group_by , value = u )]
162
- data .append (go .Box (x = values , name = u ))
245
+ data .append (go .Box (x = values , name = '{0} -' . format ( u ) ))
163
246
164
247
layout = go .Layout (
165
248
autosize = False ,
166
249
width = 900 ,
167
250
height = 350 + 40 * len (users ),
168
251
plot_bgcolor = 'rgba(249,249,249,1)' ,
169
- showlegend = False
252
+ showlegend = False ,
253
+ title = 'Execution time for every user' ,
254
+ xaxis = dict (title = 'Execution time (ms)' ),
255
+ yaxis = dict (title = 'User' )
170
256
)
171
257
graph2 = plotly .offline .plot (go .Figure (data = data , layout = layout ), output_type = 'div' , show_link = False )
172
258
return graph1 , graph2
173
259
174
260
175
- @blueprint .route ('/show-graph/<end>' )
261
+ def get_heatmap (end ):
262
+ # list of hours: 1:00 - 23:00
263
+ hours = ['0' + str (hour ) + ':00' for hour in range (0 , 10 )] + \
264
+ [str (hour ) + ':00' for hour in range (10 , 24 )]
265
+
266
+ data = get_num_requests (end )
267
+ # list of days (format: year-month-day)
268
+ days = [str (d .newTime [:10 ]) for d in data ]
269
+ # remove duplicates and sort the result
270
+ days = sorted (list (set (days )))
271
+
272
+ # create empty 2D-dictionary with the keys: [hour][day]
273
+ requests = {}
274
+ for hour in hours :
275
+ requests_day = {}
276
+ for day in days :
277
+ requests_day [day ] = 0
278
+ requests [hour ] = requests_day
279
+
280
+ # add data to the dictionary
281
+ for d in data :
282
+ day = str (d .newTime [:10 ])
283
+ hour = str (d .newTime [11 :16 ])
284
+ requests [hour ][day ] = d .count
285
+
286
+ # create a 2D-list out of the dictionary
287
+ requests_list = []
288
+ for hour in hours :
289
+ day_list = []
290
+ for day in days :
291
+ day_list .append (requests [hour ][day ])
292
+ requests_list .append (day_list )
293
+
294
+ layout = go .Layout (
295
+ autosize = False ,
296
+ width = 900 ,
297
+ height = 800 ,
298
+ plot_bgcolor = 'rgba(249,249,249,1)' ,
299
+ showlegend = False ,
300
+ title = 'Heatmap of number of requests' ,
301
+ xaxis = dict (title = 'Date' ),
302
+ yaxis = dict (title = 'Time' )
303
+ )
304
+
305
+ trace = go .Heatmap (z = requests_list , x = days , y = hours )
306
+ return plotly .offline .plot (go .Figure (data = [trace ], layout = layout ), output_type = 'div' , show_link = False )
307
+
308
+
309
+ @blueprint .route ('/result/<end>' )
176
310
@secure
177
- def show_graph (end ):
311
+ def result (end ):
178
312
rule = get_monitor_rule (end )
179
313
url = get_url (end )
180
314
versions = [str (c .version ) for c in get_endpoint_column (end , FunctionCall .version )]
@@ -188,6 +322,9 @@ def show_graph(end):
188
322
# (5) Execution time per version and (6) Execution time per user
189
323
graph5 , graph6 = get_boxplots (end , versions )
190
324
191
- return render_template ('show-graph.html' , link = config .link , session = session , rule = rule , url = url ,
325
+ # (7) Number of requests per hour
326
+ graph7 = get_heatmap (end )
327
+
328
+ return render_template ('endpoint.html' , link = config .link , session = session , rule = rule , url = url ,
192
329
times_data = graph1 , hits_data = graph2 , dot_chart_user = graph3 ,
193
- dot_chart_ip = graph4 , div_versions = graph5 , div_users = graph6 )
330
+ dot_chart_ip = graph4 , div_versions = graph5 , div_users = graph6 , div_heatmap = graph7 )
0 commit comments