IT.en_US/Cloud_OuterArchitecture

Setting up JMeter on Linux using CLI Mode

동구멍폴로 2023. 2. 8. 23:48
반응형

Setting up JMeter on Linux using CLI Mode

 JMeter is an open-source tool that is widely used for performance and load testing of applications. It provides a GUI mode for easy testing, but it also supports a Command Line Interface (CLI) mode for more advanced and automated testing. In this article, we will focus on how to set up JMeter on Linux using CLI mode.

Prerequisites

Before we dive into setting up JMeter, there are a few prerequisites that need to be taken care of.

  1. Install Java: JMeter requires Java to be installed on your system. You can download and install the latest version of Java from here.
  2. Download JMeter: You can download the latest version of JMeter from here. After downloading, extract the archive to a directory of your choice.

Setting up JMeter

Now that we have taken care of the prerequisites, let's set up JMeter.

 

1) Start JMeter: To start JMeter, navigate to the directory where you have extracted the archive and run the following command:

./jmeter -n -t test.jmx -l test.jtl

 In the above command, -n is used to specify non-GUI mode, -t is used to specify the name of the test plan file, and -l is used to specify the name of the results file.

 

2) Create a Test Plan: A test plan is used to define the test elements in JMeter. To create a test plan, you need to write a script in XML format. Here is an example of a simple test plan:

<jmeterTestPlan version="1.2" properties="2.8"> 
    <hashTree> 
        <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true"> 
            <stringProp name="TestPlan.comments"></stringProp> 
            <boolProp name="TestPlan.functional_mode">false</boolProp> 
            <boolProp name="TestPlan.serialize_threadgroups">false</boolProp> 
            <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> 
                <collectionProp name="Arguments.arguments"/> 
            </elementProp> 
        </TestPlan> 
    <hashTree> 
        <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true"> 
            <stringProp name="ThreadGroup.on_sample_error">continue</stringProp> 
            <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true"> 
                <boolProp name="LoopController.continue_forever">false</boolProp> 
                <stringProp name="LoopController.loops">1</stringProp> 
            </elementProp> 
            <stringProp name="ThreadGroup.num_threads">1</stringProp> 
            <stringProp name="ThreadGroup.ramp_time">1</stringProp> 
            <boolPropname="ThreadGroup.scheduler">false</boolProp> 
            <stringProp name="ThreadGroup.duration"></stringProp> 
            <stringProp name="ThreadGroup.delay"></stringProp> 
        </ThreadGroup> 
    <hashTree> 
        <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="HTTP Request" enabled="true"> 
            <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> 
                <collectionProp name="Arguments.arguments"/> 
            </elementProp> 
            <stringProp name="HTTPSampler.domain"></stringProp> 
            <stringProp name="HTTPSampler.port"></stringProp> 
            <stringProp name="HTTPSampler.connect_timeout"></stringProp> 
            <stringProp name="HTTPSampler.response_timeout"></stringProp> 
            <stringProp name="HTTPSampler.protocol"></stringProp> 
            <stringProp name="HTTPSampler.contentEncoding"></stringProp> 
            <stringProp name="HTTPSampler.path"></stringProp> 
            <stringProp name="HTTPSampler.method">GET</stringProp>
            <boolProp name="HTTPSampler.follow_redirects">true</boolProp> 
            <boolProp name="HTTPSampler.auto_redirects">false</boolProp> 
            <boolProp name="HTTPSampler.use_keepalive">true</boolProp> 
            <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
            <boolProp name="HTTPSampler.monitor">false</boolProp>
            <stringProp name="HTTPSampler.embedded_url_re"></stringProp> 
        </HTTPSamplerProxy> 
    <hashTree/> 
    </hashTree> 
    </hashTree> 
    </hashTree> 
</jmeterTestPlan>

 This is just a simple example to give you an idea of how a test plan looks like. You can find more information on how to write a test plan from here.

 

3) Run the Test: Once you have created the test plan, you can run it using the following command:

/jmeter -n -t test.jmx -l test.jtl

 In this command, -n specifies non-GUI mode, -t specifies the name of the test plan file, and -l specifies the name of the results file.

반응형