CentOS下结合InfluxDB及Grafana图表实时展示JMeter相关性能数据
by:授客QQ:1033553122
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 777grafana/
设置系统启动时,自动启动grafana
#chkconfig --add grafana-server