Jmeter + InfluxDB + Grafana

381 阅读2分钟

安装配置InfluxDB 参考

step1:下载influxDB

cd /usr/local

wget https://dl.influxdata.com/influxdb/releases/influxdb-1.7.0.x86_64.rpm --no-check-certificate

rpm -ivh influxdb-1.7.0.x86_64.rpm

安装完成之后,生成默认的配置文件/etc/influxdb/influxdb.conf

step2: 修改配置文件

vim /etc/influxdb/influxdb.conf

enabled = true 
database = "jmeter" # 数据库名称 
retention-policy = "" 
bind-address = ":2003" # 端口 
protocol = "tcp" 
consistency-level = "one" 

修改以下信息

[meta] 

dir = "/usr/local/influxdb/meta" #存放最终存储的数据,文件以.tsm结尾 

[data] 

dir = "/usr/local/influxdb/data" #存放数据库元数据 

wal wal-dir = "/usr/local/influxdb/wal" #存放预写日志文件 

修改HTTP端口信息 

[http] # Determines whether HTTP endpoint is enabled. 

enabled = true # The bind address used by the HTTP service. 
bind-address = ":8086"

step3: 创建存放数据目录

mkdir /usr/local/influxdb

chown -R influxdb:influxdb /usr/local/influxdb

如果使用其他用户,则需要切换到root用户才可以修改文件权限

step4: 启动influxDB服务

启动方式1:(推荐)

vim /etc/profile

添加变量:export INFLUXDB_CONFIG_PATH=/etc/influxdb/influxdb.conf

source /etc/profile 环境变量立即生效

influxd & 启动

启动成功展示如下图:

image.png

启动方式2:

influxd -config /etc/influxdb/influxdb.conf 启动

step5:启动成功验证

netstat -antp|grep 8088

influxDB的tcp端口是8088,显示如下则启动成功:

image.png

step6:创建数据库

执行如下命令

$ influx

> show databases

> CREATE DATABASE jmeter

> use jmeter

> create user "admin" with password '123456' with all privileges

此处设置的用户名和密码需要记录下来,后面配置JMeter和Grafana时有用到

安装配置Grafana 参考

step1:下载Grafana 官网地址

cd /usr/local

wget https://dl.grafana.com/oss/release/grafana-7.5.3-1.x86_64.rpm

sudo rpm -i --nodeps grafana-7.5.3-1.x86_64.rpm

grafana-server -v 查看版本

step2:启动Grafana

sudo service grafana-server start

step3:浏览器访问

http://host:3000

默认账号密码:admin/admin

可以设置匿名登录 参考

step4:设置数据源

image.png

image.png

image.png

step5:设置jmeter报告模板

image.png

image.png

jmeter设置

step1:创建后端监听器

image.png

后端监听器实现,选择influxDB

image.png

jmeter模拟发送请求后,即可在Grafana后台中看到相应数据报告展示

针对不同项目进行压测的时候,如何不覆盖原有项目的监听器,且在grafana平台上展示对应的报告呢

在jmeter中创建后端监听器时,设置application ,不同的项目对应不同的application name,在grafana平台的数据展示面板中选择对应的application即可