Reporting Service for Grafana
Did you ever want to create (professional) reports based on Grafana dashboards? I did so in order to being able to automatically get monthly reports of my home's energy usage. That's how it started.
- Build reports based on grafana dashboards, PDF (default) and many other formats supported
- Easy-to-use configuration wizard, including fully automated functionality to create a demo report
- Include dynamic content from grafana (find here a reference for all
asciidcotor reporter calls):
- panels as images
- tables based on grafana panel queries or custom database queries (no images!)
- single values to be integrated in text, based on grafana panel queries or custom database queries
- Multi purpose use of the reporter
- webservice to be called directly from grafana
- standalone command line tool, e.g. to be automated with
cron
orbash
scrips - seemlessly runs from asciidocotor docker container without further dependencies
- Webhook callbacks before, on cancel and on finishing callbacks (see configuration file)
- Solid as a rock, also in case of template errors and whatever else may happen
- Full API documentation available
Functionalities are provided as shown here:
Database | Image rendering | Panel-based rendering | Query-based rendering |
---|---|---|---|
all SQL based datasources | supported | supported | supported |
Graphite | supported | supported | supported |
Prometheus | supported | supported | supported |
other datasources | supported | not-supported | not-supported |
You don't have a grafana setup runnning already? No worries, just configure
https://play.grafana.org
in the configuration wizard and see the magic
happen!
If your grafana setup requires a login, you'll have to setup an api key for the reporter. Please follow the steps described here first.
Windows:
- Download latest Windows executable
ruby-grafana-reporter -w
Raspberry Pi:
sudo apt-get install ruby
gem install ruby-grafana-reporter
ruby-grafana-reporter -w
Ruby environment:
gem install ruby-grafana-reporter
ruby-grafana-reporter -w
Docker environment (advanced users):
- Download latest single-rb file to an empty folder
- create a configuration file by calling
ruby ruby-grafana-reporter -w
(if in doubt, run the command within your docker container) - create file
/<<path-to-single-rb-file-folder>>/startup.sh
with the following content:
cd /documents
ruby bin/ruby-grafana-reporter
- add asciidoctor your compose yaml:
asciidoctor:
image: asciidoctor/docker-asciidoctor
container_name: asciidoctor
hostname: asciidoctor
volumes:
- /<<path-to-single-rb-file-folder>>:/documents
command:
sh /documents/startup.sh
restart: unless-stopped
- start/restart the asciidoctor docker container
The key feature of the report is, that it can easily be integrated with grafana.
For accessing the reporter from grafana, you need to simply add a link to your grafana dashboard:
- Open the dashboard configuration
- Select
Links
- Select
Add
- Fill out as following:
- Type:
link
- Url:
http://<<your-server-url>>:<<your-webservice-port>>/render?var-template=demo_report
- Title:
Demo Report
- Select
Time range
- Select
Variable values
- Type:
- Select
Add
Now go back to your dashboard and click the newly generated Demo Report
link on it. Now the renderer should start it's task and show you the expected
results.
Please note, that the reporter won't automatically refresh your screen to update
the progress. Simply hit F5
to refresh your browser. After the report has been
successfully built, it will show the PDF after the next refresh automatically.
You want to select a template in grafana, which shall then be rendered?
Piece of cake: Just add a dashboard variable to your grafana dashboard named
template
and let the user select or enter a template name. To make use of it,
you should change the link of the Demo Report
link to
http://<<your-server-url>>:<<your-webservice-port>>/render?
. On
hitting the new link in the dashboard, grafana will add the selected template as
a variable and forward it to the reporter.
Running the reporter as a webservice provides the following URLs
/overview - for all running or retained renderings
/render - for rendering a template, 'var-template' is the only mandatory GET parameter
/view_report - for viewing the status or receving the result of a specific rendering, is automatically called after a successfull /render call
/cancel_report - for cancelling the rendering of a specific report, normally not called manually, but on user interaction in the /view_report or /overview URL
The main endpoint to call for report generation is configured in the previous chapter Grafana integration.
However, if you would like to see, currently running report generations and previously generated reports, you may want to call the endpoint /overview
.
This is just a collection of things, I am heading for in future, without a schedule.
- Support all grafana datasources
- Solve code TODOs
- Become rubocop ready
If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.
The code in this project is licensed under MIT license.
Inspired by Izak Marai's grafana reporter
If this project saves you as much time as I hope it does, and if you'd like to support my work, feel free donate. :)