Windows 启动 Prometheus 并且监控本地cpu等资源的完整保姆级步骤!!!
2026/8/24 19:47:24 网站建设 项目流程

Windows 启动 Prometheus 完整步骤

前提:已经解压好 prometheus‑3.13.0‑windows‑amd64.zip,不要放在中文路径! ❌错误:D:\软件\普罗米修斯✅正确:D:\dev\prometheus

1. 目录结构

D:\dev\prometheus ├─ prometheus.exe #主程序 ├─ prometheus.yml #配置文件(重点) └─ data #数据目录(首次运行会自动生成)

2. 修改配置 prometheus.yml

把下面 job 加到scrape_configs:下面,用来抓取本机 node‑exporter(你后面要启动 node‑exporter)

scrape_configs: - job_name: "prometheus" static_configs: - targets: ["localhost:9090"] - job_name: 'windows-local' static_configs: - targets: ['127.0.0.1:9100']

保存文件。

⚠️注意:yaml 缩进必须用空格,不能用 Tab,否则启动直接报错。

3. 两种启动方式

方式 A:cmd 命令行启动(推荐,能看到日志报错)

  1. 打开 cmd,cd 进入 prometheus 解压目录
D: cd D:\dev\prometheus
  1. 执行启动命令
.\prometheus.exe --config.file=prometheus.yml

看到日志输出server is ready to receive web requests代表启动成功。

不要关闭这个 cmd 黑窗口!关闭就停止服务。

方式 B:直接双击 prometheus.exe

双击 exe 也可以跑,但报错一闪而过,出问题看不到日志,调试阶段不建议双击

4. 访问 web 界面

浏览器打开:

http://127.0.0.1:9090

能打开 Prometheus 网页控制台 = 启动成功。

Windows 正确:windows_exporter

  • Linux:node_exporter,端口 9100
  • Windows:windows_exporter,端口9182(不是 9100)

1. 下载

github releases 地址: https://github.com/prometheus-community/windows_exporter/releases

下载windows_exporter‑0.30.x‑amd64.msi(msi 安装包,amd64,普通 Windows 电脑都是这个)。

2. 安装

双击 msi,一路下一步,它会自动安装成 Windows 系统服务,开机自启。 安装完自动监听:127.0.0.1:9182

浏览器访问:

http://127.0.0.1:9182/metrics

页面出现一大串指标文本,代表采集 CPU、内存、磁盘成功。

3. 修改 prometheus.yml(端口改成 9182!!)

把之前写的 9100 改掉,替换成 9182:

scrape_configs: - job_name: "prometheus" static_configs: - targets: ["localhost:9090"] - job_name: 'windows-local' static_configs: - targets: ['127.0.0.1:9182']

⚠️yaml 必须空格缩进,禁止 tab。

这是修改部分

# 新增:本机Windows系统监控任务(重点新增这段) - job_name: "local-windows-host" static_configs: - targets: ["127.0.0.1:9182"] labels: instance: "本机电脑"

重启 prometheus.exe。打开http://127.0.0.1:9090

查询语句(windows 专用)

#CPU使用率 100 - (avg by(instance) (irate(windows_cpu_time_total{mode="idle"}[1m])) * 100) #内存使用率 100 - (windows_memory_available_bytes / windows_memory_total_bytes *100)

快速核对清单

  1. ✅prometheus:端口 9090,prometheus‑3.13.x‑windows‑amd64
  2. ✅windows_exporter:端口 9182,msi 安装,系统服务自动跑
  3. ✅prometheus.yml target 写127.0.0.1:9182

查看本机 CPU、内存等资源指标,跟着操作就行

一、先确认采集状态(前置检查)
  1. 打开 Prometheus 页面顶部菜单栏:StatusTargets
  2. 查看local-windows-host条目状态:
    • 显示UP:采集正常,可以查指标;
    • 显示DOWN:检查 windows_exporter 服务是否运行、9182 端口能否访问、yml 配置 target 地址是否正确。
二、在 Prometheus 查询框输入语句查看对应资源

回到首页主查询输入框,分别粘贴下面语句,点击「Execute」执行即可出数据:

1. 本机 CPU 使用率(最常用)
100 - (avg by (instance) (irate(windows_cpu_time_total{mode="idle"}[1m])) * 100)
2. 内存使用率
100 - (windows_memory_available_bytes / windows_memory_total_bytes * 100)
3. 磁盘 C 盘使用率
100 - (windows_logical_disk_free_bytes{volume="C:"} / windows_logical_disk_size_bytes{volume="C:"} * 100)
4. 整机网络接收速率
irate(windows_net_bytes_received_total[1m])
三、界面基础操作说明
  1. 执行后默认是表格列表视图,切换上方「Graph」标签,就能看到资源随时间变化的折线曲线图;
  2. 右上角时间范围可以调整:比如选1h查看近 1 小时资源波动趋势。
四、进阶可视化(可选,更直观看大盘面板)

单纯 Prometheus 原生查询只有基础图表,日常看监控大盘搭配Grafana更方便:

  1. 下载安装 Grafana 并启动;
  2. 数据源添加你的本地 Prometheus 地址http://127.0.0.1:9090
  3. 导入 Windows 监控通用模板(模板 ID:10467),一键生成 CPU、内存、磁盘、网络完整监控仪表盘。
常见排查小问题
  1. 执行语句无数据:确认 Targets 里任务状态为 UP,windows_exporter 的 9182 端口能正常访问;
  2. 指标名称找不到:语句适配 windows_exporter 专属指标,不要套用 Linux node_exporter 的查询语句。

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询