主题
grafana如何访问node数据
数据源不是按"Node Exporter"选择的
正确的理解:
- 数据源:选择的是 Prometheus(一个数据源)
- 查询:在Prometheus数据源中查询 Node Exporter的指标
检查步骤:
1. 确认Prometheus配置
检查 prometheus.yml 是否配置了Node Exporter:
yaml
scrape_configs:
- job_name: 'prometheus' # Prometheus自身指标
static_configs:
- targets: ['localhost:9090']
- job_name: 'node' # Node Exporter指标
static_configs:
- targets: ['localhost:9100']1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
2. 测试Node Exporter指标
在Prometheus的Graph页面测试这些查询:
# 测试Node Exporter指标
node_cpu_seconds_total
node_memory_MemTotal_bytes
up{job="node"}1
2
3
4
2
3
4
3. 正确的仪表盘配置
使用这个修正版本的仪表盘JSON:
json
{
"dashboard": {
"title": "Node Exporter System Monitor",
"panels": [
{
"id": 1,
"title": "CPU Usage %",
"type": "gauge",
"datasource": "Prometheus",
"targets": [{
"expr": "100 - (avg by (instance) (rate(node_cpu_seconds_total{job=\"node\"}[5m])) * 100)"
}],
"gridPos": {"h": 8, "w": 6, "x": 0, "y": 0}
},
{
"id": 2,
"title": "Memory Usage %",
"type": "gauge",
"datasource": "Prometheus",
"targets": [{
"expr": "(1 - (node_memory_MemAvailable_bytes{job=\"node\"} / node_memory_MemTotal_bytes{job=\"node\"})) * 100"
}],
"gridPos": {"h": 8, "w": 6, "x": 6, "y": 0}
},
{
"id": 3,
"title": "CPU Usage Over Time",
"type": "timeseries",
"datasource": "Prometheus",
"targets": [{
"expr": "100 - (avg by (mode) (rate(node_cpu_seconds_total{job=\"node\"}[5m])) * 100)"
}],
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 8}
}
]
}
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
关键修改:
- 所有查询都添加了
{job="node"}来明确指定Node Exporter的指标 - 数据源统一选择 Prometheus
验证步骤:
检查Node Exporter是否被Prometheus发现:
- 访问 Prometheus → Status → Targets
- 应该看到
nodejob的状态是 UP
测试单个查询:
- 在Prometheus的Graph页面输入:
up{job="node"} - 应该返回
1(表示正常)
- 在Prometheus的Graph页面输入:
如果还是没数据,检查:
- Node Exporter端口9100是否可访问
- Prometheus配置是否正确重启
- 防火墙是否阻止了9100端口
简单来说:你只需要一个Prometheus数据源,然后在查询中指定 {job="node"} 来获取Node Exporter的指标。