Overview, Node pages: Add bar chart of daily runs

The Overview will display a bar chart of daily runs, categorized by
report status (changed, unchanged, failed).

The chart data is loaded asynchronously from JSON so it doesn't provoke
a delay in the page load. The data is JSON enconded.

This feature was in the original Puppet Dashboard.  The change was
proposed and discussed in issue #308 .

Application changes:

- app.py: New view daily_reports_chart to serve the chart data as JSON.

- dailychart.py: Submodule to query and format the chart data.

Template changes:

- layout.html: New block to add more elements to the HTML header.

- index.html, node.html: Add C3 CSS in header block, add DIV placeholder
  for the chart in content block, add dailychart.js (and dependencies)
  in script block.

Settings:

- DAILY_REPORTS_CHART_ENABLED: New setting to turn off the charts. By
  default is on.

- DAILY_REPORTS_CHART_DAYS: Changes the range of days to display in the
  charts.

Javascript changes:

- dailychart.js: New script that loads the JSON data for the chart and
  calls C3 to generate a bar chart.

CSS changes:

- puppetboard.css: Set fixed height to the chart container to avoid a
  page resize after the chart is loaded.
This commit is contained in:
Manuel Quiñones
2016-10-25 13:52:56 -03:00
parent 68ef8ac0da
commit 08e214ec15
8 changed files with 180 additions and 1 deletions

View File

@@ -13,7 +13,7 @@ from itertools import tee
from flask import (
Flask, render_template, abort, url_for,
Response, stream_with_context, redirect,
request, session
request, session, jsonify
)
from pypuppetdb import connect
@@ -24,6 +24,7 @@ from puppetboard.utils import (
get_or_abort, yield_or_stop,
jsonprint, prettyprint, Pagination
)
from puppetboard.dailychart import get_daily_reports_chart
import werkzeug.exceptions as ex
@@ -1109,3 +1110,23 @@ def radiator(env):
stats=stats,
total=num_nodes
)
@app.route('/daily_reports_chart.json',
defaults={'env': app.config['DEFAULT_ENVIRONMENT']})
@app.route('/<env>/daily_reports_chart.json')
def daily_reports_chart(env):
"""Return JSON data to generate a bar chart of daily runs.
If certname is passed as GET argument, the data will target that
node only.
"""
certname = request.args.get('certname')
result = get_or_abort(
get_daily_reports_chart,
db=puppetdb,
env=env,
days_number=app.config['DAILY_REPORTS_CHART_DAYS'],
certname=certname,
)
return jsonify(result=result)