1. 程式人生 > >telegraf1.8+influxdb1.6+grafana5.2 環境搭建 結合JMeter3.2

telegraf1.8+influxdb1.6+grafana5.2 環境搭建 結合JMeter3.2

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 \$releasever
baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key


2)安裝telegraf
#收集系統和服務的統計資料 , 並寫入到 InfluxDB資料庫 , 在需要監控的機器上安裝
yum -y install telegraf

#配置檔案路徑
/etc/telegraf/telegraf.conf


#設定開機時啟動
systemctl enable telegraf.service

#啟動
systemctl start telegraf
systemctl status telegraf

#例子:配置Telegraf(這裡用不到,所以不用配置)
[[email protected] 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 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資料庫
[[email protected] 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 預設策略
1、新建資料儲存策略
CREATE RETENTION POLICY "30d_jmeter" ON "influx_db" DURATION 30d REPLICATION 1 DEFAULT

2、刪除初始策略
DROP RETENTION POLICY "autogen" ON "influx_db"

3、顯示已有策略
SHOW RETENTION POLICIES on influx_db

#儲存檔案後,再次啟動 influxdb
systemctl start influxdb

#6-2建立jmeter資料庫
[[email protected] 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 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"