Chris Stryczynski
Chris Stryczynski

Reputation: 33861

How can I change the datasource for a Grafana dashboard?

I've got a new datasource I would like an existing dashboard to use.

How can I change it over? Is there a quicker way than exporting / importing the dashboard?

Upvotes: 31

Views: 42929

Answers (7)

RomainCarrillo
RomainCarrillo

Reputation: 1

For anyone looking for a quick win, here is what worked for me when I wanted to go from a datasource to another one with the same type (In my case InfluxDB) :

  1. First of all get the id of your current datasource, you can get it from the end of the url while modifying it
  2. Then create your new datasource and get it's id
  3. Go to your dashboard settings
  4. Go to JSON Model and simply replace the current db id with new db id (fastest way is to copy the full json in a text editor and do a search and replace all)
  5. Save changes on the json
  6. Save dashboard and reload

Upvotes: 0

cane
cane

Reputation: 1027

open json model, find templating.list section. add following part

  "templating": {
    "list": [
      {
        "label": "Data source",
        "name": "DS_PROMETHEUS",
        "query": "prometheus",
        "type": "datasource"
      },
      ...

It helped me to fix most of broken dashboards. Be sure if datasource objects defined in such form

"datasource": {
  "type": "prometheus",
  "uid": "${DS_PROMETHEUS}"
},

Upvotes: 0

NoNoob
NoNoob

Reputation: 123

Add __inputs block at the root of JSON file

{
"__inputs": [
    {
      "name": "DS_PROMETHEUS_ID",
      "label": "Prometheus Data Source",
      "description": "",
      "type": "datasource",
      "pluginId": "prometheus",
      "pluginName": "Prometheus"
    }
  ],

...
description: "",
panels:[...] 
...
}

then replace all static uid values with ${DS_PROMETHEUS_ID}

Now while importing the dashboard you will get the option to choose your own data source.

enter image description here

Upvotes: 6

Math666
Math666

Reputation: 101

In the JSON Model (dashboard settings), you can just replace all the occurrence of the id of the old source by the id of your new one

Upvotes: 0

Udo
Udo

Reputation: 2387

The following trick worked for me with Grafana 8.

As preparation you have to create a datasource variable "DS_PROMETHEUS".

Then inside the dashboard:

  1. Click "Share Dashboard or Panel"
  2. Switch to "Export" Tab
  3. Activate "Export for sharing externally"
  4. Click "View JSON" and copy the json to the clipboard

Then in the same dashboard open the "Dashboard settings"->"JSON Model" and paste the json from above.

Upvotes: 3

michalrudko
michalrudko

Reputation: 1530

Specifying a variable would not solve all the problems with changing a data source for the existing dashboard - there will be still some metadata pointing to the old one, which will result in failures. The only thing that worked for me was to go to dashboard setting and copy aside the JSON model, careful find+replace and pasting back the model. I know it's pretty lame, but this was the only thing that worked. There seems to be something missing with this feature in Grafana at the moment...

Upvotes: 12

sumek
sumek

Reputation: 28132

You can specify data source variable for a dashboard:

http://docs.grafana.org/reference/templating/#variable-types

Upvotes: 1

Related Questions