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/内存/磁盘/网络图表。

相关推荐
getapi14 分钟前
注塑件的费用构成
linux·服务器·ubuntu
鸽芷咕30 分钟前
DrissionPage 成 CANN 仓库爆款自动化工具:背后原因何在?
运维·python·自动化·cann
池央38 分钟前
CANN 算子生态的深度演进:稀疏计算支持与 PyPTO 范式的抽象层级
运维·人工智能·信号处理
郝学胜-神的一滴44 分钟前
深入解析C/S模型下的TCP通信流程:从握手到挥手的技术之旅
linux·服务器·c语言·网络·网络协议·tcp/ip
OJAC1111 小时前
当所有人都在说“运维稳了”,近屿智能看到了另一种可能
运维
释怀不想释怀1 小时前
Linux网络基础(ip,域名)
linux·网络·tcp/ip
初願致夕霞1 小时前
Linux_进程
linux·c++
人鱼传说1 小时前
docker desktop是一个好东西
运维·docker·容器
开开心心就好1 小时前
AI人声伴奏分离工具,离线提取伴奏K歌用
java·linux·开发语言·网络·人工智能·电脑·blender
lucky-billy1 小时前
Ubuntu 下一键部署 ROS2
linux·ubuntu·ros2