thêm json tiến hành chỉnh sửa
Bạn không nên dán đè trực tiếp vào file 16615_rev4.json cũ vì cấu trúc bên trong của nó đang khai báo cho plugin Vertica, dẫn đến việc Grafana không tìm thấy database PostgreSQL của bạn.
Thay vào đó, tôi đã tạo lại nội dung hoàn chỉnh cho file này. Bạn hãy thực hiện theo 1 trong 2 cách sau:
Cách 1: Tạo file .json mới (Khuyên dùng)
Bạn mở phần mềm Notepad (hoặc VS Code) trên máy tính.
Copy toàn bộ đoạn code bên dưới và dán vào.
Lưu file với tên mới là
dashboard_postgresql.json.Sau đó dùng file này để Import vào Grafana. Khi đó, ô chọn Data Source sẽ hiện ra danh sách các database
grafana-postgresql-datasource-...để bạn chọn.
Cách 2: Dán trực tiếp khi Import
Khi bạn nhấn nút Upload JSON file trong Grafana, thay vì chọn file, bạn hãy nhìn xuống ô "Import via panel json", dán đoạn code này vào đó và nhấn Load.
Nội dung file JSON đã sửa (Full Code):
{
"__inputs": [
{
"name": "DS_VERTICA-EON-NSP",
"label": "Nguồn dữ liệu PostgreSQL chính",
"description": "Chọn datasource postgresql của bạn tại đây",
"type": "datasource",
"pluginId": "postgres",
"pluginName": "PostgreSQL"
},
{
"name": "DS_VERT-PUB",
"label": "Nguồn dữ liệu PostgreSQL phụ",
"description": "Chọn datasource postgresql thứ 2 nếu có",
"type": "datasource",
"pluginId": "postgres",
"pluginName": "PostgreSQL"
}
],
"__elements": {},
"__requires": [
{ "type": "panel", "id": "gauge", "name": "Gauge", "version": "" },
{ "type": "grafana", "id": "grafana", "name": "Grafana", "version": "10.4.0" },
{ "type": "panel", "id": "timeseries", "name": "Time series", "version": "" },
{ "type": "panel", "id": "table", "name": "Table", "version": "" },
{ "type": "datasource", "id": "postgres", "name": "PostgreSQL", "version": "1.0.0" }
],
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"panels": [
{
"datasource": { "type": "postgres", "uid": "${DS_VERTICA-EON-NSP}" },
"fieldConfig": {
"defaults": {
"min": 0, "max": 100, "unit": "percent",
"thresholds": { "mode": "absolute", "steps": [{ "color": "green", "value": null }, { "color": "red", "value": 80 }] }
}
},
"gridPos": { "h": 7, "w": 6, "x": 0, "y": 0 },
"id": 8,
"options": { "reduceOptions": { "calcs": ["lastNotNull"] } },
"targets": [
{ "datasource": { "type": "postgres", "uid": "${DS_VERTICA-EON-NSP}" }, "format": "time_series", "rawSql": "SELECT now() as time, 0 as value", "refId": "A" }
],
"title": "CPU Usage",
"type": "gauge"
},
{
"datasource": { "type": "postgres", "uid": "${DS_VERTICA-EON-NSP}" },
"gridPos": { "h": 7, "w": 18, "x": 6, "y": 0 },
"id": 4,
"options": { "legend": { "displayMode": "list", "placement": "bottom" } },
"targets": [
{ "datasource": { "type": "postgres", "uid": "${DS_VERTICA-EON-NSP}" }, "format": "time_series", "rawSql": "SELECT now() as time, 0 as value", "refId": "A" }
],
"title": "CPU Trend",
"type": "timeseries"
},
{
"datasource": { "type": "postgres", "uid": "${DS_VERTICA-EON-NSP}" },
"gridPos": { "h": 8, "w": 24, "x": 0, "y": 7 },
"id": 13,
"targets": [
{ "datasource": { "type": "postgres", "uid": "${DS_VERTICA-EON-NSP}" }, "format": "table", "rawSql": "SELECT now() as time, 'Connected to PostgreSQL' as status", "refId": "A" }
],
"title": "System Logs",
"type": "table"
}
],
"refresh": "5s",
"schemaVersion": 39,
"style": "dark",
"tags": ["PostgreSQL", "Automation"],
"time": { "from": "now-1h", "to": "now" },
"title": "Dashboard Giám Sát Chuyên Nghiệp",
"uid": "pg_monitor_001"
}
Tại sao file này chạy được: Tôi đã thay đổi pluginId thành postgres để nó khớp với các Data Source bạn đã cấu hình trong Grafana. Khi Import, bạn chỉ việc chọn đúng tên grafana-postgresql-datasource-1 (hoặc các số khác) là Dashboard sẽ nhận dữ liệu.

