Jmeter(三十九) - 從入門到精通進階篇 - Jmeter配置文件的刨根問底 - 上篇(詳解教程)


1.簡介

為什么宏哥要對Jmeter的配置文件進行一下講解了,因為有的童鞋或者小伙伴在測試中遇到一些需要修改配置文件的問題不是很清楚也不是很懂,就算修改了也是模模糊糊的。更有甚者覺得那是禁地神聖不可輕犯不敢觸碰不敢修改,害怕修改錯了Jmeter運行不了了。聽宏哥的大膽修改大不了再重新安裝一個新的Jmeter,或者你有做備份的好習慣,在修改前備份好以后大膽修改,修改錯了直接使用備份文件恢復過來就可以。

2.配置文件

在%JMETER_HOME%\bin(or $JMETER_HOME/bin)目錄下搜索框中輸入:properties 會發現存在多個配置文件,如下圖所示:

宏哥接下來將按照其的重要性的先后順序進行一一講解和說明,其中最重要的是jmeter.properties.是Jmeter核心配置項文件,下面對其常用的一些配置項的設置進行總結與說明.

2.官方建議

將需要修改的屬性值,復制粘貼到同目錄下的 user.properties ,這里就是簡單的提一下,后邊再介紹user.properties文件

好處:當Jmeter升級時,可以避免修改項需要重新應用

3.jmeter.properties文件

由於這個文件太大了,宏哥在這里就翻譯了其中的一部分,有興趣的可以全部翻一下看看到底都是干什么的。

3.1文件許可證說明

3.1.1第1段——許可證說明

(1)原文

################################################################################
# Apache JMeter Property file
################################################################################

## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.

(2)譯文

# 示例user.properties文件
#
## Apache軟件基金會(ASF)下一個或多個許可
## 貢獻者許可協議。請參閱
## 此作品用於獲取關於版權所有權的附加信息。
## ASF根據Apache 2.0 版本許可證協議將此文件授權給您。
## (“許可證”);除非符合以下條件,否則不能使用此文件
## 許可證。您可以在
## 
## http://www.apache.org/licenses/LICENSE-2.0
## 
## 除非適用法律要求或書面同意,軟件
## 根據在“AS IS”BASIS上分發的許可證基礎上發布的,
## 無任何明示或暗示的保證或條件。
## 有關管理權限的特定語

3.2文件修改說明

3.2.1第2段——用於說明jmeter.properties文件

(1)原文

################################################################################
#
# THIS FILE SHOULD NOT BE MODIFIED
#
# This avoids having to re-apply the modifications when upgrading JMeter
# Instead only user.properties should be modified:
# 1/ copy the property you want to modify to user.properties from jmeter.properties
# 2/ Change its value there
#
################################################################################

# JMeter properties are described in the file
# http://jmeter.apache.org/usermanual/properties_reference.html
# A local copy can be found in
# printable_docs/usermanual/properties_reference.html

#Preferred GUI language. Comment out to use the JVM default locale's language.
#language=en


# Additional locale(s) to add to the displayed list.
# The current default list is: en, fr, de, no, es, tr, ja, zh_CN, zh_TW, pl, pt_BR
# [see JMeterMenuBar#makeLanguageMenu()]
# The entries are a comma-separated list of language names
#locales.add=zu

(2)譯文

################################################################################
#
# 這個文件不應該被修改
#
# JMeter這就避免了在升級JMeter時必須重新應用配置而再次修改
# user.properties文件的修改代替這里文件的修改:
# 1/ 從jmeter.properties文件中復制要修改的屬性到user.properties文件中修改
# 2/ 在user.properties文件中修改復制屬性的值
#
################################################################################

# 這個文件中描述了JMeter的配置
# 文件訪問地址:http://jmeter.apache.org/usermanual/properties_reference.html
# 這個文件的副本在本地也可以找到
# 本地文件的位置:printable_docs/usermanual/properties_reference.html

#首選GUI語言。注釋掉以使用JVM默認語言環境的語言。
#language=en


# 要添加到顯示列表的其他區域設置。
# 當前默認的列表: en, fr, de, no, es, tr, ja, zh_CN, zh_TW, pl, pt_BR
# [請參見JMeterMenuBar\35; MakeLanguageenu()]
# 這些條目是以逗號分隔的語言名稱列表
#locales.add=zu

3.3說明XML解析器

3.3.1第3段——用於說明XML解析器

(1)原文

#---------------------------------------------------------------------------
# XML Parser
#---------------------------------------------------------------------------

# Path to a Properties file containing Namespace mapping in the form
# prefix=Namespace
# Example:
# ns=http://biz.aol.com/schema/2006-12-18
#xpath.namespace.config=


# XPath2 query cache for storing compiled XPath queries
#xpath2query.parser.cache.size=400

(2)譯文

#---------------------------------------------------------------------------
# XML 解析器
#---------------------------------------------------------------------------

# 包含格式為prefix = Namespace的名稱空間映射的屬性文件的路徑。例子:
# prefix=Namespace
# Example:
# ns=http://biz.aol.com/schema/2006-12-18
#xpath.namespace.config=


# 查詢緩存,用於存儲編譯的XPath查詢,默認為400
#xpath2query.parser.cache.size=400

3.4說明SSL配置

3.4.1第4段——用於說明SSL配置

(1)原文

#---------------------------------------------------------------------------
# SSL configuration
#---------------------------------------------------------------------------

## SSL System properties are now in system.properties

# JMeter no longer converts javax.xxx property entries in this file into System properties.
# These must now be defined in the system.properties file or on the command-line.
# The system.properties file gives more flexibility.

# By default, SSL session contexts are now created per-thread, rather than being shared.
# The original behaviour can be enabled by setting the JMeter property to true
#https.sessioncontext.shared=false

# Be aware that https default protocol may vary depending on the version of JVM
# See https://blogs.oracle.com/java-platform-group/entry/diagnosing_tls_ssl_and_https
# See https://bz.apache.org/bugzilla/show_bug.cgi?id=58236
# Default HTTPS protocol level:
#https.default.protocol=TLS
# This may need to be changed here (or in user.properties) to:
#https.default.protocol=SSLv3

# List of protocols to enable. You may have to select only a subset if you find issues with target server.
# This is needed when server does not support Socket version negotiation, this can lead to:
# javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
# java.net.SocketException: Connection reset
# see https://bz.apache.org/bugzilla/show_bug.cgi?id=54759
#https.socket.protocols=SSLv2Hello SSLv3 TLSv1

# Control if we allow reuse of cached SSL context between iterations
# set the value to 'false' to reset the SSL context each iteration
# Deprecated since 5.0
#https.use.cached.ssl.context=true

# 
# Reset HTTP State when starting a new Thread Group iteration which means:
# true means next iteration is associated to a new user
# false means next iteration is associated to same user
# true involves: 
# - Closing opened connection
# - resetting SSL State 
#httpclient.reset_state_on_thread_group_iteration=true

# Start and end index to be used with keystores with many entries
# The default is to use entry 0, i.e. the first
#https.keyStoreStartIndex=0
#https.keyStoreEndIndex=0

(2)譯文

#---------------------------------------------------------------------------
# SSL 配置
#---------------------------------------------------------------------------

## SSL系統屬性現在位於system.properties中

# JMeter不再轉換javax。jmeter.properties中的xxx屬性條目 進入系統屬性
# 現在必須在system.properties文件或命令行中定義它們。
# 在 system.properties文件提供了更多的靈活性。

# By default, SSL session contexts are now created per-thread, rather than being shared.默認情況下,SSL會話上下文現在是按線程創建的,而不是共享的。
# 可以通過將此屬性設置為true來啟用原來行為。默認為:false
#https.sessioncontext.shared=false

# 請注意,https默認協議可能會根據JVM的版本而有所不同。
# See https://blogs.oracle.com/java-platform-group/entry/diagnosing_tls_ssl_and_https
# See https://bz.apache.org/bugzilla/show_bug.cgi?id=58236
# 默認HTTPS協議級別:
#https.default.protocol=TLS
# 這可能需要(或者在user.properties文件中) 更改為:
#https.default.protocol=SSLv3

# 要啟用的協議列表。如果發現目標服務器有問題,則可能只需要選擇一個子集。
# 如果服務器不支持Socket版本協商,則需要這樣做,這可能導致以下錯誤: 
# javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
# java.net.SocketException: Connection reset
# see https://bz.apache.org/bugzilla/show_bug.cgi?id=54759
#https.socket.protocols=SSLv2Hello SSLv3 TLSv1

# 控制是否允許在迭代之間重用緩存的SSL上下文。
# 將值設置為false可在每次迭代時重置SSL上下文。默認為:true
# Deprecated since 5.0
#https.use.cached.ssl.context=true

# 
# 開始新的線程組迭代時,重置HTTP狀態。
# true表示下一次迭代與新用戶相關聯。
# false表示下一次迭代與同一用戶相關聯。
# true 涉及: 
# - 關閉打開的連接
# - 重置SSL狀態
#httpclient.reset_state_on_thread_group_iteration=true

# 與具有許多條目的密鑰庫一起使用的起始索引和結束索引。
# 默認值是使用條目0,即第一個。
#https.keyStoreStartIndex=0
#https.keyStoreEndIndex=0

下邊宏哥就挑一些常用和重要的和童鞋們或者小伙伴們分享一下。

4.GUI語言

4.1Windows系統

4.1.1方法一

——修改Options
依次點擊Options-->Choose Language-->Chinese(Simplified)即可配置成中文簡體,需注意的是該方法只對當次生效,下次打開Jmeter依然是英文。如需永久生效,請使用下面兩種方法。

4.1.2方法二

——修改jmeter.properties文件

打開jmeter解壓縮文件下的bin目錄,找到jmeter.properties文件並用編輯器打開,
在#language=en下面插入一行language=zh_CN,修改后保存
重新啟動Jmeter界面顯示為中文簡體

注意:

功能:設置JMeter GUI界面的顯示語言 說明:若沒有設置,則使用JVM(Java虛擬機)設置的locale語言.
4.1.3方法三

——修改jmeter.bat文件

使用編輯器打開JMeter啟動文件jmeter.bat
將set JMETER_LANGUAGE=-Duser.language="en" -Duser.region="EN"修改成set JMETER_LANGUAGE=-Duser.language="zh" -Duser.region="CN",保存代碼
重新啟動Jmeter界面顯示為中文簡體

4.2Linux系統

在Linux中可以設置JVM的locale:

[root@localhost ~]# locale
LANG=zh_CN.UTF-8
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=
[root@localhost ~]# vi /etc/sysconfig/i18n
[root@localhost ~]# cat !$
cat /etc/sysconfig/i18n
LANG="zh_CN.UTF-8"
[root@localhost ~]#

注意:此配置項只能在jmeter.properties中設置才有效。

5.GUI圖標放大比例設置

5.1JMeter GUI界面布局

當JMeter以GUI模式運行時,窗口主要由三部分構成:
1.功能區
上方菜單欄,下方工具欄。菜單欄展示了JMeter提供的功能菜單,而工具欄中的圖標
是常見功能的快捷方式。
2.視圖區
以樹狀結構呈現JMeter元素,其中“Test Plane”是樹的根節點,每一個節點就是一個JMeter元素。
在此區域可以添加、刪除節點或者通過拖曳調整節點的位置。
3.內容區
當在視圖區選中一個JMeter元素節點時,內容區則會相應地顯示該元素的內容。
這時可以對其內容進行查看、設置等操作。

5.2GUI圖標放大比例設置

jmeter.hidpi.mode=true #開啟視網膜模式
jmeter.hidpi.scale.factor=1.2 #將圖標放大1.2倍

5.3功能區工具欄圖標大小設置

#工具欄圖標默認size: 22x22
#可用size: 22x22, 32x32, 48x48
jmeter.toolbar.icons.size=32x32

5.4視圖區目錄樹圖標大小設置

#目錄樹圖標默認size: 19x19
#可用size: 19x19, 24x24, 32x32, 48x48
jmeter.tree.icons.size=24x24

5.5內容區編輯字體設置

#調整JMeter內容區的編輯字體
jsyntaxtextarea.font.family=consolas  #默認Hack,太難看,使用經典的consolas
jsyntaxtextarea.font.size=18  #這兩個配置項必須同時設置才有效

5.6響應數據編碼設置

#響應數據編碼默認為ISO-8859-1(即Latin-1)
sampleresult.default.encoding=UTF-8  #設置為UTF-8,避免出現亂碼

6.添加JMeter元素快捷鍵設置

#配置添加JMeter元素時使用的快捷鍵,最多支持10個.
#在windows上可以使用 Ctrl+0  Ctrl+1 ... Ctrl+9
#在macOS上可以使用 Command+0 Command+1 ... Command+9
gui.quick_0=ThreadGroupGui     #新增線程組
gui.quick_1=HttpTestSampleGui  #新增HTTP取樣器
gui.quick_2=RegexExtractorGui  #新增正則表達式提取器
gui.quick_3=AssertionGui       #新增響應斷言
gui.quick_4=ConstantTimerGui   #新增常量定時器
gui.quick_5=TestActionGui      #新增測試活動
gui.quick_6=JSR223PostProcessor  #新增JSR223 后置處理程序
gui.quick_7=JSR223PreProcessor   #新增JSR223 預處理程序
gui.quick_8=DebugSampler         #新增調試取樣器
gui.quick_9=ViewResultsFullVisualizer #新增察看結果樹

7.HTTP Request Post Content-Type設置

# Should JMeter add to POST request content-type header if missing:
# Content-Type: application/x-www-form-urlencoded
# Was true before version 5.0
post_add_content_type_if_missing=true
說明:此配置項在JMeter5.0以前默認值為true,以后版本默認為false,故在5.0以后的版本中
發送POST請求,將參數放在"body data"中,且沒有設置
Content-Type時,默認為Content-Type值為"text/plain",而不是"application/x-www-form-urlencoded".

8.小結

1.宏哥在設置GUI語言的時候發現,宏哥的jmeter.properties文件中設置注釋掉了,而且宏哥用的是win10默認的locale語言默認是中文但是宏哥啟動jmeter后,發現GUI的語言還是英文。經過一系列研究發現是因為jmeter.bat文件中還有語言設置。

使用編輯器打開JMeter啟動文件jmeter.bat
將set JMETER_LANGUAGE=-Duser.language="en" -Duser.region="EN"修改成set JMETER_LANGUAGE=-Duser.language="zh" -Duser.region="CN",保存代碼
重新啟動Jmeter界面顯示為中文簡體

2.jvm中的語言都是取得系統locale語言
(1)Windows系統

a.輸入命令:java -X

b.輸入命令:java -XshowSettings:locale

(2)Linux系統

a.輸入命令:java -X

b.輸入命令:java -XshowSettings:locale

好了今天就分享到這里吧,希望大家喜歡,同時也感謝您耐心的閱讀本文!!!

 

您的肯定就是我進步的動力。如果你感覺還不錯,就請鼓勵一下吧!記得隨手點波  推薦  不要忘記哦!!!

別忘了點 推薦 留下您來過的痕跡

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM