当前位置: 首页 > ai >正文

@Prometheus 监控操作系统-Exporter(Win Linux)

文章目录

  • Prometheus 监控操作系统(Win&Linux)-Exporter
    • 1. 概述
    • 2. Linux 系统监控 (Node Exporter)
      • 2.1 下载 Node Exporter
      • 2.2 创建 Systemd 服务
      • 2.3 启动服务
      • 2.4 验证安装
    • 3. Windows 系统监控 (Windows Exporter)
      • 3.1 下载 Windows Exporter
      • 3.2 安装选项
      • 3.3 验证安装
      • 3.4 防火墙配置
    • 4. Prometheus 服务器配置
      • 4.1 添加 Linux 节点
      • 4.2 添加 Windows 节点
      • 4.3 重载配置
    • 5. 验证监控数据
    • 6. 可选:配置 TLS 和认证
      • 6.1 Linux Node Exporter
      • 6.2 Windows Exporter
    • 7. 故障排除
      • 7.1 Linux 常见问题
      • 7.2 Windows 常见问题
    • 8. 维护与升级
      • 8.1 Linux Node Exporter
      • 8.2 Windows Exporter

Prometheus 监控操作系统(Win&Linux)-Exporter

1. 概述

本文档提供了在 Windows 和 Linux 操作系统上安装 Prometheus exporter 的详细步骤,用于监控系统指标。

2. Linux 系统监控 (Node Exporter)

2.1 下载 Node Exporter

# 创建专用用户
sudo useradd --no-create-home --shell /bin/false node_exporter# 下载最新版 Node Exporter
wget https://github.com/prometheus/node_exporter/releases/download/v1.6.1/node_exporter-1.6.1.linux-amd64.tar.gz# 解压
tar xvf node_exporter-1.6.1.linux-amd64.tar.gz# 移动二进制文件到系统目录
sudo mv node_exporter-1.6.1.linux-amd64/node_exporter /usr/local/bin/# 设置权限
sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter# 清理
rm -rf node_exporter-1.6.1.linux-amd64*

2.2 创建 Systemd 服务

创建服务文件 /etc/systemd/system/node_exporter.service

[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter[Install]
WantedBy=multi-user.target

2.3 启动服务

sudo systemctl daemon-reload
sudo systemctl start node_exporter
sudo systemctl enable node_exporter

2.4 验证安装

curl http://localhost:9100/metrics

3. Windows 系统监控 (Windows Exporter)

3.1 下载 Windows Exporter

  1. 访问 Windows Exporter 发布页面
  2. 下载最新 .msi 安装包 (如 windows_exporter-0.24.0-amd64.msi)

3.2 安装选项

运行 MSI 安装包时可以使用以下参数(通过命令行或安装界面):

# 基本安装
msiexec /i windows_exporter-0.24.0-amd64.msi# 自定义监听端口
msiexec /i windows_exporter-0.24.0-amd64.msi LISTEN_PORT=5000# 启用特定收集器
msiexec /i windows_exporter-0.24.0-amd64.msi ENABLED_COLLECTORS="cpu,memory,os,disk,net,service"

常用收集器列表:

  • cpu
  • memory
  • os
  • disk
  • net
  • service
  • process
  • iis (如需监控IIS)

3.3 验证安装

  1. 服务应自动启动
  2. 打开浏览器访问 http://localhost:9182/metrics (默认端口9182)

3.4 防火墙配置

如需远程访问,需开放防火墙端口:

New-NetFirewallRule -Name "Windows Exporter" -DisplayName "Windows Exporter (Prometheus)" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 9182

4. Prometheus 服务器配置

4.1 添加 Linux 节点

编辑 Prometheus 配置文件 prometheus.yml

scrape_configs:- job_name: 'node_linux'static_configs:- targets: ['linux-server-ip:9100']

4.2 添加 Windows 节点

  - job_name: 'node_windows'static_configs:- targets: ['windows-server-ip:9182']

4.3 重载配置

# 发送 SIGHUP 信号
kill -HUP $(pidof prometheus)# 或使用 systemd
sudo systemctl reload prometheus

5. 验证监控数据

  1. 访问 Prometheus Web UI (http://prometheus-server:9090)
  2. 执行查询如 node_cpu_seconds_totalwindows_cpu_time_total 验证数据

6. 可选:配置 TLS 和认证

6.1 Linux Node Exporter

# 生成证书
openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 \-keyout node_exporter.key -out node_exporter.crt \-subj "/CN=node_exporter" -addext "subjectAltName = IP:127.0.0.1"# 修改服务文件
ExecStart=/usr/local/bin/node_exporter --web.config.file=/etc/node_exporter/web.yml

创建 /etc/node_exporter/web.yml

tls_server_config:cert_file: node_exporter.crtkey_file: node_exporter.key
basic_auth_users:prometheus: $2y$05$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

6.2 Windows Exporter

Windows Exporter 不支持原生 TLS,建议通过反向代理或网络隔离保护。

7. 故障排除

7.1 Linux 常见问题

  • 端口被占用:检查是否有其他服务使用9100端口 netstat -tulnp | grep 9100
  • 权限问题:确保 node_exporter 用户有足够权限
  • SELinux 阻止:临时禁用 setenforce 0 或配置适当策略

7.2 Windows 常见问题

  • 服务未启动:检查服务状态 Get-Service windows_exporter
  • 防火墙阻止:验证防火墙规则
  • 指标不全:检查启用的收集器,确保所需收集器已启用

8. 维护与升级

8.1 Linux Node Exporter

# 停止服务
sudo systemctl stop node_exporter# 备份旧版本
sudo cp /usr/local/bin/node_exporter /usr/local/bin/node_exporter.bak# 下载并安装新版本
# ...重复安装步骤...# 重启服务
sudo systemctl start node_exporter

8.2 Windows Exporter

  1. 通过控制面板卸载旧版本
  2. 安装新版本 MSI 包
  3. 服务将自动重启

此 SOP 提供了 Prometheus 监控 Windows 和 Linux 操作系统的基本安装配置步骤,可根据实际环境需求进行调整。

http://www.xdnf.cn/news/10089.html

相关文章:

  • mysql数据库基础命令总结常用10个
  • 需求可测试性评价
  • selenium自动化浏览器
  • c++流之sstream/堆or优先队列的应用[1]
  • 智橙PLM与MES系统集成项目执行记录 智渤慧晟机械装备技术服务部 24.08
  • 大模型-attention汇总解析之-GQA
  • Python爬虫实战:研究Goutte库相关技术
  • Haproxy
  • 白皮精读:214页数据安全治理白皮书6.0【附全文阅读】
  • 超级对话3:大跨界且大综合的学问融智学应用场景述评(不同第三方的回应)之三
  • 低碳理念在道路工程中的应用-预制路面
  • P23:实现天气预测
  • 宽带不给公网IP?本地内网的网络服务怎么让外网访问?
  • [python] 最大公约数 和 最小公倍数
  • PostgreSQL日常运维
  • Linux | Shell脚本的常用命令
  • 计算机一次取数过程分析
  • AAAI 2025论文分享│STD-PLM:基于预训练语言模型的时空数据预测与补全方法
  • 八N皇后问题
  • 抗辐照加固CANFD芯片:以车规级设计提升商业航天系统可靠性
  • HCIP:MPLS静态LSP的配置及抓包
  • @Docker Compose部署Alertmanager
  • 基于Python的单斜式ADC建模与仿真分析
  • nginx日志分析笔记
  • 每日一题:H指数
  • Vue 3前沿生态整合:WebAssembly与TypeScript深度实践
  • systemctl实现定时任务(比crontab好用)
  • Python中的变量、赋值及函数的参数传递概要
  • ch12 课堂参考代码 及 题目参考思路
  • E. Melody 【CF1026 (Div. 2)】 (求欧拉路径之Hierholzer算法)