grafana 使用下拉框

1、配置数据源
在这里插入图片描述

2、新建仪表盘
在这里插入图片描述

在这里插入图片描述
3、编写SQL
在这里插入图片描述

SELECT
   $__timeGroupAlias(dc_time,$__interval),
  h_data as '溼度'
FROM ht_data
WHERE
  $__timeFilter(dc_time)
and ht_b_num = SUBSTRING_INDEX(SUBSTRING_INDEX('$ht_sn', ')', 1), '(', -1)
ORDER BY dc_time
SELECT
   $__timeGroupAlias(dc_time,$__interval),
  t_data as '溫度'
FROM ht_data
WHERE
  $__timeFilter(dc_time)
and ht_b_num = SUBSTRING_INDEX(SUBSTRING_INDEX('$ht_sn', ')', 1), '(', -1) 
ORDER BY dc_time

4、添加下拉框
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

grafana支持JSON导入仪表盘

{
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "-- Grafana --",
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "editable": true,
  "gnetId": null,
  "graphTooltip": 0,
  "id": 12,
  "iteration": 1689911241546,
  "links": [],
  "panels": [
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": "MySQL-HT",
      "description": "",
      "fieldConfig": {
        "defaults": {
          "custom": {}
        },
        "overrides": []
      },
      "fill": 1,
      "fillGradient": 0,
      "gridPos": {
        "h": 14,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "hiddenSeries": false,
      "id": 2,
      "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": [
        {
          "alias": "溫度",
          "yaxis": 2
        }
      ],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "format": "time_series",
          "group": [
            {
              "params": [
                "ht_b_num"
              ],
              "type": "column"
            }
          ],
          "metricColumn": "none",
          "rawQuery": true,
          "rawSql": "SELECT\n   $__timeGroupAlias(dc_time,$__interval),\n  h_data as '溼度'\nFROM ht_data\nWHERE\n  $__timeFilter(dc_time)\nand ht_b_num = SUBSTRING_INDEX(SUBSTRING_INDEX('$ht_sn', ')', 1), '(', -1)\nORDER BY dc_time",
          "refId": "A",
          "select": [
            [
              {
                "params": [
                  "h_data"
                ],
                "type": "column"
              },
              {
                "params": [
                  "avg"
                ],
                "type": "aggregate"
              },
              {
                "params": [
                  "h_data"
                ],
                "type": "alias"
              }
            ]
          ],
          "table": "ht_data",
          "timeColumn": "dc_time",
          "timeColumnType": "datetime",
          "where": [
            {
              "name": "$__timeFilter",
              "params": [],
              "type": "macro"
            }
          ]
        },
        {
          "format": "time_series",
          "group": [],
          "metricColumn": "none",
          "rawQuery": true,
          "rawSql": "SELECT\n   $__timeGroupAlias(dc_time,$__interval),\n  t_data as '溫度'\nFROM ht_data\nWHERE\n  $__timeFilter(dc_time)\nand ht_b_num = SUBSTRING_INDEX(SUBSTRING_INDEX('$ht_sn', ')', 1), '(', -1) \nORDER BY dc_time",
          "refId": "B",
          "select": [
            [
              {
                "params": [
                  "oven_use_id"
                ],
                "type": "column"
              }
            ]
          ],
          "table": "alarm",
          "timeColumn": "alarm_time",
          "timeColumnType": "timestamp",
          "where": [
            {
              "name": "$__timeFilter",
              "params": [],
              "type": "macro"
            }
          ]
        }
      ],
      "thresholds": [
        {
          "colorMode": "critical",
          "fill": true,
          "line": true,
          "op": "gt",
          "value": null,
          "yaxis": "left"
        }
      ],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "$ht_sn車間溫溼度變化曲線",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "format": "humidity",
          "label": "溼度",
          "logBase": 1,
          "max": "100",
          "min": "0",
          "show": true
        },
        {
          "format": "celsius",
          "label": "溫度",
          "logBase": 1,
          "max": "100",
          "min": "0",
          "show": true
        }
      ],
      "yaxis": {
        "align": false,
        "alignLevel": null
      }
    }
  ],
  "refresh": "5m",
  "schemaVersion": 25,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": [
      {
        "allValue": null,
        "current": {
          "selected": false,
          "text": "品保(QC)",
          "value": "品保(QC)"
        },
        "datasource": "MySQL-HT",
        "definition": "select DISTINCT(CONCAT(area_code,'(',department,')'))  from  ht_device_set_new WHERE department IS NOT NULL AND department!=''",
        "hide": 0,
        "includeAll": false,
        "label": "線別",
        "multi": false,
        "name": "ht_department",
        "options": [],
        "query": "select DISTINCT(CONCAT(area_code,'(',department,')'))  from  ht_device_set_new WHERE department IS NOT NULL AND department!=''",
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      },
      {
        "allValue": null,
        "current": {
          "selected": false,
          "text": "新廠一樓IQC檢驗區(HT088)",
          "value": "新廠一樓IQC檢驗區(HT088)"
        },
        "datasource": "MySQL-HT",
        "definition": "select DISTINCT(CONCAT(area_note,'(',ht_b_num,')')) from  ht_device_set_new where  status='normal' and department= SUBSTRING_INDEX(SUBSTRING_INDEX('$ht_department', ')', 1), '(', -1)\n\n    ",
        "hide": 0,
        "includeAll": false,
        "label": "溫溼度採集模塊編號",
        "multi": false,
        "name": "ht_sn",
        "options": [],
        "query": "select DISTINCT(CONCAT(area_note,'(',ht_b_num,')')) from  ht_device_set_new where  status='normal' and department= SUBSTRING_INDEX(SUBSTRING_INDEX('$ht_department', ')', 1), '(', -1)\n\n    ",
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 3,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      }
    ]
  },
  "time": {
    "from": "now-6h",
    "to": "now"
  },
  "timepicker": {
    "refresh_intervals": [
      "10s",
      "30s",
      "1m",
      "5m",
      "15m",
      "30m",
      "1h",
      "2h",
      "1d"
    ]
  },
  "timezone": "",
  "title": "全廠溫溼度查詢",
  "uid": "oONwp-GMz",
  "version": 31
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值