Skip to content

Commit e1b2607

Browse files
committed
merged issue #66
2 parents 2641d36 + d4f4331 commit e1b2607

File tree

5 files changed

+73
-10
lines changed

5 files changed

+73
-10
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Changed
1111

1212
- Added new graph: Version usage
1313

14+
- Added column (Hits in past 7 days) in Measurements Overview
15+
1416
- Fixed bug with configuration
1517

1618
- Changed rows and column in outlier-table

flask_monitoringdashboard/database/function_calls.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,30 @@ def get_times():
4646
return result
4747

4848

49+
def get_hits(date_from=None):
50+
""" Return all entries of measurements with the number of execution times which are called after 'date_from'
51+
:param date_from: A datetime-object
52+
"""
53+
with session_scope() as db_session:
54+
result = db_session.query(FunctionCall.endpoint,
55+
func.count(FunctionCall.execution_time).label('count')). \
56+
filter(FunctionCall.time > date_from).group_by(FunctionCall.endpoint).all()
57+
db_session.expunge_all()
58+
return result
59+
60+
61+
def get_average(date_from=None):
62+
""" Return the average of execution times which are called after 'date_from' grouped per endpoint
63+
:param date_from: A datetime-object
64+
"""
65+
with session_scope() as db_session:
66+
result = db_session.query(FunctionCall.endpoint,
67+
func.avg(FunctionCall.execution_time).label('average')). \
68+
filter(FunctionCall.time > date_from).group_by(FunctionCall.endpoint).all()
69+
db_session.expunge_all()
70+
return result
71+
72+
4973
def get_data_from(time_from):
5074
"""
5175
Returns all data in the FunctionCall table, for the export data option.

flask_monitoringdashboard/routings/measurements.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from flask_monitoringdashboard.colors import get_color
99
from flask_monitoringdashboard.database.endpoint import get_last_accessed_times, get_num_requests
1010
from flask_monitoringdashboard.database.function_calls import get_times, get_reqs_endpoint_day, get_versions, \
11-
get_data_per_version, get_endpoints, get_data_per_endpoint, get_hits_per_version
11+
get_data_per_version, get_endpoints, get_data_per_endpoint, get_hits_per_version, get_hits, get_average
1212
from flask_monitoringdashboard.security import secure, is_admin
1313

1414

@@ -18,9 +18,14 @@ def overview():
1818
colors = {}
1919
for result in get_times():
2020
colors[result.endpoint] = get_color(result.endpoint)
21+
22+
week_ago = datetime.datetime.now() - datetime.timedelta(days=7)
23+
today = datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
24+
2125
return render_template('dashboard/measurement-overview.html', link=config.link, curr=2, times=get_times(),
2226
colors=colors, access=get_last_accessed_times(), session=session, index=0,
23-
is_admin=is_admin())
27+
is_admin=is_admin(), hits_last_days=get_hits(week_ago), hits_today=get_hits(today),
28+
average_last_days=get_average(week_ago), average_today=get_average(today))
2429

2530

2631
@blueprint.route('/measurements/heatmap')

flask_monitoringdashboard/templates/dashboard/measurement-overview.html

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,58 @@
3838
<table class="table table-striped table-bordered table-hover sortable">
3939
<thead>
4040
<tr>
41-
<th>Color</th>
42-
<th class="clickable">Endpoint</th>
43-
<th class="clickable">Hits</th>
44-
<th class="clickable">Last accessed</th>
45-
<th class="clickable">Average execution time (in ms)</th>
46-
<th></th>
41+
<th rowspan="2">Color</th>
42+
<th class="clickable" rowspan="2">Endpoint</th>
43+
<th colspan="3" style="text-align: center;">Number of hits</th>
44+
<th colspan="3" style="text-align: center;">Average execution time (ms)</th>
45+
<th class="clickable" rowspan="2">Last accessed</th>
46+
<th rowspan="2">Details</th>
47+
</tr>
48+
<tr>
49+
<th class="clickable">Today</th>
50+
<th class="clickable">Last 7 days</th>
51+
<th class="clickable">Overall</th>
52+
53+
<th class="clickable">Today</th>
54+
<th class="clickable">Last 7 days</th>
55+
<th class="clickable">Overall</th>
4756
</tr>
4857
</thead>
4958
<tbody>
5059
{% for record in times %}
5160
<tr>
5261
<td style="background-color: {{ colors[record.endpoint] }}"></td>
5362
<td style="max-width: 200px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">{{ record.endpoint }}</td>
63+
<td style="text-align: right;">
64+
{% for hits in hits_today %}
65+
{{ hits.count if hits.endpoint == record.endpoint }}
66+
{% endfor %}
67+
</td>
68+
<td style="text-align: right;">
69+
{% for hits in hits_last_days %}
70+
{{ hits.count if hits.endpoint == record.endpoint }}
71+
{% endfor %}
72+
</td>
5473
<td style="text-align: right;">{{ record.count }}</td>
74+
75+
<td style="text-align: right;">
76+
{% for average in average_today %}
77+
{{ ((average.average*10)|round)/10 if average.endpoint == record.endpoint }}
78+
{% endfor %}
79+
</td>
80+
<td style="text-align: right;">
81+
{% for average in average_last_days %}
82+
{{ ((average.average*10)|round)/10 if average.endpoint == record.endpoint }}
83+
{% endfor %}
84+
</td>
85+
<td style="text-align: right;">{{ ((record.average*10)|round)/10 }}</td>
86+
5587
{% for a in access %}
5688
{% if record.endpoint == a.endpoint %}
5789
<td style="text-align: center;">{{ "{:%Y-%m-%d %H:%M:%S }".format(a.last_accessed) if a.last_accessed }}</td>
5890
{% endif %}
5991
{% endfor %}
60-
<td style="text-align: right;">{{ ((record.average*10)|round)/10 }}</td>
92+
6193
<td>
6294
<a href="{{ url_for('dashboard.result_heatmap', end=record.endpoint) }}"
6395
class="btn btn-default btn-sm right-align-custom">

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def desc():
1919

2020
setuptools.setup(
2121
name="Flask-MonitoringDashboard",
22-
version='1.10.9',
22+
version='1.11.0',
2323
packages=setuptools.find_packages(),
2424
include_package_data=True,
2525
platforms='Any',

0 commit comments

Comments
 (0)