telegraf1.8+influxdb1.6+grafana5.2 环境搭建 结合JMeter3.2
参考地址:https://blog.csdn.net/laisinanvictor/article/details/80007356
1)配置yum源
#配置yum源 /etc/yum.repos.d/influxdb.repo[influxdb]name = InfluxDB Repository - RHEL \$releaseverbaseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stableenabled = 1gpgcheck = 1gpgkey = https://repos.influxdata.com/influxdb.key 2)安装telegraf#收集系统和服务的统计数据 , 并写入到 InfluxDB数据库 , 在需要监控的机器上安装yum -y install telegraf#配置文件路径
/etc/telegraf/telegraf.conf #设置开机时启动systemctl enable telegraf.service#启动
systemctl start telegrafsystemctl status telegraf#例子:配置Telegraf(这里用不到,所以不用配置)
[root@monitor src]# vim /etc/telegraf/telegraf.conf## 修改内容如下# Configuration for influxdb server to send metrics to[[outputs.influxdb]] ## The full HTTP or UDP URL for your InfluxDB instance. ## ## Multiple URLs can be specified for a single cluster, only ONE of the ## urls will be written to each interval. # urls = ["unix:///var/run/influxdb.sock"] # urls = ["udp://127.0.0.1:8089"] # urls = ["http://127.0.0.1:8086"]urls = ["http://10.1.5.49:8086"]
## The target database for metrics; will be created as needed.
# database = "telegraf"database = "ip_214_70_stat"
systemctl restart telegraf#卸载telegraf(重装时需要卸载)
rm -rf telegrafrm -rf /etc/systemd/system/multi-user.target.wants/telegraf.service#检查Telegraf配置
systemctl status telegraf#状态是running说明配置加载成功 3)安装influxdb#时序数据库,默认端口为Web端8083,API端8086,默认登陆信息admin 使用方式有点类似MySQL#新版本 web界面功能被去掉了#安装
yum -y install influxdb#设置开机时启动
systemctl enable influxdb.service#启动
systemctl start influxdbsystemctl status influxdb#增加8083 8086端口,允许他通过防火强 influxdb:8083 8086
firewall-cmd --zone=public --add-port=8083/tcp --permanentfirewall-cmd --zone=public --add-port=8086/tcp --permanent#重新加载防火强
firewall-cmd --reload#查看通过防火强的端口
firewall-cmd --zone=public --list-ports#重启防火强
systemctl restart firewalld 4)创建 Influxdb数据库[root@monirot src]# influxConnected to http://localhost:8086 version 1.6.3InfluxDB shell version: 1.6.3#重启influxdb
systemctl restart influxdb#查看数据打开 Influxdb 查询界面:http://你的ip地址:8086 , 输入查询语句seclect * from cpu可查询到 CPU 相关信息。访问 influxdb
http://ip:8086/ 5)安装Grafana#访问各类数据源,自定义报表,显示图表等等, 用于提供界面监控,默认端口为3000,默认登陆信息admin地址:https://grafana.com/grafana/download?platform=linuxwget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.2.4-1.x86_64.rpm
sudo yum -y localinstall grafana-5.2.4-1.x86_64.rpmyum -y install fontconfig
yum -y install freetype*yum -y install urw-fonts 安装路径 /usr/sbin/grafana-serverinit.d路径 /etc/init.d/grafana-server环境变量文件路径 /etc/sysconfig/grafana-serverini 文件路径 /etc/grafana/grafana.iniInstalls systemd service (if systemd is available) name grafana-server.service日志文件路径 /var/log/grafana/grafana.logsqllite3库路径 /var/lib/grafana/grafana.dbsystemctl daemon-reload
systemctl start grafana-serversystemctl status grafana-server#设置开机时启动
systemctl enable grafana-server.service#启动
systemctl start grafana-serversystemctl status grafana-server随机启动
sudo systemctl enable grafana-server.service#安装ssh服务
yum -y install openssh-server.x86_64#增加3000端口,允许他通过防火强 Grafana:3000
firewall-cmd --zone=public --add-port=3000/tcp --permanent#重新加载防火强
firewall-cmd --reload#查看通过防火强的端口
firewall-cmd --zone=public --list-ports#重启防火强
systemctl restart firewalld#重启
systemctl restart grafana-server#配置Grafana
http://192.168.169.131:3000 账号:admin 密码:admin 新密码为 123456 6)将JMeter压测后的结果数据,通过Grafana界面展示出来#6-1修改influxdb配置文件vim /etc/influxdb/influxdb.conf#打开8086端口
[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 #在以下地方新增 influx_db 数据库,配置好 监控 influx_db 端口号默认为 2003[[graphite]] # Determines whether the graphite endpoint is enabled. enabled = true database = "influx_db" retention-policy = "" #influxdb上数据保存策略,参考后面设置 bind-address = ":2003" protocol = "tcp" consistency-level = "one"#influxdb上数据保存策略(该步骤可忽略)
name 策略名 duration持续时间 0 无限制 shardGroupDuration shardGroup存储时间 replicaN副本个数 default 默认策略1、新建数据保存策略CREATE RETENTION POLICY "30d_jmeter" ON "influx_db" DURATION 30d REPLICATION 1 DEFAULT2、删除初始策略
DROP RETENTION POLICY "autogen" ON "influx_db"3、显示已有策略
SHOW RETENTION POLICIES on influx_db#保存文件后,再次启动 influxdb
systemctl start influxdb#6-2创建jmeter数据库
[root@monitor jmeter3.2]# influxConnected to http://localhost:8086 version 1.6.3InfluxDB shell version: 1.6.3> create database influx_db> use influx_dbUsing database influx_db> create user "admin" with password '123456' with all privileges> create database graphite_db
> use graphite_dbUsing database graphite_db> create user "admin" with password '123456' with all privileges> create database ip_214_70_stat
> use ip_214_70_statUsing database ip_214_70_stat> create user "admin" with password '123456' with all privileges> show databasesname: databasesname----influx_db_internalip_214_70_stat> exit #6-3在jmeter脚本文件中,新增监听器:Backend Listener方式1:Backend Listener implementation:保持默认 org.apache.jmeter.visualizers.backend.graphite.GraphiteBackendListenerClientAsync Quenue size:取数据的间隔 5000毫秒graphiteMetricsSender:保持默认 org.apache.jmeter.visualizers.backend.graphite.TextGraphiteMetricsSender
graphiteHost:influxdb机器的IP地址 ipgraphitePort:influxdb中配置的端口号 默认 2003rootMetricsPrefix:influxdb中配置的表名 jmeter. 不要更改该名字summaryOnly:改成 false 是否统计总量samplersList:改成 .* 请求的URL关键字.*useRegexpForSamplersList:改成 truepercentiles:保持默认 90;95;99#要配置对应某个请求的话,需要配置一下三项,否则保持默认就行
summaryOnly:改成 falsesamplersList:改成 .*请求的URL关键字.* #summaryOnly=true,此处设置则失效,与请求的URL进行匹配,支持正则表达式,就是请求的名称是什么,这里就要配置的好去对应它useRegexpForSamplersList:改成 true 方式2:Backend Listener implementation:保持默认 org.apache.jmeter.visualizers.backend.influxdb.influxdbBackendListenerClientAsync Quenue size:取数据的间隔 5000毫秒graphiteMetricsSender:保持默认 org.apache.jmeter.visualizers.backend.influxdb.HttpMetricsSender
graphiteHost:influxdb机器的IP地址 ip http://ip:8086/write?db=influx_dbapplication:应用名 比如:某某系统接口测试 influx_dbmeasurement: jmetersummaryOnly:改成 false 是否统计总量samplersRegex:.* 正则表达式percentiles:保持默认 50;90;95;99testTitle:influx_db_testTitleeventTags:influx_db_eventTags#6-4访问grafana http://ip:3000/
#修改配置文件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[security]
# default admin user, created on startupadmin_user = admin# default admin password, can be changed before first start of grafana, or in profile settings
admin_password = 123456 #配置数据库 ,保存后退出#8086端口 是Grafana用来从数据库取数据的端口 2003端口是JMeter往数据库里面发数据的端口name:name 随意取值type:influxDBHTTP
URL:http://ip:8086Access:Server(Default)InfluxDB Details
Database:influx_db#创建jmeter数据库时,指定的用户,该用户可访问该jmeter数据库user:admin Password:123456Min time interval:10秒
#配置数据库面板 Home->dashboard->Graph->Edit#在编辑中,选择数据库 Data Source :middleground#压测运行完成,到图标里面就可以看到对应数据库了jmeter.all.h.count 所有请求的TPS
jmeter.<请求名称>.h.count 对应<请求名称>的TPSjmeter.all.ok.pct99 99%的请求响应时间jmeter.<请求名称>.ok.pct99 对应<请求名称>99%的请求响应时间jmeter.all.test.startedT 线程数#安装jmeter模板,进入下面网站,选择influxdb 搜索jmeter
https://grafana.com/dashboards选择JMeter Load Testby NovaTec-APM,之后下载Download JSON下载文件JMeter-InfluxDB-Writer-plugin-1.2.jar 放到lib\ext目录下在grafana中,上传刚下载的json文件到dashboard,将2个josn文件上传到grafana,导入到 dashboard 中
业务资源:资源监控面板配置参考这个文件:https://grafana.com/dashboards/4026 或https://grafana.com/dashboards/1152 或https://grafana.com/dashboards/5496(使用该模板,要用jm5.0) 通过jmeter搜索硬件资源:资源监控面板配置参考这个文件:https://grafana.com/dashboards/3967 或https://grafana.com/dashboards/928 通过System搜索
yum -y install sysstat
telegraf.conf 配置新增以下内容[global_tags][agent] interval = "15s" round_interval = true metric_batch_size = 1000 metric_buffer_limit = 10000 collection_jitter = "0s" flush_interval = "15s" flush_jitter = "0s" precision = "" debug = false quiet = false logfile = "" hostname = "" omit_hostname = false[[outputs.influxdb]] retention_policy = "" write_consistency = "any" timeout = "5s" username = "my login" password = "my password"[[inputs.cpu]] percpu = true totalcpu = true collect_cpu_time = true report_active = true[[inputs.disk]] ignore_fs = ["tmpfs", "devtmpfs", "devfs"][[inputs.diskio]][[inputs.kernel]][[inputs.mem]][[inputs.processes]][[inputs.swap]][[inputs.system]][[inputs.net]][[inputs.netstat]] [[inputs.sysstat]] activities = ["DISK"] [inputs.sysstat.options] -C = "cpu" -B = "paging" -b = "io" -d = "disk" "-n ALL" = "network" "-P ALL" = "per_cpu" -q = "queue" -r = "mem_util" -S = "swap_util" -u = "cpu_util" -v = "inode" -W = "swap" -w = "task"