一文掌握GitHub热门开源项目Prometheus(Windows 10版)

云信安装大师
90
AI 质量分
10 5 月, 2025
2 分钟阅读
0 阅读

一文掌握GitHub热门开源项目Prometheus(Windows 10版)

引言

Prometheus是一款开源的系统监控和警报工具包,最初由SoundCloud开发,现已成为云原生计算基金会(CNCF)的毕业项目。本文将手把手教你如何在Windows 10系统上安装和配置Prometheus,并创建一个简单的监控示例。

准备工作

在开始之前,请确保你的Windows 10系统满足以下要求:
– Windows 10(64位)版本1809或更高
– 至少4GB内存
– 2GB可用磁盘空间
– PowerShell 5.1或更高版本

第一步:下载Prometheus

  1. 访问Prometheus官方GitHub发布页面:
    https://github.com/prometheus/prometheus/releases

  2. 找到最新的稳定版本(本文以v2.40.5为例),下载Windows版本的压缩包:
    prometheus-2.40.5.windows-amd64.zip

  3. 使用PowerShell下载(可选):

    代码片段
    Invoke-WebRequest -Uri "https://github.com/prometheus/prometheus/releases/download/v2.40.5/prometheus-2.40.5.windows-amd64.zip" -OutFile "prometheus-2.40.5.windows-amd64.zip"
    

第二步:安装Prometheus

  1. 解压下载的zip文件到你想安装的目录,例如C:\Prometheus

    代码片段
    Expand-Archive -Path "prometheus-2.40.5.windows-amd64.zip" -DestinationPath "C:\Prometheus"
    
  2. 进入解压后的目录:

    代码片段
    cd C:\Prometheus\prometheus-2.40.5.windows-amd64
    
  3. 查看目录结构:

    代码片段
    ├── prometheus.exe        # Prometheus主程序
    ├── promtool.exe          # Prometheus工具
    ├── prometheus.yml        # 默认配置文件
    └── console_libraries/    # Web控制台模板库
        └── consoles/         # Web控制台模板
    

第三步:配置Prometheus

  1. Prometheus的主配置文件是prometheus.yml。用文本编辑器打开它:
代码片段
# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every15 seconds.

# A scrape configuration containing exactly one endpoint to scrape:
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']
  1. (可选)添加Windows Exporter监控目标(需要先安装Windows Exporter):
代码片段
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'windows'
    static_configs:
      - targets: ['localhost:9182']

第四步:运行Prometheus

  1. 在PowerShell中启动Prometheus:
代码片段
.\prometheus.exe --config.file=prometheus.yml
  1. Prometheus默认会监听9090端口。打开浏览器访问:
代码片段
http://localhost:9090
  1. (可选)将Prometheus安装为Windows服务(需要管理员权限):
代码片段
# 创建服务(注意路径可能需要调整)
New-Service -Name "Prometheus" `
            -BinaryPathName "C:\Prometheus\prometheus-2.40.5.windows-amd64\prometheus.exe --config.file=C:\Prommerce\promethus-2..40..windows-amd64\promethus.yml" `
            -DisplayName "Promethus Monitoring" `
            -StartupType Automatic

#启动服务 
Start-Service-Prometh us 

第五步:验证安装

1.在 Prometh us Web界面中( http :// localhost :9090 / graph ) ,尝试查询一些内置指标:

代码片段
process_cpu_seconds_total 
代码片段
go_goroutines 
代码片段
 prometh us _build_info 

2.点击”Execute”按钮并切换到”Graph”选项卡查看数据图表。

第六步:监控 Windows系统 (可选)

要监控 Windows系统指标 ,需要先安装 Windows Exporter:

1.下载最新版 Windows Exporter :
https :// github . com / prometh us — community / windows _ exporter / releases

2.安装并启动 Windows Exporter (默认端口9182):

代码片段
msiexec /i windows_exporter—*.msi ENABLED_COLLECTORS="cpu,memory,os,disk,net,service"

3.在 prometh us . yml中添加配置后重启 Prometh us 。

常见问题解决

Q1:无法访问 http :// localhost :9090

A1:检查 Prometh us是否正在运行 ,防火墙是否阻止了9090端口。

Q2:指标数据不更新

A2:检查 scrape _ interval配置 ,确保目标端点可访问。

Q3:内存使用过高

A3:调整 storage . tsdb . retention参数限制数据保留时间。

总结

通过本文 ,你已成功在 Windows10上:

✓下载并安装了 Prometh us
✓配置了基本监控
✓学会了查询指标数据
✓了解了如何监控 Windows系统

作为扩展 ,你可以:

•探索 Alertmanager设置警报
•集成 Grafana进行可视化
•添加更多 exporter监控其他服务

希望这篇指南能帮助你开始使用这个强大的监控工具!

原创 高质量