在性能测试中,服务器资源是值得关注一项内容,目前,市面上已经有很多的服务器资 源监控方法和各种不同的监控工具,方便在各个项目中使用。
但是,在性能测试中,究竟哪些指标值得被关注呢?
监控有着的分级体系,下面引用:

在以前的工作中,想要实现服务器资源监控和DB的监控,只能依靠任务管理器和肉眼, 也无法保存历史数据,结果也存在很大误差,导致无法给出精确结果。
下面对 prometheus 进行介绍:
node_expoert:被监控机器。Windows 或者是 Linux 的系统都可以 Prometheus:Prometheus 服务,用于监控数据收集和查询,部署在 windows 下和 Linux 下 都可以
Grafana:Grafana 服务,用于数据展示,部署在 windows 下和 Linux 下都可以

node_expoert:(windows)
第一步:
打开运行 windows_exporter.exe

验证方法:在浏览器里面访问:locahost:9182,如果能正常访问,出现以下内容,表 示启动成功:

第二步:服务器应该都开启了防火墙,需要把使用的端口允许通过防火墙,才可以使用。



第三步:验证在另外的机器上是否可以正常 在另外的机器上的浏览器中输入服务器的 ip+9182 检查是否出现和第一步相同的结果
node_expoert:(Linux,以 centos7 为例)
第一步:
上传 node_expoert。Windows 和 Linux 使用到的 node_expoert 不一致 第二步:
移动进行目录

第三步:后台启动
nohup /usr/local/node_exporter/node_exporter & 如果出现把输出追加到 nohup.out,为正常 第四步:检查服务是否正常开启
运行:netstat -nultp
启动成功结果:

第四步:服务器应该都开启了防火墙
在 Linux 下,node_expoert 使用的端口为 9100。先检查端口是否开启:
运行:firewall-cmd --query-port=9100/tcp
如果返回 no,则端口未开启
开启对应端口:
firewall-cmd --zone=public --add-port=9100/tcp --permanent 开启端口之后需要重启一下防火墙:
firewall-cmd --reload
第五步:
在另外的机器上访问采集地址:
服务器 ip:9100/metrics
如果出现以下内容表示成功

Prometheus:
以 windows 为例,如果需要使用 docker 或者是 Linux,请参考:https://testerhome.com/topics/22231** 下载:在官网上即可获取到最新的安装包**
第一步:服务启动:双击运行即可

验证方法:
访问服务器 ip+9090,能正常访问,出现以下内容表示启动成功

第二步:
准备 node_expoert
打开 prometheus.yml 的配置文件,在配置文件中添加一个新的 job

第三步:重启 prometheus 的服务
第四步:
经过短暂的延迟之后,访问 prometheus 的服务地址。进入 status---targets 即可看到刚刚添加的 node_expoert

node_expoert 的状态为 up,则表示成功访问 node_expoert 的状态为 down,则表示失败

Grafana:
Grafana 是一个开源的度量分析和可视化工具,可以通过将采集的数据分析,查询,然 后进行可视化的展示,并能实现报警。
服务安装:
访问官网获取安装包
服务启动:
进入 GrafanaLabs\grafana\bin,运行 grafana-server.exe 启动服务 访问地址为:服务器 ip+3000
同样,如果防火墙打开,需要允许 grafana-server.exe 通过防火墙 第一次访问,使用
admini/admini 进行登录即可 成功之后系统会提示修改密码,修改符合规则要求的密码即可
第一步:
添加数据源
进入 Configuration-Data Sources,添加数据源,选择 Prometheus

数据源设置:
填写完成 name 和 url 之后保存即可

第二步:
添加监控看板 目前,我们使用官方提供的看板 点击 create----import

特别注意:
1.Windows 系统的机器和 Linux 系统的机器,使用的看板文件是不一致的,windows 机器只 能使用 windows 看板,Linux 机器只能使用 Linux 看板
2.如果在监控 window服务器的时候,node_expoert 使用的是最新的 V0.13.0 版本,需要把 看板中的查询语句进行修改替换
需要把 wmi_修改为 windows_

3.如 果 要 获 取 官 方 的 看 板 , 请 访 问 :https://grafana.com/grafana/dashboards

最后感谢每一个认真阅读我文章的人,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:
这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!
