TDengine有 tdengine-datasource可以配合pull和grafana进行系统监控。在使用TDengine2.4以上版本时,数据显示不全,可以通过对脚本的修改来完善。
1、 tdengine-datasource安装
安装步骤参考:https://github.com/taosdata/grafanaplugin,步骤很详细,按步骤安装即可。安装后的grafana dashboard id 是15146。
在TDengine集群中,显示界面如下:
2、“No data”问题修正
可以看到有几处显示为“No data”。这时可以通过修改脚本来修正,步骤如下:
2.1、下拉"Number of MNodes",选Inspect
选Json,替换Json内容,点“Applay”确定
此处的JSON脚本为:
{
"id": 27,
"gridPos": {
"h": 3,
"w": 3,
"x": 2,
"y": 7
},
"type": "stat",
"title": "Number of MNodes",
"repeatDirection": "h",
"transformations": [
{
"id": "filterByValue",
"options": {
"filters": [
{
"config": {
"id": "greater",
"options": {
"value": 0
}
},
"fieldName": "dnodes"
}
],
"match": "any",
"type": "include"
}
},
{
"id": "reduce",
"options": {
"includeTimeField": false,
"mode": "reduceFields",
"reducers": [
"count"
]
}
},
{
"id": "filterFieldsByName",
"options": {
"include": {
"names": [
"dnodes"
]
}
}
}
],
"datasource": {
"type": "tdengine-datasource",
"uid": "lF_2I2o7k"
},
"pluginVersion": "8.3.2",
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
},
"mappings": [],
"color": {
"mode": "thresholds"
}
},
"overrides": []
},
"options": {
"reduceOptions": {
"values": true,
"calcs": [
"lastNotNull"
],
"fields": ""
},
"orientation": "auto",
"textMode": "auto",
"colorMode": "value",
"graphMode": "area",
"justifyMode": "auto",
"text": {}
},
"targets": [
{
"alias": "dnodes",
"formatType": "Time series",
"queryType": "SQL",
"refId": "A",
"sql": "show mnodes",
"target": "select metric",
"timeshift": {},
"type": "timeserie"
}
]
}
2.2、替换“Number of Databases”的JSON,内容如下
{
"id": 65,
"gridPos": {
"h": 3,
"w": 3,
"x": 9,
"y": 7
},
"type": "stat",
"title": "Number of Databases",
"repeatDirection": "h",
"transformations": [
{
"id": "reduce",
"options": {
"includeTimeField": false,
"mode": "reduceFields",
"reducers": [
"count"
]
}
},
{
"id": "filterFieldsByName",
"options": {
"include": {
"names": [
"dnodes"
]
}
}
}
],
"pluginVersion": "8.3.2",
"description": "",
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
},
"mappings": [],
"color": {
"mode": "thresholds"
}
},
"overrides": []
},
"options": {
"reduceOptions": {
"values": true,
"calcs": [
"lastNotNull"
],
"fields": ""
},
"orientation": "auto",
"textMode": "auto",
"colorMode": "value",
"graphMode": "area",
"justifyMode": "auto",
"text": {}
},
"targets": [
{
"alias": "dnodes",
"colNameFormatStr": "",
"colNameToGroup": "",
"datasource": {
"type": "tdengine-datasource",
"uid": "lF_2I2o7k"
},
"formatType": "Time series",
"queryType": "SQL",
"refId": "A",
"sql": "show databases;",
"target": "select metric",
"timeshift": {},
"type": "timeserie"
}
],
"datasource": null
}
2.3、替换“Number of Databases”的JSON,内容如下
{
"id": 55,
"gridPos": {
"h": 3,
"w": 3,
"x": 9,
"y": 10
},
"type": "stat",
"title": "Number of Connections",
"repeatDirection": "h",
"transformations": [
{
"id": "filterByValue",
"options": {
"filters": [],
"match": "all",
"type": "include"
}
},
{
"id": "reduce",
"options": {
"includeTimeField": false,
"mode": "reduceFields",
"reducers": [
"count"
]
}
},
{
"id": "filterFieldsByName",
"options": {
"include": {
"names": [
"connId"
]
}
}
}
],
"pluginVersion": "8.3.2",
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
},
"mappings": [],
"color": {
"mode": "thresholds"
}
},
"overrides": []
},
"options": {
"reduceOptions": {
"values": true,
"calcs": [
"lastNotNull"
],
"fields": ""
},
"orientation": "auto",
"textMode": "auto",
"colorMode": "value",
"graphMode": "area",
"justifyMode": "auto",
"text": {}
},
"targets": [
{
"alias": "connId",
"colNameFormatStr": "",
"colNameToGroup": "",
"datasource": {
"type": "tdengine-datasource",
"uid": "lF_2I2o7k"
},
"formatType": "Time series",
"queryType": "SQL",
"refId": "A",
"sql": "show connections",
"target": "select metric",
"timeshift": {},
"type": "timeserie"
}
],
"datasource": null
}
再次刷新,数据显示正常(参考如下),保存即可。