def test_update_monitor_rule(self): """ Test whether the function returns the right values. """ from flask_monitoringdashboard.database.endpoint import get_monitor_rule, update_monitor_rule current_value = get_monitor_rule(NAME).monitor new_value = not current_value update_monitor_rule(NAME, new_value) self.assertEqual(get_monitor_rule(NAME).monitor, new_value)
def test_get_monitor_rule(self): """ Test wheter the function returns the right values. """ from flask_monitoringdashboard.database.endpoint import get_monitor_rule from flask_monitoringdashboard import config rule = get_monitor_rule(NAME) self.assertEqual(rule.endpoint, NAME) self.assertTrue(rule.monitor) self.assertEqual(rule.version_added, config.version)
def result_hits_per_hour(end): rule = get_monitor_rule(end) url = get_url(end) return render_template('endpoint/plotly.html', link=config.link, session=session, rule=rule, url=url, graph=get_hits_per_hour(end), end=end, index=2)
def result_time_per_version(end): rule = get_monitor_rule(end) url = get_url(end) return render_template('endpoint/plotly.html', link=config.link, session=session, rule=rule, url=url, graph=get_time_per_version(end, get_versions(end)), end=end, index=5)
def result_outliers(end): rule = get_monitor_rule(end) url = get_url(end) return render_template('endpoint/outliers.html', link=config.link, session=session, rule=rule, url=url, end=end, index=7, table=get_outliers_sorted(end, Outlier.execution_time))
def rules(): form = MonitorDashboard() values = {} all_rules = user_app.url_map.iter_rules() if request.method == 'POST' and form.validate(): # Remove the monitor endpoints from the database reset_monitor_endpoints() for rule in user_app.url_map.iter_rules(): # Remove existing wrappers original = getattr(user_app.view_functions[rule.endpoint], 'original', None) if original: user_app.view_functions[rule.endpoint] = original # request.form only contains checkboxes that are checked for data in request.form: if data.startswith('checkbox-'): endpoint = data.rsplit('-', 1)[1] update_monitor_rule(endpoint, value=True) rule = get_monitor_rule(endpoint) # Add wrappers to the existing functions user_app.view_functions[rule.endpoint] = track_performance(user_app.view_functions[rule.endpoint], rule.endpoint) # store the result from the database in values (used for rendering) for rule in user_app.url_map.iter_rules(): values[rule.endpoint] = get_monitor_rule(rule.endpoint).monitor la = get_last_accessed_times() # filter flask_monitoringdashboard rules all_rules = [r for r in all_rules if not r.rule.startswith('/' + config.link) and not r.rule.startswith('/static-' + config.link)] colors = {} for rule in all_rules: colors[rule.endpoint] = get_color(rule.endpoint) return render_template('dashboard/rules.html', link=config.link, curr=1, rules=all_rules, access=la, form=form, session=session, values=values, colors=colors)
def result_time_per_version_per_ip(end): rule = get_monitor_rule(end) url = get_url(end) graph, form = get_time_per_version_per_ip(end, get_versions(end)) return render_template('endpoint/time_per_user.html', link=config.link, session=session, rule=rule, url=url, graph=graph, form=form, end=end, index=4)