深色模式
node_exporter 采集主机指标
几乎所有主机监控的第一步:装一个 node_exporter,把机器指标变成
/metrics接口。
适用环境
- Linux 服务器(物理机 / 虚拟机均可)
- 已运行 Prometheus 并能热加载配置
bash
# 查看系统版本,选择对应架构的包
cat /etc/os-release | grep -E '^(ID|VERSION_ID)='1
2
2
操作步骤
1. 下载并安装
bash
VERSION=v1.8.0
cd /opt
wget https://github.com/prometheus/node_exporter/releases/download/${VERSION}/node_exporter-${VERSION}.linux-amd64.tar.gz
tar xf node_exporter-${VERSION}.linux-amd64.tar.gz
cp node_exporter-${VERSION}.linux-amd64/node_exporter /usr/local/bin/1
2
3
4
5
2
3
4
5
2. 配置 systemd
bash
useradd -rs /sbin/nologin node_exporter
cat > /etc/systemd/system/node_exporter.service <<'EOF'
[Unit]
Description=node_exporter
After=network.target
[Service]
User=node_exporter
ExecStart=/usr/local/bin/node_exporter
Restart=always
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload && systemctl enable --now node_exporter1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
3. 在 Prometheus 加入抓取
yaml
- job_name: node
static_configs:
- targets: ['localhost:9100']1
2
3
2
3
bash
curl -X POST http://localhost:9090/-/reload1
验证
bash
# 直接看原始指标
curl -s http://localhost:9100/metrics | grep '^node_cpu_seconds_total' | head1
2
2
常见坑
暴露面风险
node_exporter 默认不鉴权,不要直接暴露到公网,用防火墙或反向代理限制来源。
不要 --collector.* 全开
collectors 全开会拖慢抓取并膨胀时序,只开需要的(如 systemd、diskstats)。