Example #1
0
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 dashboard 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_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(end))
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_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)