How can I change the datasource for a Grafana dashboard?
Asked Answered
C

5

28

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?

Cosette answered 19/2, 2019 at 23:40 Comment(3)
You should see that from the panel. Click Edit->Metrics->Data SourceBridie
I'd have to change that for each panel thoughCosette
@ChrisStryczynski, did you find a way to do that? I was looking to have two dashboard one pointing to staging prometheus, the other one pointing to production oneHoggish
P
12

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...

Pizzicato answered 3/4, 2020 at 17:39 Comment(0)
O
4

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

Ornate answered 22/9, 2023 at 21:31 Comment(1)
Very useful trick for dashboards imported manually. I believe this however will not work for provisioned dashboards say from a git repo workflow.Umbelliferous
J
2

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.

Judon answered 23/5, 2022 at 10:16 Comment(0)
H
1

You can specify data source variable for a dashboard:

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

Hoggish answered 18/3, 2019 at 11:48 Comment(1)
That documentation is rather terse - could you add an example?Glasshouse
G
0

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

Gehrke answered 29/9, 2022 at 15:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.