Coder Social home page Coder Social logo

ruby-grafana-reporter's Introduction

MIT License Build Status Coverage Status Gem Version

Ruby Grafana Reporter

Reporting Service for Grafana

Table of Contents

About the project

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.

Features

  • 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 or bash 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

Quick Start

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:

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

Grafana integration

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
  • 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.

Webservice overview

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.

Roadmap

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

Contributing

If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.

Licensing

The code in this project is licensed under MIT license.

Acknowledgements

Inspired by Izak Marai's grafana reporter

Donations

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. :)

paypal

ruby-grafana-reporter's People

Contributors

divinity666 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.