Metrics display tune

This commit is contained in:
redref
2017-02-01 13:56:31 +01:00
parent 1758f972f1
commit bb26c5bbea
3 changed files with 15 additions and 23 deletions

View File

@@ -531,25 +531,17 @@ def reports_ajax(env, node_name):
reports_events = [] reports_events = []
total = 0 total = 0
report_event_counts = {} # Convert metrics to relational dict
# Create a map from the metrics data to what the templates metrics = {}
# use to express the data.
events_metrics = ['success', 'failure', 'noop']
resources_metrics = ['total', 'skipped']
for report in reports_events: for report in reports_events:
if total is None: if total is None:
total = puppetdb.total total = puppetdb.total
report_counts = {} metrics[report.hash_] = {'resources': {}, 'events': {}}
for metric in report.metrics: for m in report.metrics:
if ('category' in metric and metric['category'] == 'events' and if m['category'] not in metrics[report.hash_]:
'name' in metric and metric['name'] in events_metrics): metrics[report.hash_][m['category']] = {}
report_counts[metric['name']] = metric['value'] metrics[report.hash_][m['category']][m['name']] = m['value']
if ('category' in metric and metric['category'] == 'resources' and
'name' in metric and metric['name'] in resources_metrics):
report_counts[metric['name']] = metric['value']
report_event_counts[report.hash_] = report_counts
if total is None: if total is None:
total = 0 total = 0
@@ -560,7 +552,7 @@ def reports_ajax(env, node_name):
total=total, total=total,
total_filtered=total, total_filtered=total,
reports=reports, reports=reports,
report_event_counts=report_event_counts, metrics=metrics,
envs=envs, envs=envs,
current_env=env, current_env=env,
columns=REPORTS_COLUMNS[:max_col]) columns=REPORTS_COLUMNS[:max_col])

View File

@@ -57,16 +57,16 @@
{% endif %} {% endif %}
{%- endmacro %} {%- endmacro %}
{% macro report_status(caller, status, node_name, events, current_env, unreported_time=False, report_hash=False) -%} {% macro report_status(caller, status, node_name, metrics, current_env, unreported_time=False, report_hash=False) -%}
<a class="ui {{status}} label status" href="{{url_for('report', env=current_env, node_name=node_name, report_id=report_hash)}}">{{ status|upper }}</a> <a class="ui {{status}} label status" href="{{url_for('report', env=current_env, node_name=node_name, report_id=report_hash)}}">{{ status|upper }}</a>
{% if status == 'unreported' %} {% if status == 'unreported' %}
<span class="ui label status"> {{ unreported_time|upper }} </span> <span class="ui label status"> {{ unreported_time|upper }} </span>
{% else %} {% else %}
<span title="Total resources" class="ui small count label{% if events['total'] %} total">{{events['total']}}{% else %}">0{% endif%}</span> <span title="Total resources" class="ui small count label{% if metrics.resources.total %} total">{{ metrics.resources.total }}{% else %}">0{% endif%}</span>
<span title="Failure events" class="ui small count label{% if events['failure'] %} failed">{{events['failure']}}{% else %}">0{% endif%}</span> <span title="Failure events" class="ui small count label{% if metrics.events.failure %} failed">{{ metrics.events.failure }}{% else %}">0{% endif%}</span>
<span title="Success events" class="ui small count label{% if events['success'] %} changed">{{events['success']}}{% else %}">0{% endif%}</span> <span title="Success events" class="ui small count label{% if metrics.events.success %} changed">{{ metrics.events.success }}{% else %}">0{% endif%}</span>
<span title="Skip events" class="ui small count label{% if events['skipped'] %} skipped">{{events['skipped']}}{% else %}">0{% endif%}</span> <span title="Skipped resources" class="ui small count label{% if metrics.resources.skipped %} skipped">{{ metrics.resources.skipped }}{% else %}">0{% endif%}</span>
<span title="Noop resources" class="ui small count label{% if events['noop'] %} noop">{{events['noop']}}{% else %}">0{% endif%}</span> <span title="Noop events" class="ui small count label{% if metrics.events.noop %} noop">{{ metrics.events.noop }}{% else %}">0{% endif%}</span>
{% endif %} {% endif %}
{%- endmacro %} {%- endmacro %}

View File

@@ -15,7 +15,7 @@
"<span rel=\"utctimestamp\">{{ report[column.attr] }}</span>" "<span rel=\"utctimestamp\">{{ report[column.attr] }}</span>"
{%- elif column.type == 'status' -%} {%- elif column.type == 'status' -%}
{% filter jsonprint -%} {% filter jsonprint -%}
{{ macros.report_status(status=report.status, node_name=report.node, events=report_event_counts[report.hash_], report_hash=report.hash_, current_env=current_env) }} {{ macros.report_status(status=report.status, node_name=report.node, metrics=metrics[report.hash_], report_hash=report.hash_, current_env=current_env) }}
{%- endfilter %} {%- endfilter %}
{%- elif column.type == 'node' -%} {%- elif column.type == 'node' -%}
{% filter jsonprint %}<a href="{{url_for('node', env=current_env, node_name=report.node)}}">{{ report.node }}</a>{% endfilter %} {% filter jsonprint %}<a href="{{url_for('node', env=current_env, node_name=report.node)}}">{{ report.node }}</a>{% endfilter %}