系统性能监控:Prometheus + Grafana 监控服务器性能(Window环境)

一. Prometheus简介

Prometheus使用Go语言开发,是最初在SoundCloud上构建的开源系统监控和警报工具,在2016年加入了Cloud Native Computing FoundationCNCF)基金会,是继Kubernetes之后该基金会的第二个托管项目。

1. 主要特性

多维数据模型,由指标名称和键值对标识的时间序列数据度量

PromQL查询语言

不依赖分布式存储;单个服务器节点是自治的

通过HTTP使用pull模式收集时间序列数据

支持通过中间网关推送时间序列数据

通过服务发现或静态配置发现目标对象

支持多种图形和仪表盘

 

2. 组成

Prometheus主服务器:用于抓取并存储时间序列数据

客户端库:用于检测应用程序代码

推送网关:支持短生命周期

各种exporter:HAProxy,StatsD,Graphite等服务收集服务器性能数据

警告管理器

各种支持工具

 

二. Prometheus + Grafana监控系统性能

主要用到了Prometheuswindows_exporterGrafanaPrometheuswindows_exporter收集保存服务器性能数据,Grafana用于图形化展示数据。

二.1. 安装wmi-exporter

下载地址:https://github.com/martinlindhe/wmi_exporter/releases选择最新msi文件下载安装即可。

完成安装后会自动创建一个开机自启的服务,通过服务(services.msc)判断是否有有windows_exporter

 

 通过访问http://localhost:9182 出现下图,即代表安装采集数据成功。

 

二.2. 安装Prometheus

下载地址:https://prometheus.io/download/ 选择windows环境下选择最新windows-amd64.zip文件下载。

文件下载后解压,双击prometheus.exe文件,运行Prometheus ;默认端口为9090通过访问http://localhost:9090,显示下图,代表运行成功;

 

Prometheus配置文件为prometheus.yml文件,我使用的配置如下:

# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration

alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093 

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml" 

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.

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"] 

  - job_name: 'Windows'
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    static_configs:

    - targets: ['localhost:9182']

添加监控主机,在scrape_configs节点下配置如下,可根据需要配配置多个节点位置,也可在targets节点中使用逗号分隔配置多台主机:

  - job_name: 'Windows'
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    static_configs:
- targets: ['wmi.Exporter主机地址:端口号’]

 完成配置,重新运行程序,进入http://localhost:9090/classic/targets,可查看查看监控信息;

 

 

二.3. 安装Grafana

下载地址:https://grafana.com/grafana/download选择windows 版本官方提供installerzip file两种类型下载包,本次选用zip file文件包。

文件下载后解压,进入bin目录双击grafana-server.exe文件,运行Grafana,如下图:

 

进入系统:

上图所示,默认端口为3000通过访问http://localhost:300,显示下图,代表运行成功;

 

系统第一次运行,默认用户密码为:admin/admin,系统会提示修改密码。

 

进入系统

 

配置数据源:

选择Configuration-Data source-Add data source,选择Prometheus;在HTTP-URL中填写Prometheus地址,保存配置(注意查看提示,是否验证成功);如下图:

 

 

  验证成功

 

添加仪表盘:

选择Dashboards-Browse,点击Import,导入模版,如下图:

模版获取地址:https://grafana.com/dashboards,打开上述地址,在Search框中输入Windows,选择所需要的模版;记录下模版ID或下载JSON文件(Download JSON);较多大老推荐合使用ID10467模块;

 

 

配置完成!

 

参考内容:

https://www.cnblogs.com/guoxiangyue/p/11777227.html
https://www.cnblogs.com/hiyong/p/14587293.html
https://glory.blog.csdn.net/article/details/108275219

posted @ 2021-12-29 16:56  年近40学编程  阅读(394)  评论(0编辑  收藏  举报