Grafana导入 json 文件的 dashboard 错误 Templating Failed to upgrade legacy queries Datasource xxx not found

Grafana导入 json 文件的 dashboard 错误 Templating Failed to upgrade legacy queries Datasource xxx not found_第1张图片

参考

Support dashboard variables in dashboard provisioning

前言

从一套环境导出 dashboard 为 json 文件,在另一套环境中导入,那么出现如标题的问题, 应该怎么解决呢?1. 闲的蛋疼的话可以一个一个慢慢编辑,选择正确得 Datasource(日后导入到其他环境依旧需要如此操作); 2. 直接编辑 json 文件(一劳永逸,环境随便换)

实操

  1. 方式1

添加一个输入参数

{
  "__inputs": [
    {
      "name": "DS_PROMETHEUS",
      "label": "prometheus",
      "description": "",
      "type": "datasource",
      "pluginId": "prometheus",
      "pluginName": "Prometheus"
    }
  ],
..................................................
        # 所有的这些
        "datasource": {
          "type": "prometheus",
          "uid": "xxxx-uid"
        },
        # 修改为
        "datasource": "${DS_PROMETHEUS}",
}
  1. 方式2

硬编码

{
  ...........................
        # 所有的这些
        "datasource": {
          "type": "prometheus",
          "uid": "xxxx-uid"
        },
        # 修改为
        # 所有的这些
        "datasource": {
          "type": "prometheus",
          "uid": "prometheus"
        },
  ...........................
}
  1. 方式3

添加一个变量

{
  .................
  # 找到 templating.list, 添加一个变量,这里的变量名为 DS_PROMETHEUS,值为 prometheus
  "templating": {
    "list": [
      {
        "datasource": "Prometheus",
        "description": null,
        "error": null,
        "hide": 0,
        "includeAll": false,
        "label": "datasource",
        "multi": false,
        "name": "DS_PROMETHEUS",
        "options": [],
        "query": "prometheus",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "type": "datasource"
      },
...
        # 所有的这些
        "datasource": {
          "type": "prometheus",
          "uid": "xxxx-uid"
        },
        # 修改为
        # 所有的这些
        "datasource": {
          "type": "prometheus",
          "uid": "${DS_PROMETHEUS}"
        },
}

你可能感兴趣的:(kubernetes,Prometheus,json,kubernetes,docker,devops,容器)