2被测端监控:Exporter + Prometheus + Grafana 上一节我们介绍了在压测端使用JMeter集群+Influxdb存储+Grafana实时数据展示进行监控压测端,这一节我们来介绍下在被测端的监控工具组合:Exporter + Prometheus + Grafana。 2.1 Exporter 在被测端,如果操作系统为Linux系统,对应的Exporter为node_exporter;如果操作系统为Windows系统,对应的Exporter为windows_exporter.exe。我们先来介绍node_exporter的安装。 1)node_exporter node_exporter可通过以下几个步骤进行和下载和安装。
node_exporter-0.18.1.linux-amd64.tar.gz。
2)windows_exporter.exe windows_exporter可通过以下几个步骤进行下载和安装。
图14 windows_exporter主界面
注意node_exporter端口为9100,而windows_exporter为9182。
点击Metrics可以显示收集到的Windows操作系统信息
# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 0
go_gc_duration_seconds{quantile="0.25"} 0
go_gc_duration_seconds{quantile="0.5"} 0
go_gc_duration_seconds{quantile="0.75"} 0
go_gc_duration_seconds{quantile="1"} 0.0022913
go_gc_duration_seconds_sum 0.0043842
go_gc_duration_seconds_count 34
…
其中。
2.2 Prometheus Prometheus 是由 SoundCloud 开源监控告警解决方案。 1)Prometheus Windows版本通过网页下载prometheus-2.27.1.windows-amd64;Liunx下通过以下命令来完成安装。
https://github.com/prometheus/prometheus/releases/download/v2.15.1/prometheus-2.15.1.linux-amd64.tar.gz
2)修改prometheus.yml文件中的端口号。
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from
this config.
- job_name: 'OS'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['127.0.0.1:9182']
在这里Windows下使用- targets: ['127.0.0.1:9182'],而Linux下使用- targets: ['127.0.0.1:9100']。 下面来简单介绍一下这个文件。
3)运行prometheus.exe,打开浏览器,在地址栏中输入:http://127.0.0.1:9090/targets,如图15所示。
图15 Prometheus主界面
在这个界面中我们可以看见windows_exporter.exe或node_exporter被Prometheus监控到。
2.3 Grafana Grafana的安装我们在上一节中介绍过,现在让我们来看一下如何对Prometheus进行配置。 1)启动Grafana 2)打开浏览器,在地址栏中输入:http://127.0.0.1:3000/datasources/new,按下图输入Name,HTTP下的URL、Access。如图16所示。
图16 配置Grafana访问Prometheus信息
3)点击【Save & Test】,验证测试通过,如图17所示。
图17 验证配置Grafana访问Prometheus信息是否正确
4)接下来按照1.3第7)步,import windows_exporter.exe或node_exporter数据,如图18所示。
图18 import windows_exporter或node_exporter数据
注意:windows_exporter ID为10467,node_exporter ID为8919。可以通过https://grafana.com/grafana/dashboards/10467和https://grafana.com/grafana/dashboards/8919来查看信息。 5)点击【Import】就可以看到监控信息了,如图19所示和图20所示。这里监控都是被测机器操作系统的数据,包括CPU、内存、网络、磁盘等信息。
图19 确认Import windows_exporter或node_exporter数据
图20 windows_exporter或node_exporter监控数据展示
2.4 配置MySQL监控 另外我们还可以来监控MySQL信息。 1)通过https://prometheus.io/download/来下载mysql_export。如图21所示。
图21 下载mysql_export
2)下载完毕,修改my.cnf文件,配置MySQL连接信息。
[client]
host=127.0.0.1
port=3306
user=root
password=123456
在这里host为MySQL所在的IP地址、port为端口号,默认是3306、user是MySQL的用户名、password是MySQL的密码。 3)通过运行mysqld_exporter.exe --config.my-cnf=my.cnf启动,启动后,在浏览器的地址栏中输入:http://127.0.0.1:9104/。得到图22所示。
图22 mysqld_exporter主界面
4)对prometheus.yml进行如下配置。
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this
config.
- job_name: 'OS'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['127.0.0.1:9182']
- job_name: 'MySql'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['127.0.0.1:9104']
5)重新启动prometheus.exe,在浏览器送输入http://127.0.0.1:9090/targets,得到图23界面。
图23 Prometheus主界面
在这个界面中我们可以看见mysqld_exporter被prometheus监控。 6)启动Grafana,Import mysql_exporter数据信息。如图24所示。
图24 import mysql_exporter数据
7)mysql_exporter节点为11323,可以通过https://grafana.com/grafana/dashboards/11323来查看 8)最后点击【Load】,仍旧选择Prometheus就可以看到mysql_exporter的信息了。如图25所示。
图25 mysql_exporter监控数据展示
关于Prometheus可以参考https://www.bookstack.cn/read/prometheus-book/README.md。