EIDiamond / grafana_image_downloader

Download Grafana panel as image, add watermark and send to telegram chat or channel.
Apache License 2.0
1 stars 1 forks source link

Capture single dashboard with all panels at once #5

Closed Dorlas closed 1 year ago

Dorlas commented 1 year ago

Tell me, please, is it possible to download the entire image from the Grafana at once with a dashboard that contains many panels?

EIDiamond commented 1 year ago

The project is using Grafana image renderer plugin to render images. At this moment the answer is no.

Based on the documentation.
Note: Image rendering of dashboards is not supported at this time.

I guess it's is possible to write script to make screenshot a whole dashboard, but I haven't research it.

Dorlas commented 1 year ago

I testing another project: https://github.com/wkhtmltopdf/wkhtmltopdf

On trivial sites work very well (make PNG or PDF with content).

BUT - on Grafana snapshot URL-s (without authentication) - i grab only BLACK square (((

EIDiamond commented 1 year ago

Great, thank you for sharing.

Another idea is:

  1. Parse dashboard json configuration or set up it manually in configuration: panels list, sizes and location.
  2. Render image for every panel on dashboard
  3. Combine all images into one image

It's just an idea. I guess the hardest part is combine images in the same way how they are represent on dashboard. But may works for simple cases. Just example of dashboard: image_2023-03-21_232239866

EIDiamond commented 1 year ago

BTW, I like idea with screenshot. It will work in all cases.

Dorlas commented 1 year ago

Hello again!

I write worked code, with webbrowser, pygetwindow and ImageGrab Python Modules.

First module open Firefox on target URL: firefox = webbrowser.Mozilla("C:\Program Files\Mozilla Firefox\firefox.exe") firefox.open("http://x.x.x.x:3000/d/cyos1EX7k3/pokazateli-vnutribol-nichnyh-konsul-tacij?orgId=1&kiosk=tv")

pygetwindow locate Browser coordinates. ImageGrab grab screenshot and save it to single file.

Next i'am collect all Grafana dashboards, what i needs.

With PIL (pillow) and PyPDF2 modules i'am convert all PNG to multple PDF files. Next all PDF files combine to single PDF.

And Finally i'am send PDF to email.