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

相关推荐
螺蛳粉 螺蛳粉6 分钟前
第一篇:Keepalived 高可用实战:VIP 漂移与 Nginx 主备切换完整指南
运维·nginx·负载均衡·keepalived·高可用
荣合技术服务9 分钟前
VMware ESXi 虚拟化平台服务器虚拟机数据恢复服务
linux·运维·服务器
杭州领祺科技12 分钟前
保信子站深度解析:继电保护信息采集与故障诊断的关键枢纽
linux·服务器·网络·新能源·储能·虚拟电厂
xh didida15 分钟前
Linux -- 进程概念
linux·服务器·开发语言·c++
爱吃香菜的初学者15 分钟前
十三.Linux——信号量
linux·运维·服务器·开发语言
吴声子夜歌24 分钟前
Nginx应用与运维——Nginx在Kubernetes中的应用(三)
运维·nginx·kubernetes
小小龙学IT30 分钟前
ROS2 安装完全指南(Ubuntu 版):从零开始到跑通第一个节点本文
linux·运维·ubuntu
Ruiery31 分钟前
Linux 6.6内核 CPU 深度解析(十二):SMT 进阶 — core scheduling 与共享算力的负载平衡
linux·运维·服务器
影视飓风TIM33 分钟前
Linux 进程虚拟地址空间详解
linux·算法
硅基手札43 分钟前
【Linux内核专栏 12】VFS 与文件系统
linux