系统性能监控:Prometheus + Grafana 监控服务器性能(Window环境)
目录
系统性能监控:Prometheus + Grafana 监控服务器性能(Window环境)
一. Prometheus简介Prometheus使用Go语言开发,是最初在SoundCloud上构建的开源系统监控和警报工具,在2016年加入了Cloud Native Computing Foundation(CNCF)基金会,是继Kubernetes之后该基金会的第二个托管项目。
1. 主要特性:
2. 组成:
二. Prometheus + Grafana监控系统性能主要用到了Prometheus,windows_exporter和Grafana,Prometheus和windows_exporter收集保存服务器性能数据,Grafana用于图形化展示数据。 二.1. 安装wmi-exporter下载地址:https://github.com/martinlindhe/wmi_exporter/releases选择最新msi文件下载安装即可。 完成安装后会自动创建一个开机自启的服务,通过服务(services.msc)判断是否有有windows_exporter
通过访问http://localhost:9182 出现下图,即代表安装采集数据成功。
二.2. 安装Prometheus下载地址:Download | Prometheus 选择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: 'A3mall' # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ['localhost:9182'] 添加监控主机,在scrape_configs节点下配置如下,可根据需要配配置多个节点位置,也可在targets节点中使用逗号分隔配置多台主机:
完成配置,重新运行程序,进入http://localhost:9090/classic/targets,可查看查看监控信息;
二.3. 安装Grafana下载地址:https://grafana.com/grafana/download,选择windows 版本;官方提供installer、zip 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框中输入选择所需要的模版;记录下模版ID或下载JSON文件(Download JSON); Windows模板推荐:10467模块; Linux服务器系统性能监控推荐8919。 mysql性能监控:7362
配置完成! |