Generate graph in Grafana from API

grafanagraphmonitoring

I'm looking for a way to generate an arbitrary graph from the Grafana API, ideally by just feeding it a query.
After looking in the doc I don't see anything to do it directly, so the only way I can see would be to :

  • Generate a dashboard json with just the graph I want
  • Create the dashboard through the API by sending that json
  • Export that graph as jpg
  • Delete this darshboard

That seems a bit silly, isn't there a way to just generate a graph from a specific query directly ?
The goal here is to add a graph in our monitoring alerts, that way if we get a high load alert on a server for example I could generate a query to get that server's load graph, and include that in the alert e-mail. Nothing life changing, but it would be a nice feature to have I think.

Best Answer

You can render a graphic in this way:

http://[grafana-url]/render/dashboard-solo/db/[dashboard_name]?panelId=[number_panel]&?from=now-24h?to=now

You can change from and to.

If you use authentication you have to use Authorization Bearer and maybe base64encode for result from query.

I hope it helps.