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
}