压测监控平台搭建
配置Docker环境
- yum包更新到最新
sudo yum update
- 安装需要的软件包
#yum-utils提供yum-config-manager功能
#device-mapper-persistent-date和lvm2是devicemapper驱动需要依赖的包
sudo yum install -y yum-utils device-mapper-persistent-date lvm2
- 设置yum源为阿里云
#配置yum源的代理,类似于maven镜像仓库,加速下载软件
sudo yum-config-manager --add-repo mirrors.aliyun.com/dockerce/
linux/centos/docker-ce.repo
- 安装docker
sudo yum install docker-ce
#查看docker版本
docker -v
安装influxDB
- 下载influxDB的镜像
docker pull influxdb:1.8
- 启动influxDB容器
docker run -d --name influxdb -p 8086:8086 -p 8083:8083 influxdb:1.8
- 进入容器内部,创建jmeter数据库
docker exec -it influxdb /bin/bash
输入influx命令进入influx操作界面
#创建数据库
create databases jmeter
#查看数据库
show databases
#使用数据库
use jmeter
#查询数据库数据
select * from jmeter
- 设置JMeter脚本后置处理器
想要将JMeter的测试数据导入influxDB,就需要再JMeter中使用Backend Listener配置
1)主要配置说明:后端监听器实现(implementation)选择influxDB对应的
- influxdbUrl:需要改为自己influxdb的部署ip和映射端口,端口是容器启动时映射的8086端口,db后面跟的是刚才创建的数据库名称
- application:可根据需要自由定义,只是注意后面再Grafana中选对即可
- measurement:表名,默认是jmeter,也可以自定义
- summaryOnly:选择true的话就只有总体的数据,false会记录总体数据,然后再将每个transantion都分别记录
- samplersRegex:样本正则表达式,将匹配的样本发送到数据库
- percentiles:响应时间的百分位P90、P95、P99
- testTitle:events表中的text字段的内容
- eventTags:任务标签,配置Grafana一起使用
2)运行验证:运行JMeter脚本,然后在influxDB中查看是否有数据(select * from jmeter)
安装和使用Grafana
安装Grafana
- 下载Grafana镜像
docker pull grafana/grafana
- 启动Grafana容器
docker run -d --name grafana -p 3000:3000 grafana/grafana
- 访问grafana主页
http://服务器ip:3000
默认账号密码:admin/admin
配置Grafana
- 选择添加数据源
- 找到并选择influxDB
- 配置influxDB数据源
出现Data source is working表示配置成功
- 导入模板
模板导入分别有以下3种方式:
- 直接输入模板id号
- 直接上传模板json文件
- 直接输入模板json内容
这里提供两个模板ID
- Apache JMeter Dashboard
- dashboad-ID:5496
- JMeter Dashboard(3.2 and up)
- ashboad-ID:3351
- 导入模板并配置
- 监控数据展示
安装node_exporter
#下载安装包
wget -c https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_ex
porter-0.18.1.linux-amd64.tar.gz
#解压
tar zxvf node_exporter-0.18.1.linux-amd64.tar.gz -C /usr/local/
#启动
cd /usr/local/node_exporter-0.18.1.linux-amd64
nohup ./node_exporter > node.log 2>&1 &
访问node_exporter主页http://服务器ip:9100
安装Prometheus(普罗米修斯)
- 下载解压运行
#下载安装包
wget -c https://github.com/prometheus/prometheus/releases/download/v2.15.1/prometheus
-2.15.1.linux-amd64.tar.gz
#解压
tar zxvf prometheus-2.15.1.linux-amd64.tar.gz -C /usr/local/
#运行
cd //usr/local/prometheus-2.15.1.linux-amd64
nohup ./prometheus > prometheus.log 2>&1 &
- 修改yml配置
增加scrape_configs的配置
# 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: 'aisino'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['192.168.51.170:9100']
- 访问prometheus监控目标
http://服务器ip:9090/targets
Grafana整合Prometheus监控
- 添加prometheus数据源
- 配置prometheus数据源
- 导入模板ID
- Node Exporter for Prometheus Dashboard EN 20201010
- dashboard-ID: 11074
- Node Exporter Dashboard
- dashboard-ID: 16098
- 监控数据展示