Generating reports and schedule your delivery Grafana

In this post we will see something very interesting, and have a Dashboard Grafana Chulis, where with custom graphs at all times we see the situation of our platform, no? Imagine that this, we add the ability to generate a report from the Dashboard that interests us PDF, and schedule your emailing to see the summary of yesterday, from last week…

 

Straight to the point, come! We started with a utility that has desarrrollado Izak Marais and we in the GitHub (from Microsoft and, who understands…), good, We have a service by pdflatex generate a PDF file that interests us Dashboard, and then we send sendemail already fully customized mail and reports that pleases us!

 

REQUIREMENTS,

The first, our machine Grafana, in my case is a Centos 7.3 which we will install the following requirements:

yum install texlive-pdftex texlive-latex-bin texlive-texconfig* texlive-latex* texlive-metafont* texlive-cmap* texlive-ec texlive-fncychap* texlive-pdftex-def texlive-fancyhdr* texlive-titlesec* texlive-multirow texlive-framed* texlive-wrapfig* texlive-parskip* texlive-caption texlive-ifluatex* texlive-collection-fontsrecommended texlive-collection-latexrecommended texinfo-tex

 

We downloaded and installed Go:

wget https://dl.google.com/go/go1.10.2.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.10.2.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin

 

And finally we downloaded the Reporter will allow us said, generate a PDF with Dashboards Grafana:

go get github.com/IzakMarais/reporter/...
go install -v github.com/IzakMarais/reporter/cmd/grafana-reporter

 

Just as opening the port on the firewall and Reloading the configuration:

firewall-cmd --zone=public --permanent --add-port=8686/tcp
firewall-cmd --reload

 

We can try to run it directly to validate that everything works fine, the use '–help’ to see some interesting parameter, such as connecting to a remote Grafana, etc… run:

/root/go/bin/grafana-reporter

 

Eye! Before further, Dashboards have to be created in Grafana v5 and v4 inherited no, ok? If you have some old dashboard, so simple will make a “Save as…” and we will become version 5.

 

Generating a report manually,

Now and we could try to generate a report, We have a couple of options, one that would create a Report button on the Dashboard itself so that when someone wants, you download a PDF of what you're watching. It would be as easy as in Grafana:

 

Within the Dashboard that interests us > Click on the nut or “Settings” > “Link” > “Add Dashboard Link” and indicate the following information

  • Type: Link, we marked such.
  • Url: http://DIRECCION_IP_GRAFANA:8686/api/v5/report/{dashboardUID}
  • Title: Informe PDF
  • Tooltip: Generate a PDF of this Dashboard
  • Icon: doc, to be an icon of a document.
  • Time range: I put mark to allow periods of time.
  • Variable values: Mark it to play with dates.
  • Open in new tab: We mark if we want the PDF generates it in a new tab.

 

And nothing, we would see that pressing a button as we generate the report in PDF!

 

As we can guess, the URL to generate the PDF would be something like (obviously we can play with the margins of the dates or periods of PDF):

http://DIRECCIÓN_IP_GRAFANA:8686/api/v5/report/ID-DASHBOARD?from=now-24h&to=now

 

 

Generating scheduled reports,

Come to the interesting! The first, we make the grafana-reporter starts with the machine, the fastest, to boot at startup, mismamente in add Cron with crontab -e’ the next:

@reboot /root/go/bin/grafana-reporter

 

If we want to send them by mail automatically, will install sendemail:

yum install sendemail

 

We create a script where we put the URLs of Reports interests us and we generate the downloaded with wget, and finally email it, I'll call for example 'grafana_report_diario.sh':

# Dashboard Servidores VMware
wget -O diario_VMware.pdf http://DIRECCION_IP_GRAFANA:8686/api/v5/report/NRkUakSik?from=now-24h&to=now

# Dashboard Servidores Citrix
wget -O diario_Citrix.pdf http://DIRECCION_IP_GRAFANA:8686/api/v5/report/YpIJqYkik?from=now-24h&to=now

sleep 40s
/usr/bin/sendemail -f desde@bujarra.com-t para@bujarra.com -s mail.bujarra.com -m "Estimados señores,\nSe les adjuntan los informes con los consumos de su datacenter.\nQue tengan muy buen dia!" -u "Grafana - Informe Diario" -xu usuario@bujarra.com -xp XXXXXXXX -o tls=auto -a diario_VMware.pdf diario_Citrix.pdf

 

It is script 'grafana_report_diario.sh’ It will run for example every day at 0 and as we will bring fresh data and send by mail to our bosses, customers, IT department…

 

Result,

This would be an example of PDF you are going to receive, clear that everyone will have their custom Dashboard, you serve as an example!

 

Do not tell me not!!! Awesome!!!

I hope you have been interesting and may be able to provide always something new and positive in your work!!

 

Hector Herrero
Latest posts by Hector Herrero (see all)