CentOS下结合InfluxDB及Grafana图表实时展示JMeter相关性能数据
by:授客 QQ:1033553122
JMeter Backend Listener监听器配置 9
Win7 64位
Python 3.4.0
JMeter 2.13 r1665067
CentOS 6 64位(内核版本2.6.32-642.el6.x86_64)
influxdb-1.5.2.x86_64.rpm
网盘下载地址:
https://pan.baidu.com/s/1jAbY4xz5gvzoXxLHesQ-PA
grafana-5.1.2-1.x86_64.rpm
下载地址:
https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.1.3-1.x86_64.rpm
下载地址:https://pan.baidu.com/s/1wtnPH-iYxaXc6FnL1i0ZVg
influxdb-5.0.0-py2.py3-none-any.whl
下载地址:
https://pypi.org/project/influxdb/#files
下载地址:https://pan.baidu.com/s/1DQ0HGYNg2a2-VnRSBdPHmg
1、安装influxdb
# rpm -ivh influxdb-1.5.2.x86_64.rpm
修改配置
如下,修改一下带背景色内容
# vim /etc/influxdb/influxdb.conf
[http]
# Determines whether HTTP endpoint is enabled.
enabled = true
# The bind address used by the HTTP service.
bind-address = ":8086"
# Determines whether user authentication is enabled over HTTP/HTTPS
auth-enabled = false
说明:设置auth-enabled = false是为了免账号密码授权认证访问,图个方便
# The default realm sent back when issuing a basic auth challenge.
# realm = "InfluxDB"
# Determines whether HTTP request logging is enabled.
# log-enabled = true
[[graphite]]
#Determines whether the graphite endpoint is enabled.
enabled = true
database = "jmeter"
# retention-policy = ""
bind-address = ":2003"
protocol = "tcp"
consistency-level = "one"
#说明 设置consistency-level = "one" 设置一致性级别,设置为one表示读操作不会对写操作造成延迟
# These next lines control how batching works. You should have this enabled
# otherwise you could get dropped metrics or poor performance. Batching
# will buffer points in memory if you have many coming in.
# Flush if this many points get buffered
batch-size = 5000
# number of batches that may be pending in memory
batch-pending = 10
# Flush at least this often even if we haven't hit buffer limit
batch-timeout = "1s"
# UDP Read buffer size, 0 means OS default. UDP listener will fail if set above OS max.
udp-read-buffer = 0
### This string joins multiple matching 'measurement' values providing more control over the final measurement name.
separator = "."
说明:个人理解,这里的[[graphite]]配置主要是为收集JMeter性能数据配置的,如果不需要收集jmeter性能数据,应该可以不用配置(未测试)
启动/重启linfluxdb
# service influxdb start
# service influxdb restart
Stopping influxdb...
influxdb process was stopped [ OK ]
Starting influxdb...
influxdb process was started [ OK ]
查看是否在监听端口
[appdeploy@cnsz22VLK6817:/etc/influxdb]#netstat -antp | grep 2003
tcp 0 0 0.0.0.0:2003 0.0.0.0:* LISTEN 23994/influxd
2、创建influxdb数据库
# /usr/bin/influx
Connected to http://localhost:8086 version 1.5.2
InfluxDB shell version: 1.5.2
# 查看有哪些数据库
> show databases
name: databases
name
----
_internal
# 创建数据库,库名为 jmeter(create database dbname)
> create database jmeter
> show databases
name: databases
name
----
_internal
jmeter
# 附其它操作(类似mysql数据库)
# “切换”到要操作的数据库(use dbname)
> use jmeter
# 查看有哪些数据表(influxdb中定义为measurement)
> show measurements
name: measurements
name
----
jmeter.all.a.count
jmeter.all.a.max
jmeter.all.a.min
jmeter.all.a.pct90
jmeter.all.a.pct95
jmeter.all.a.pct99
……
说明:以上数据是我跑压测后才有的,往下不再赘述
# 查询数据表数据
> select * from "jmeter.all.a.max" limit 10
name: jmeter.all.a.max
time value
---- -----
1526383743000000000 6
1526383744000000000 18
1526383745000000000 18
1526383746000000000 18
1526383747000000000 27
1526383962000000000 7
1526383963000000000 7
1526383964000000000 12
1526383965000000000 12
1526383966000000000 12
注意:表名为上述xx.xxx.xx的形式的时候,需要加双引号,删除的时候也是
# 删除数据表(drop measurement measurement_name)
> drop measurement " jmeter.all.a.max"
# 删除数据库
> drop database dbname
3、安装grafana
# rpm -ivh grafana-5.1.2-1.x86_64.rpm
检查、修改grafana.ini配置
# vim /etc/grafana/grafana.ini
####################################
[server]
# Protocol (http, https, socket)
;protocol = http
# The ip address to bind to, empty will bind to all interfaces
;http_addr =
# The http port to use
;http_port = 3000
# The public facing domain name used to access grafana from a browser
;domain = localhost
……
[security]
# default admin user, created on startup
;admin_user = admin
# default admin password, can be changed before first start of grafana, or in profile settings
;admin_password = admin
……
启动grafana
# /usr/local/grafana/etc/init.d/grafana-server start
Starting Grafana Server: ... [ OK ]
不同系统可能不一样,也可能是 /usr/sbin/grafana-server
或者
# service grafana-server start
# sudo /bin/systemctl start grafana-server.service
自家电脑上安装时发现会出现没法启动的情况,tail -f /var/log/grafana/grafana.log 发现error="open /var/run/grafana/grafana-server.pid: permission denied"错误
解决方法:
# cd /var/run/
# chmod 777 grafana/
设置系统启动时,自动启动grafana
# chkconfig --add grafana-server
或者
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable grafana-server.service
注意:安装grafana时不要指定安装路径,按默认的就好
浏览器输入网址:10.203.25.106:3000访问看看效果:
输入账号admin 密码admin 登录
参考链接:https://blog.csdn.net/wudufeng/article/details/78567866
打开页面中按如方式填写
说明
Name 数据源名称,自定义
Type 设置为InfluxDB
URL 设置influxDB服务器地址和端口(这里的8086为influxdb配置文件,[http]节点下配置的 bind-address值
Database 设置为在influxdb配置中,[[graphite]]节点下配置的database值,这样grafana就可以从这个数据库读取相关表相关数据了
User Password 可以不填写,因为设置授权认证
最后点击Save&Test按钮,如果成功则可看到上述Data source working的提示
[http]
# Determines whether HTTP endpoint is enabled.
enabled = true
# The bind address used by the HTTP service.
bind-address = ":8086"
右键测试计划、线程组 -> 添加 -> 监听器 -> Backend Listener
如下,修改graphiteHost为influxdb服务器所在地址,设置influxdb 配置文件中[[graphite]]节点下,配置的bind-address 值,设置rootMetricsPrefix为配置的database值,其它暂且默认即可
也可以设置summaryOnly为false,并在samplerList中填写sampler元素名称(多个元素之间用逗号分隔),如下(JMeter 2.13)
这样就可以统计单个sampler的相关信息了
samplersList也支持正则表达式,具体操作如下:
1.将“summanyOnly”修改成False,
2.将“userRegexpForSamplersList”修改成True,
3. 设置“samplersList”的值为匹配目标sampler的正则表达式
参考链接:
http://jmeter.apache.org/usermanual/component_reference.html#Backend_Listener
图表配置并查看效果
jmeter measurement说明
线程/虚拟用户指标
test.minAT
最小活动线程数
test.maxAT
最大活动线程数
test.meanAT
平均活动线程数
test.startedT
已启动线程数
test.endedT
已完成线程数
响应时间指标
.ok.count
统计指定sampler的响应成功的响应数
注:samplerName指定了要统计的sampler,如果为all则表示针对所有all sampler的统计
.h.count
统计指定sampler的服务器每秒点击数,会累计sample结果及子sample结果(如果使用了事务控制器,必须取消勾选 Generate parent sampler 选项)
.ok.min
统计指定sampler响应成功的最小响应时间
.ok.max
统计指定sampler响应成功的最大响应时间
.ok.avg
统计指定sampler响应成功的平均响应时间
.ok.pct
统计指定sampler响应成功的百分比
.ko.count
统计指定sampler响应失败数
.ko.min
统计指定sampler响应失败的最小响应时间
.ko.max
统计指定sampler响应失败的最大响应时间
.ko.avg
统计指定sampler响应失败的平均响应时间
.ko.pct
统计指定sampler响应失败的百分比
.a.count
统计指定sampler请求数
.a.min
统计指定sampler请求的最小响应时间
.a.max
统计指定sampler的最大响应时间
.a.avg
统计指定sampler的平均响应时间
.a.pct
统计指定sampler的响应占比
参考链接:
http://jmeter.apache.org/usermanual/realtime-results.html#metrics
http://www.testautomationguru.com/jmeter-real-time-results-influxdb-grafana/