Programatically export images (png/jpg) of grafana dashboard

I have a visual in grafana. I can manually go to the menu on the panel of grafana click share -> snapshot -> rendering and export the snapshot and then I can curl it using snapshot url. This works great. Is there a way I can script that in python?. Is there some api I can hit that will return png/jpg images from the graph panel of grafana dashboard?

I was googling around and it looks like there isn’t any way to gererate png/jpg images from the grafana dashboard periodically. if there is a way or any solution then please help me out
thanks in advance

1 Like

I was playing this morning on the same issue and I’ve found an “automatic” solution. Basically, you have to play with the panelId parameter, each picture on a dashboard has its own. See the example:

curl 'DASHBOARD_URL?orgId=1&from=1514764800000&to=1546300800000&panelId=4&width=1000&height=500&tz=Europe%2FZurich' -o 4.png

Above I am downloading the picture with panelId 4. Here the doc for the authentication via HTTP: https://grafana.com/docs/http_api/auth/

I hope it will help.

3 Likes

Hello!

I am trying to do the same thing here but what I get running the query like you wrote here is an HTML file, not a png file… the panelID and URL and all is OK, no auth issue. Do you know what I could be doing wrong?

This is the start of the file I get:

  !(function() {
    if ('PerformanceLongTaskTiming' in window) {
      var g = (window.__tti = { e: [] });
      g.o = new PerformanceObserver(function(l) {
        g.e = g.e.concat(l.getEntries());
      });
      g.o.observe({ entryTypes: ['longtask'] });
    }
  })();

</script>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width" />
<meta name="theme-color" content="#000" />

<title>Grafana</title>