Skip to content

Commit

Permalink
merged issue #66
Browse files Browse the repository at this point in the history
  • Loading branch information
mircealungu committed Mar 28, 2018
2 parents 2641d36 + d4f4331 commit e1b2607
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Changed

- Added new graph: Version usage

- Added column (Hits in past 7 days) in Measurements Overview

- Fixed bug with configuration

- Changed rows and column in outlier-table
Expand Down
24 changes: 24 additions & 0 deletions flask_monitoringdashboard/database/function_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ def get_times():
return result


def get_hits(date_from=None):
""" Return all entries of measurements with the number of execution times which are called after 'date_from'
:param date_from: A datetime-object
"""
with session_scope() as db_session:
result = db_session.query(FunctionCall.endpoint,
func.count(FunctionCall.execution_time).label('count')). \
filter(FunctionCall.time > date_from).group_by(FunctionCall.endpoint).all()
db_session.expunge_all()
return result


def get_average(date_from=None):
""" Return the average of execution times which are called after 'date_from' grouped per endpoint
:param date_from: A datetime-object
"""
with session_scope() as db_session:
result = db_session.query(FunctionCall.endpoint,
func.avg(FunctionCall.execution_time).label('average')). \
filter(FunctionCall.time > date_from).group_by(FunctionCall.endpoint).all()
db_session.expunge_all()
return result


def get_data_from(time_from):
"""
Returns all data in the FunctionCall table, for the export data option.
Expand Down
9 changes: 7 additions & 2 deletions flask_monitoringdashboard/routings/measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from flask_monitoringdashboard.colors import get_color
from flask_monitoringdashboard.database.endpoint import get_last_accessed_times, get_num_requests
from flask_monitoringdashboard.database.function_calls import get_times, get_reqs_endpoint_day, get_versions, \
get_data_per_version, get_endpoints, get_data_per_endpoint, get_hits_per_version
get_data_per_version, get_endpoints, get_data_per_endpoint, get_hits_per_version, get_hits, get_average
from flask_monitoringdashboard.security import secure, is_admin


Expand All @@ -18,9 +18,14 @@ def overview():
colors = {}
for result in get_times():
colors[result.endpoint] = get_color(result.endpoint)

week_ago = datetime.datetime.now() - datetime.timedelta(days=7)
today = datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)

return render_template('dashboard/measurement-overview.html', link=config.link, curr=2, times=get_times(),
colors=colors, access=get_last_accessed_times(), session=session, index=0,
is_admin=is_admin())
is_admin=is_admin(), hits_last_days=get_hits(week_ago), hits_today=get_hits(today),
average_last_days=get_average(week_ago), average_today=get_average(today))


@blueprint.route('/measurements/heatmap')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,58 @@
<table class="table table-striped table-bordered table-hover sortable">
<thead>
<tr>
<th>Color</th>
<th class="clickable">Endpoint</th>
<th class="clickable">Hits</th>
<th class="clickable">Last accessed</th>
<th class="clickable">Average execution time (in ms)</th>
<th></th>
<th rowspan="2">Color</th>
<th class="clickable" rowspan="2">Endpoint</th>
<th colspan="3" style="text-align: center;">Number of hits</th>
<th colspan="3" style="text-align: center;">Average execution time (ms)</th>
<th class="clickable" rowspan="2">Last accessed</th>
<th rowspan="2">Details</th>
</tr>
<tr>
<th class="clickable">Today</th>
<th class="clickable">Last 7 days</th>
<th class="clickable">Overall</th>

<th class="clickable">Today</th>
<th class="clickable">Last 7 days</th>
<th class="clickable">Overall</th>
</tr>
</thead>
<tbody>
{% for record in times %}
<tr>
<td style="background-color: {{ colors[record.endpoint] }}"></td>
<td style="max-width: 200px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">{{ record.endpoint }}</td>
<td style="text-align: right;">
{% for hits in hits_today %}
{{ hits.count if hits.endpoint == record.endpoint }}
{% endfor %}
</td>
<td style="text-align: right;">
{% for hits in hits_last_days %}
{{ hits.count if hits.endpoint == record.endpoint }}
{% endfor %}
</td>
<td style="text-align: right;">{{ record.count }}</td>

<td style="text-align: right;">
{% for average in average_today %}
{{ ((average.average*10)|round)/10 if average.endpoint == record.endpoint }}
{% endfor %}
</td>
<td style="text-align: right;">
{% for average in average_last_days %}
{{ ((average.average*10)|round)/10 if average.endpoint == record.endpoint }}
{% endfor %}
</td>
<td style="text-align: right;">{{ ((record.average*10)|round)/10 }}</td>

{% for a in access %}
{% if record.endpoint == a.endpoint %}
<td style="text-align: center;">{{ "{:%Y-%m-%d %H:%M:%S }".format(a.last_accessed) if a.last_accessed }}</td>
{% endif %}
{% endfor %}
<td style="text-align: right;">{{ ((record.average*10)|round)/10 }}</td>

<td>
<a href="{{ url_for('dashboard.result_heatmap', end=record.endpoint) }}"
class="btn btn-default btn-sm right-align-custom">
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def desc():

setuptools.setup(
name="Flask-MonitoringDashboard",
version='1.10.9',
version='1.11.0',
packages=setuptools.find_packages(),
include_package_data=True,
platforms='Any',
Expand Down

0 comments on commit e1b2607

Please sign in to comment.