根据变量选择配置Grafana仪表板

时间:2020-05-14 10:55:15

标签: variables grafana dashboard

我正在使用grafana绘制来自不同装置的数据。每个安装包含多个设备,每个设备都有一个设备ID(设备ID用于从数据库中获取相关数据)。

当前,我正在为每次安装创建一个新的仪表板,并手动设置每个设备ID的查询,即使所有这些仪表板都是相同的,唯一的不同是设备ID。

我想要一个安装名称列表(我可以在grafana中将其创建为客户变量),以便选择安装时,仪表板将更新为使用此安装中包含的设备ID。 / p>

任何人知道grafana是否可以支持它吗?以及如何?

在仪表板中使用的一个查询片段下面,我只想定义一个安装名称,因此,如果在其中选择一个值,则下面的“ dev0000001”值将替换为与选择的安装。

{
  "aliasColors": {},
  "bars": false,
  "dashLength": 10,
  "dashes": false,
  "datasource": "db0000001",
  "fill": 1,
  "fillGradient": 0,
  "gridPos": {
    "h": 8,
    "w": 24,
    "x": 0,
    "y": 8
  },
  "id": 4,
  "legend": {
    "avg": false,
    "current": false,
    "max": false,
    "min": false,
    "show": true,
    "total": false,
    "values": false
  },
  "lines": true,
  "linewidth": 1,
  "nullPointMode": "null",
  "options": {
    "dataLinks": []
  },
  "percentage": false,
  "pointradius": 2,
  "points": false,
  "renderer": "flot",
  "seriesOverrides": [],
  "spaceLength": 10,
  "stack": false,
  "steppedLine": false,
  "targets": [
    {
      "format": "time_series",
      "group": [],
      "metricColumn": "none",
      "rawQuery": false,
      "rawSql": "SELECT\n  $__time(time_column),\n  value1\nFROM\n  metric_table\nWHERE\n  $__timeFilter(time_column)\n",
      "refId": "A",
      "select": [
        [
          {
            "params": [
              "value"
            ],
            "type": "column"
          },
          {
            "params": [
              "Actual Temp"
            ],
            "type": "alias"
          }
        ]
      ],
      "table": "rawvalues",
      "timeColumn": "\"time\"",
      "timeColumnType": "timestamp",
      "where": [
        {
          "name": "$__timeFilter",
          "params": [],
          "type": "macro"
        },
        {
          "datatype": "text",
          "name": "",
          "params": [
            "value_name",
            "=",
            "'actual_temp'"
          ],
          "type": "expression"
        },
        {
          "datatype": "varchar",
          "name": "",
          "params": [
            "device_id",
            "=",
            "'dev0000001'"
          ],
          "type": "expression"
        }
      ]
    }
  ],
  "thresholds": [],
  "timeFrom": null,
  "timeRegions": [],
  "timeShift": null,
  "title": "Panel Title",
  "tooltip": {
    "shared": true,
    "sort": 0,
    "value_type": "individual"
  },
  "type": "graph",
  "xaxis": {
    "buckets": null,
    "mode": "time",
    "name": null,
    "show": true,
    "values": []
  },
  "yaxes": [
    {
      "format": "short",
      "label": null,
      "logBase": 1,
      "max": null,
      "min": null,
      "show": true
    },
    {
      "format": "short",
      "label": null,
      "logBase": 1,
      "max": null,
      "min": null,
      "show": true
    }
  ],
  "yaxis": {
    "align": false,
    "alignLevel": null
  }
}

0 个答案:

没有答案