telegraf1.8+influxdb1.6+grafana5.2 環境搭建 結合JMeter3.2node
參考地址:https://blog.csdn.net/laisinanvictor/article/details/80007356linux
1)配置yum源
#配置yum源 /etc/yum.repos.d/influxdb.repo
[influxdb]
name = InfluxDB Repository - RHEL \$releasever
baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.keyweb
2)安裝telegraf
#收集系統和服務的統計數據 , 並寫入到 InfluxDB數據庫 , 在須要監控的機器上安裝
yum -y install telegraf正則表達式
#配置文件路徑
/etc/telegraf/telegraf.confsql
#設置開機時啓動
systemctl enable telegraf.serviceshell
#啓動
systemctl start telegraf
systemctl 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"]apache
urls = ["http://10.1.5.49:8086"]json
## The target database for metrics; will be created as needed.
# database = "telegraf"vim
database = "ip_214_70_stat"
systemctl restart telegraf
#卸載telegraf(重裝時須要卸載)
rm -rf telegraf
rm -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 influxdb
systemctl status influxdb
#增長8083 8086端口,容許他經過防火強 influxdb:8083 8086
firewall-cmd --zone=public --add-port=8083/tcp --permanent
firewall-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]# influx
Connected to http://localhost:8086 version 1.6.3
InfluxDB 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=linux
wget 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.rpm
yum -y install fontconfig
yum -y install freetype*
yum -y install urw-fonts
安裝路徑 /usr/sbin/grafana-server
init.d路徑 /etc/init.d/grafana-server
環境變量文件路徑 /etc/sysconfig/grafana-server
ini 文件路徑 /etc/grafana/grafana.ini
Installs systemd service (if systemd is available) name grafana-server.service
日誌文件路徑 /var/log/grafana/grafana.log
sqllite3庫路徑 /var/lib/grafana/grafana.db
systemctl daemon-reload
systemctl start grafana-server
systemctl status grafana-server
#設置開機時啓動
systemctl enable grafana-server.service
#啓動
systemctl start grafana-server
systemctl 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 默認策略
一、新建數據保存策略
CREATE RETENTION POLICY "30d_jmeter" ON "influx_db" DURATION 30d REPLICATION 1 DEFAULT
二、刪除初始策略
DROP RETENTION POLICY "autogen" ON "influx_db"
三、顯示已有策略
SHOW RETENTION POLICIES on influx_db
#保存文件後,再次啓動 influxdb
systemctl start influxdb
#6-2建立jmeter數據庫
[root@monitor jmeter3.2]# influx
Connected to http://localhost:8086 version 1.6.3
InfluxDB shell version: 1.6.3
> create database influx_db
> use influx_db
Using database influx_db
> create user "admin" with password '123456' with all privileges
> create database graphite_db
> use graphite_db
Using database graphite_db
> create user "admin" with password '123456' with all privileges
> create database ip_214_70_stat
> use ip_214_70_stat
Using database ip_214_70_stat
> create user "admin" with password '123456' with all privileges
> show databases
name: databases
name
----
influx_db
_internal
ip_214_70_stat
> exit
#6-3在jmeter腳本文件中,新增監聽器:Backend Listener
方式1:
Backend Listener implementation:保持默認 org.apache.jmeter.visualizers.backend.graphite.GraphiteBackendListenerClient
Async Quenue size:取數據的間隔 5000毫秒
graphiteMetricsSender:保持默認 org.apache.jmeter.visualizers.backend.graphite.TextGraphiteMetricsSender
graphiteHost:influxdb機器的IP地址 ip
graphitePort:influxdb中配置的端口號 默認 2003
rootMetricsPrefix:influxdb中配置的表名 jmeter. 不要更改該名字
summaryOnly:改爲 false 是否統計總量
samplersList:改爲 .* 請求的URL關鍵字.*
useRegexpForSamplersList:改爲 true
percentiles:保持默認 90;95;99
#要配置對應某個請求的話,須要配置一下三項,不然保持默認就行
summaryOnly:改爲 false
samplersList:改爲 .*請求的URL關鍵字.* #summaryOnly=true,此處設置則失效,與請求的URL進行匹配,支持正則表達式,就是請求的名稱是什麼,這裏就要配置的好去對應它
useRegexpForSamplersList:改爲 true
方式2:
Backend Listener implementation:保持默認 org.apache.jmeter.visualizers.backend.influxdb.influxdbBackendListenerClient
Async Quenue size:取數據的間隔 5000毫秒
graphiteMetricsSender:保持默認 org.apache.jmeter.visualizers.backend.influxdb.HttpMetricsSender
graphiteHost:influxdb機器的IP地址 ip http://ip:8086/write?db=influx_db
application:應用名 好比:某某系統接口測試 influx_db
measurement: jmeter
summaryOnly:改爲 false 是否統計總量
samplersRegex:.* 正則表達式
percentiles:保持默認 50;90;95;99
testTitle:influx_db_testTitle
eventTags: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 startup
admin_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:influxDB
HTTP
URL:http://ip:8086
Access:Server(Default)
InfluxDB Details
Database:influx_db
#建立jmeter數據庫時,指定的用戶,該用戶可訪問該jmeter數據庫
user:admin Password:123456
Min time interval:10秒
#配置數據庫面板 Home->dashboard->Graph->Edit
#在編輯中,選擇數據庫 Data Source :middleground
#壓測運行完成,到圖標裏面就能夠看到對應數據庫了
jmeter.all.h.count 全部請求的TPS
jmeter.<請求名稱>.h.count 對應<請求名稱>的TPS
jmeter.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 sysstattelegraf.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"