JMeter長時間壓測的可視化監控報告配置(linux)

一、準備性能測試可視化監控系統程序安裝包

JMeter運行需要jdk環境,版本選擇1.8;以下軟件選擇官網下載:
[jmeter](https://archive.apache.org/dist/jmeter/binaries/)
[InfluxDB_linux版本](https://dl.influxdata.com/influxdb/releases/influxdb-1.7.7.x86_64.rpm)
[telegraf_LInux版本](https://dl.influxdata.com/telegraf/releases/telegraf-1.12.4-1.x86_64.rpm)
[Grafana](https://dl.grafana.com/oss/release/grafana-6.4.3-1.x86_64.rpm)
[grafana官網](https://grafana.com/grafana/download?platform=linux)
下載都是rpm,則使用yum install 直接安裝對應的rpm包即可,所幸這些軟件環境可以下載二進制安裝包直接解壓目錄配置環境變量使用即可。

二、組成可視化監控系統的工具介紹

  • 優先說明各軟件的使用及具體作用:
1、jmeter性能測試工具--添加監聽元件、寫入influxdb數據庫;
2、influxdb作爲數據源,收集數據爲測試報告分析提供數據來源;
3、telegraf收集系統資源數據並寫入influxdb數據庫,如:cpu、memory、disk、network等數據;
4、grafana可視化web系統,添加influxdb數據源,然後通過圖形化報表形式展示,提供郵件、釘釘預警等需求功能。
  • grafana可視化工具的介紹:
①可視化:快速和靈活的客戶端圖形具有多種選項。面板插件爲許多不同的方式可視化指標和日誌。
②報警:可視化地爲最重要的指標定義警報規則。Grafana將持續評估它們,併發送通知。
③通知:警報更改狀態時,它會發出通知。接收電子郵件通知。
④動態儀表盤:使用模板變量創建動態和可重用的儀表板,這些模板變量作爲下拉菜單出現在儀表板頂部。
⑤混合數據源:在同一個圖中混合不同的數據源!可以根據每個查詢指定數據源。這甚至適用於自定義數據源。
⑥註釋:註釋來自不同數據源圖表。將鼠標懸停在事件上可以顯示完整的事件元數據和標記。
⑦過濾器:過濾器允許您動態創建新的鍵/值過濾器,這些過濾器將自動應用於使用該數據源的所有查詢。

三、jmeter工具No-GUI模式做性能測試,如何做可視化監控報告?

  • jmeterHome\bin\jmeter -n -t jmeterHome\bin\MysqlTest.jmx -R 192.168.1.110,192.168.1.111,[省略後面的IP] -l Report\log-20190802.csv -e -o DashReport\htmlReport-20190802
  • 上面的命令可生成csv報告,還可以渲染成html報告,但是有一個問題,就是時間持續一長,那麼csv文件逐漸變大,html報告渲染就會很慢,機器內存喫不消,但是還有別的方式來獲取接口前後請求的時間差來展示報告,方案也不是很優化。

四、Grafana + InfluxDB + Telegraf可視化監控系統搭建過程

  1. 隨便找一個臨時目錄/op下載安裝包
[root@localhost /]# cd /opt
[root@localhost opt]# wget  https://dl.influxdata.com/telegraf/releases/telegraf-1.12.4-1.x86_64.rpm
[root@localhost opt]# yum install telegraf-1.12.4.1-1.x86_64.rpm
  1. 配置telegraf,安裝默認的配置文件路徑:/etc/telegraf/telegraf.conf
[root@localhost /]# vim /etc/telegraf/telegraf.conf
#優先配置本地influxdb本地數據庫地址
###############################################################################
#                            OUTPUT PLUGINS                                   #
###############################################################################
#幾個關鍵配置項需要去掉註釋
# Configuration for sending metrics to InfluxDB
[[outputs.influxdb]]
urls = ["http://127.0.0.1:8086"] # 切記influxdb數據庫端口不要衝突,配置一致
database = "telegraf" #自定義數據庫名字
## Write consistency (clusters only), can be: "any", "one", "quorum", "all".
## Only takes effect when using HTTP.
write_consistency = "any"
## Timeout for HTTP messages.
timeout = "5s" #
## HTTP Basic Auth #默認數據庫名稱爲賬號密碼,在grafana配置http認證時使用
username = "telegraf"
password = "telegraf"

然後再配置基本監控項
###############################################################################
#                            INPUT PLUGINS                                    #
###############################################################################

基本cpu、memory、disk默認選項,打開監控false改成true

3.先別急啓動服務,influxdb還未完成配置啓動

[root@localhost /]$ systemctl start telegraf.service
[root@localhost /]$ systemctl telegraf status  # 執行失敗,
    
# 另一種啓動方式:
[root@localhost /]$ nohup /usr/bin/telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d  &

4.同樣wget下載influxdb安裝文件並默認安裝,修改/etc/influxdb/influxdb.conf文件(jmeter通過2003端口連,可自定義)

[root@localhost /]# vim /etc/influxdb/influxdb.conf
[[graphite]]
enabled = true
database = "jmeter"
bind-address = ":2003"
protocol = "tcp"
consistency-level = "one"

[http]
# Determines whether HTTP endpoint is enabled.
enabled = true
# The bind address used by the HTTP service.
bind-address = ":8086"

5.啓動influxdb服務報錯,可能是需要創建執行influxdb系統用戶,未考證?

[root@localhost /]# systemctl start influxdb.service
[root@localhost /]# systemctl enable influxdb   # 添加開啓自啓
[root@localhost /]# systemctl influxdb status  #查看服務狀態
###發現啓動失敗:Failed to start InfluxDB is an open-source, distributed, time series database. &百度解答失敗!

6.解決啓動influxdb服務方案:yum install rpm安裝方式,需要找出服務安裝的路徑,找到最直接的啓動方式;

[root@localhost /]$ whereis influxdb
/usr/lib/influxdb /etc/influxdb
#找到兩個目錄:第一個是安裝服務的路徑,即啓動腳本路徑,第二個就是配置文件
#進入服務腳本目錄
[root@localhost /]$ cd /usr/lib/influxdb/scripts
[root@localhost scripts]$ vim influxdb.service
#找到ExecStart後面的啓動方式
[root@localhost /]$ /usr/bin/influxd -config /etc/influxdb/influxdb.conf
#執行報錯:8088端口被佔用,所以需要修改influxdb.conf配置文件,找到8088端口修改即可:#bind-address="127.0.0.1:8088", 打開註釋,改成8181

#再次啓動,需要在後臺運行,
[root@localhost /]$ nohup /usr/bin/influxd -config /etc/influxdb/influxdb.conf &

7.回到部署telegraf的第3步驟中,命令啓動telegraf.

8.安裝grafana,配置路徑:/etc/grafana/grafana.ini,默認端口3000,可以直接web訪問,默認賬號密碼:admin/admin

[root@localhost /]# vim /etc/grafana/grafana.ini
#修改配置文件,其中修改的所有開放的註釋,都在web界面settings中顯示
#每次修改配置文件之後,都需要重啓grafana服務:service grafana-server restart

#在grafana.ini中開啓告警
#################################### Alerting ############################
[alerting]
# Disable alerting engine & UI features
enabled = true   #開啓
# Makes it possible to turn off alert rule execution but alerting UI is visible
execute_alerts = true  #開啓

#grafana.ini中配置郵件服務器
#################################### SMTP / Emailing ##########################
[smtp]
enabled = true #是否開啓
host = smtp.mxhichina.com:465  #發送服務器地址,可以在郵箱的配置教程中找到
user [email protected] #賬號
# If the password contains # or ; you have to wrap it with trippel quotes. Ex """#password;"""
password =******  # 這個密碼是開啓smtp服務器生成的密碼,如qq郵箱
;cert_file =
;key_file =
#skip_verify = true #取消認證
from_address = [email protected] 
from_name = Grafana
# EHLO identity in SMTP dialog (defaults to instance_name)
;ehlo_identity = dashboard.example.com

使用grafana-cli工具安裝
#獲取可用插件列表
[root@localhost /]# grafana-cli plugins list-remote  
修改圖形爲餅狀
[root@localhost /]# grafana-cli plugins install grafana-piechart-panel
安裝其他圖形插件
[root@localhost /]# grafana-cli plugins install grafana-clock-panel
#鐘錶形展示
[root@localhost /]# grafana-cli plugins install briangann-gauge-panel
#字符型展示
[root@localhost /]# grafana-cli plugins install natel-discrete-panel
#服務器狀態
[root@localhost /]# grafana-cli plugins install vonage-status-panel

#卸載:
[root@localhost /]# grafana-cli plugins uninstall vonage-status-panel
#安裝和卸載後需要重啓grafana才能夠生效

#啓動:
[root@localhost /]# service grafana-server start
#停止:
[root@localhost /]# service grafana-server stop
#重啓:
[root@localhost /]# service grafana-server restart
#加入開機自啓動: 
[root@localhost /]# chkconfig --add grafana-server on

9.grafana只有graph支持告警通知,grafana的告警通知渠道有很多種,像Email、Teams、釘釘等都有支持。

#在上面的配置中,已經開啓了郵箱認證,並配置郵箱服務器,現在需要在grafana界面配置預警Alerting:Alert rules & notifications

#配置完成,發送郵件測試,查看日誌
[root@localhost /]$ cd /var/log/grafana/
[root@localhost /]$ tailf grafana.log 
#失敗failed to send notification...440 mail from account doesn't conform with authentication 

#繼續檢查配置文件:郵箱服務器是否配置正確,
# skip_verify = true #取消認證,還是註釋吧

save & test:發送成功:

10.補充一下,cpu監控指標、內存指標、

#CPU總量相關字段:
cpu_time_user:用戶進程用時。
cpu_time_system:系統內核用時。
cpu_time_idle:空閒CPU用時。
cpu_time_nice:優先級調度用時。
cpu_time_iowait:iowait用時。
cpu_time_irq:中斷用時。
cpu_time_softirq:軟中斷用時。
cpu_time_steal:Steal用時。
cpu_time_guest:Guest用時。
cpu_time_guest_nice:GuestNice用時。
cpu_time_cpu:CPU序號名稱。


#CPU用量相關指標:
cpu_usage_user:用戶用量百分比(0~100)。
cpu_usage_system:系統用量百分比(0~100)。
cpu_usage_idle:空閒百分比(0~100)。
cpu_usage_nice:優先級調度程序用量百分比(0~100)。
cpu_usage_iowait:IOwait時間佔比(0~100)。
cpu_usage_irq:中斷時間佔比(0~100)。
cpu_usage_softirq:軟中斷時間佔比(0~100)。
cpu_usage_steal:虛擬CPU的競爭等待時間佔比(0~100)。
cpu_usage_guest:虛擬進程的CPU用時佔比(0~100)。
cpu_usage_guest_nice:虛擬進程CPU調度用時佔比(0~100)。
cpu_usage_cpu:CPU序號名稱。

#內存
mem_total:內存總數。
mem_available:可用內存數。
mem_used:已用內存數。
mem_free:空閒內存。
mem_cached:用於緩存的內存。
mem_buffered:文件buffer內存。
mem_active:活躍使用的內存總數(包括cache和buffer內存)。
mem_inactive:空閒的內存數(包括free和avalible的內存)。
mem_used_percent:內存已用百分比(0~100)。
mem_available_percent:內存剩餘百分比(0~100)。

#磁盤
disk_path:磁盤路徑。
disk_device:磁盤設備名。
disk_fstype:文件系統類型。
disk_total:磁盤總大小。
disk_free:磁盤剩餘大小。
disk_used:磁盤用量。
disk_used_percent:磁盤已用百分比。
disk_inodes_total:總inode數量。
disk_inodes_fress:空閒的inode數量。
disk_inodes_used:使用的inode數量。

#磁盤讀寫
diskio_reads:磁盤被讀的總次數。
diskio_writes:磁盤被寫的總次數。
diskio_read_bytes:讀取的總數據量。
diskio_write_bytes:寫入的總數據量。
diskio_read_time:磁盤讀取總用時。
diskio_write_time:磁盤寫入總用時。
diskio_io_time:io總時間。
diskio_iops_in_progress:運行中的每秒IO數據量。
diskio_name:磁盤名稱。
diskio_serial:磁盤被讀的總次數。

#系統指標
system_load1:1分鐘平均load值。
system_load5:5分鐘平均load值。
system_load15:15分鐘平均load值。
system_n_users:用戶數。
system_n_cpus:CPU核數。
system_uptime:系統啓動時間。
system_uptime_format:格式化的系統啓動時間。
system_n_net_cards:網卡數。
system_n_disks:磁盤數。
system_n_services:總服務數。

#網絡連接
netstat_tcp_established:ESTABLISHED狀態的網絡鏈接數。
netstat_tcp_syn_sent:SYN_SENT狀態的網絡鏈接數。
netstat_tcp_syn_recv:SYN_RECV狀態的網絡鏈接數。
netstat_tcp_fin_wait1:FIN_WAIT1狀態的網絡鏈接數。
netstat_tcp_fin_wait2:FIN_WAIT2狀態的網絡鏈接數。
netstat_tcp_time_wait:TIME_WAIT狀態的網絡鏈接數。
netstat_tcp_close:CLOSE狀態的網絡鏈接數。
netstat_tcp_close_wait:CLOSE_WAIT狀態的網絡鏈接數。
netstat_tcp_last_ack:LAST_ACK狀態的網絡鏈接數。
netstat_tcp_closing:CLOSING狀態的網絡鏈接數。
netstat_tcp_none:NONE狀態的網絡鏈接數。
netstat_udp_socket:UDP狀態的網絡鏈接數。

#交換區
swap_total:Swap空間總量。
swap_used:Swap已使用空間。
swap_free:Swap空閒空間。
swap_in:Swap使用空間佔比。
swap_out:Swap空間換入數據量。
swap_used_percent:Swap空間換出數據量。

#內核
kernel_interrupts:內核中斷次數。
kernel_context_switches:內核上下文切換次數。
kernel_processes_forked:fork的進程數。
kernel_boot_time:內核啓動時間。
kernel_disk_pages_in:磁盤換入數量。
kernel_disk_pages_out:磁盤換出數量。
linux_sysctl_fs_aio_nr:當前 aio 請求數。
linux_sysctl_fs_aio_max_nr:最大允許的 aio 請求。
linux_sysctl_fs_dquot_nr:分配的磁盤配額項及空餘項。
linux_sysctl_fs_dquot_max:緩存的磁盤配額的最大值。
linux_sysctl_fs_super_nr:已分配的 super block 數。
linux_sysctl_fs_super_max:系統能夠分配的 super block 數。
linux_sysctl_fs_inode_nr:分配的 inode 數。
linux_sysctl_fs_inode_free_nr:空閒的 inode 數。
linux_sysctl_fs_inode_preshrink_nr:inode 預縮減數。
linux_sysctl_fs_dentry_nr:當前分配的 dentry 緩存數。
linux_sysctl_fs_dentry_unused_nr:未使用的 dentry 緩存數。
linux_sysctl_fs_dentry_age_limit:dentry 緩存被創建以來的時長。
linux_sysctl_fs_dentry_want_pages:系統需要的頁面數。
linux_sysctl_fs_file_nr:已分配、使用的和最大的文件句柄數。
linux_sysctl_fs_file_max:內核支持的最大file handle數量。

11.Grafana是個功能強大、展現層很漂亮的數據可視化監控工具,目前爲止grafana+influxdb+telegraf可視化監控系統平臺搭建完成。

五、設計JMeter性能測試腳本,添加Backend Listener監聽器,配置說明:

  • 啓動Jmeter創建測試計劃添加Backend Listener,配置監聽參數:
graphiteMetricsSender:org.apache.jmeter.visualizers.backend.graphite.TextGraphiteMetricsSender
graphiteHost:influxdb時序數據庫服務啓動ip地址
graphitePort:2003 #influxdb.conf配置文件可自定義端口
rootMetricsPrefix:jmeter #時序匹配規則
summaryOnly:false
samplersList:JDBC.* #監聽所有以JDBC名稱開頭的Request請求正則表達式,即sampler請求名稱
useRegexpForSamplersList:true  #支持上面的表達式
percentiles:90;95;99


influxdbMetricsSender:org.apache.jmeter.visualizers.backend.influxdb.HttpMetricsSender
influxdbUrl:http://127.0.0.1:8086/write?db=jmeter #數據庫服務數據寫入url
application:application name #應用名稱
measurement:jmeter #度量
summaryOnly:false
samplersRegex:.* #sampler匹配規則
percentiles:90;95;99
testTitle:Test name 
eventTags:	
  • grafana添加數據源之後,創建報表需要的字段
# 線程/虛擬用戶指標¶

<rootMetricsPrefix> test.minAT
最小活動線程
<rootMetricsPrefix> test.maxAT
最大活動線程
<rootMetricsPrefix> test.meanAT
平均活動線程
<rootMetricsPrefix> test.startedT
啓動線程
<rootMetricsPrefix> test.endedT
結束線程

#響應時間指標¶

<rootMetricsPrefix> <samplerName> .ok.count
採樣器名稱的成功響應數
<rootMetricsPrefix> <samplerName> .h.count
服務器每秒命中次數,此度量標準累積樣本結果和子結果(如果使用事務控制器,則應取消選中“生成父樣本”)
<rootMetricsPrefix> <samplerName> .ok.min
成功響應採樣器名稱所需的最短響應時間
<rootMetricsPrefix> <samplerName> .ok.max
成功響應採樣器名稱的最大響應時間
<rootMetricsPrefix> <samplerName> .ok.avg
採樣器名稱成功響應的平均響應時間。
<rootMetricsPrefix> <samplerName> .ok.pct <percentileValue>
計算成功採樣器名稱響應的百分比。每個計算值都有一個度量標準。
<rootMetricsPrefix> <samplerName> .ko.count
採樣器名稱的失敗響應數
<rootMetricsPrefix> <samplerName> .ko.min
採樣器名稱響應失敗的最短響應時間
<rootMetricsPrefix> <samplerName> .ko.max
採樣器名稱響應失敗的最大響應時間
<rootMetricsPrefix> <samplerName> .ko.avg
採樣器名稱響應失敗的平均響應時間。
<rootMetricsPrefix> <samplerName> .ko.pct <percentileValue>
爲採樣器名稱的失敗響應計算的百分比。每個計算值都有一個度量標準。
<rootMetricsPrefix> <samplerName> .a.count
採樣器名稱的響應數(ok.count和ko.count的總和)
<rootMetricsPrefix> <samplerName> .sb.bytes
已發送字節
<rootMetricsPrefix> <samplerName> .rb.bytes
接收字節
<rootMetricsPrefix> <samplerName> .a.min
採樣器名稱響應的最短響應時間(ok.count和ko.count的最小值)
<rootMetricsPrefix> <samplerName> .a.max
採樣器名稱響應的最大響應時間(ok.count和ko.count的最大值)
<rootMetricsPrefix> <samplerName> .a.avg
採樣器名稱響應的平均響應時間(ok.count和ko.count的平均值)
<rootMetricsPrefix> <samplerName> .a.pct <percentileValue>
爲採樣器名稱的響應計算的百分比。每個計算值都有一個度量標準。(根據合格和不合格樣品的總數計算)

The default percentiles setting on the百分比設置爲“ 90; 95; 99”,即3個百分點分別爲90%,95%和99%。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章