转载自 https://testerhome.com/topics/21113
概述
关于influxdb+grafana的文章,谷歌百度一大把,但是99.9%不知所云,不是这边漏一点就是那边漏一点。甚至怀疑绝大部分都是互相抄袭。本着前人挖坑后入埋的态度,我整理了一份详细的文档,给大家分享一下。ubuntu环境
influxdb安装配置
下载安装influxdb工具
wget https://dl.influxdata.com/influxdb/releases/influxdb_1.2.4_amd64.deb
sudo dpkg -i influxdb_1.2.4_amd64.deb
修改配置文件
vim /etc/influxdb/influxdb.conf
修改host
开放8086端口
开放8083端口
开放2003端口,同时修改数据库名称(我的库名是jmeter,后面会建)
启动数据库。执行influxd run
配置influxdb数据库
进入数据库
执行:influx进入数据库
添加用户名密码
[root@imzcy ~]# influx
> CREATE USER root WITH PASSWORD '000000' WITH ALL PRIVILEGES
> SHOW USERS
user admin
root true
开启auth认证
配置文件中,8086端口下开启auth权限控制
vim /etc/influxdb/influxdb.conf
重启数据库
重启数据库之后再访问数据库就需要带入用户名密码了,否则会报错
influx -username root -password 000000
浏览器启动influxdb数据库
需要配置用户名密码,然后连接
创建两个数据库,jmeter和telegraf。语法和mysql一致
telegraf服务器监控配置
安装telegraf
wget https://dl.influxdata.com/telegraf/releases/telegraf_0.11.1-1_amd64.deb
sudo dpkg -i telegraf_0.11.1-1_amd64.deb
修改配置文件
vim /etc/telegraf/telegraf.conf
配置host,端口(8086),数据库名称,数据库用户名密码
启动telegraf
/etc/init.d/telegraf restart
grafana配置
下载安装grafana
wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana_5.1.3_amd64.deb
sudo apt-get install -y adduser libfontconfig
sudo dpkg -i grafana_5.1.3_amd64.deb
服务端启动grafana
执行:service grafana-server restart
浏览器启动grafana
用户名密码默认是admin admin
grafana服务连接数据库
配置datasource,连接jmeter和telegraf两个数据库
grafana导入模板
jmeter模板id:4026
telegraf模板id:3967
system资源监控
点击/home/system
jmeter性能指标监控
jmeter添加后端监听器
配置监听器并运行
添加数据库连接host,端口,库名,用户名,密码
grafana监听jmeter数据
常用sql
聚合报告
SELECT count(responseTime) as Count, mean(responseTime) as Avg, min(responseTime) as Min, median(responseTime) as Median, percentile(responseTime, 90) as "90%",percentile(responseTime, 95) as "95%",percentile(responseTime, 99) as "99%", max(responseTime) as Max, (sum(errorCount)/count(responseTime)) as "Error Rate" FROM "requestsRaw" WHERE $timeFilter GROUP BY time(1m)
吞吐量
SELECT count("responseTime") FROM "requestsRaw" WHERE $timeFilter GROUP BY time(1s)
响应时间
SELECT mean("responseTime") FROM "requestsRaw" WHERE $timeFilter GROUP BY time($__interval)
活动线程
SELECT mean("meanActiveThreads") FROM "virtualUsers" WHERE $timeFilter GROUP BY time(1s)