How to create Grafana Dashboards-as-Code(Influx db as source)

I am trying to create the Grafana Dashboards and panel programmatically.

I tied this using Grafanalib + python+Prometheus and I am able to create nice dashboard with many lables.
I tried the same with Grafanalib+InfluxDB but the queries are not updating(Creating) in the graph. Is there any other way to do this.

What do you mean by “the queries are not updating(Creating) in the graph”? Are they not updating, or are they not being created?

Grafana has an HTTP API for Dashboards, which is what I assume the Weaveworks Grafanalib library is using. Grafana also provides a JavaScript example for scripting dashboards.

It’s possible that this is a problem with Grafana or the API, or a bug in the grafanalib library, or with your implementation. It’s hard to say without more information.

This is what I tried with WeaveWorks GrafanaLib library

My python script to create json it will create a graph

from grafanalib.core import *
dashboard = Dashboard(
        title="Free Disk",
            expr='SELECT mean("Percent_Idle_Time") FROM "win_cpu" WHERE ("host" = 'DESKTOP-V4S49U7') AND $timeFilter GROUP BY time(10m) fill(null)',

Find the screenshot of dashboard

This does not appear to be an issue with InfluxDB. As noted in Grafanalib issue #122, the library supports all datasources.

I see you’ve already commented on that issue. I suggest adding significantly more detail, since there isn’t enough information there for someone to answer your question.

If I understand the process correctly, you will first need to generate a JSON representation of the dashboard using the instructions here. You can then update the dashboard using Grafana’s HTTP API for Dashboards.

In that case, someone will need the following information to help you:

  1. How are you using Grafanalib? In addition to the script you shared above, what are the commands you are using to generate the JSON?
  2. Is the JSON that is being generated by Grafanalib correct?
  3. What commands are you using to update the dashboard in Grafana? What is their output? Are you seeing errors?

Hopefully someone from the Grafanalib library or Grafana community can help you from there.

I communicated with author of GrafanaLib -they told to use prometheus and they don’t have idea about influx.

OK, so contrary to the comment in that issue it sounds like they don’t actually support all datasources. Maybe you could open an issue requesting InfluxDB support?

Since Grafana dashboards can be represented using a JSON Model, and then uploaded using the API, there are many ways to create dashboards programmatically, depending on what your requirements are.

If the JavaScript example isn’t a good starting point for you, have you looked at: