Docker监控系统中添加NodeExporter

目录

注意

[修改 docker-compose.yml,增加 Node Exporter](#修改 docker-compose.yml,增加 Node Exporter)

[修改 Prometheus 配置文件,添加 Node Exporter 目标](#修改 Prometheus 配置文件,添加 Node Exporter 目标)

[启动 Node Exporter 并刷新 Prometheus 配置](#启动 Node Exporter 并刷新 Prometheus 配置)

验证


注意

localhost是本机的ip地址,需要修改

修改 docker-compose.yml,增加 Node Exporter

在 /opt/monitor/docker-compose.yml 文件中,增加一个服务 node-exporter:

复制代码
version: '3.9'
services:
  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    volumes:
      - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
    ports:
      - "9090:9090"
    restart: always

  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    ports:
      - "3000:3000"
    environment:
      - GF_SECURITY_ADMIN_USER=admin
      - GF_SECURITY_ADMIN_PASSWORD=admin
    restart: always

  node-exporter:
    image: prom/node-exporter:latest
    container_name: node-exporter
    network_mode: "host"       # 让 Node Exporter 能直接访问宿主机指标
    pid: "host"                # 允许访问宿主机进程信息
    restart: always

说明:

  • network_mode: "host" 是 Node Exporter 的推荐配置,可以直接采集宿主机指标。

  • 不需要端口映射,因为 Prometheus 会直接抓 9100 端口。

修改 Prometheus 配置文件,添加 Node Exporter 目标

编辑 /opt/monitor/prometheus/prometheus.yml,增加 node-exporter scrape 配置:

复制代码
global:
  scrape_interval: 5s

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'node-exporter'
    static_configs:
      - targets: ['localhost:9100']

启动 Node Exporter 并刷新 Prometheus 配置

复制代码
cd /opt/monitor

# 重新启动容器
docker compose down
docker compose up -d

或者只重启 Prometheus 和 Node Exporter:

复制代码
docker compose up -d prometheus node-exporter

验证

  1. Prometheus 页面访问:http://localhost:9090

    Status → Targets 中,你应该看到:

Grafana 页面访问:http://localhost:3000

登录账号:admin / admin

可以导入官方 Node Exporter dashboard(Dashboard ID: 1860),直接显示主机 CPU/内存/磁盘/网络图表。

相关推荐
酷道1 天前
CentOS 7 安装 Docker
linux·docker·centos
Python-AI Xenon1 天前
双网卡双网关服务器策略路由配置与持久化完全指南
linux·运维·计算机网络·网络故障排查
最后一个bug1 天前
ubuntu24.04在docker下迁移gitlab16
linux·运维·docker
yyyyy_abc1 天前
负载均衡与高可用
运维·负载均衡
遇印记1 天前
软考知识点(windows系统管理与命令)
运维·服务器·网络·windows·ddos
风曦Kisaki1 天前
# Linux运维Day03:Nginx 反向代理(服务集群)、负载均衡、四层调度与优化
linux·运维·nginx
木雷坞1 天前
csdn-enterpriseGitLab Runner docker pull 慢:并行流水线镜像拉取排查
运维·docker·容器·gitlab
十子木1 天前
git 如何恢复特定版本的内容
linux·git
雪度娃娃1 天前
Asio异步读写——简单服务器和客户端异步通信
运维·服务器·网络·c++·php
2601_953660371 天前
File类
linux·开发语言·python