Monitoring Cpu Usage: Jmeter's Performance Insights

how to monitor cpu usage in jmeter

Monitoring CPU usage is an important aspect of load testing, as it helps to ensure that the test system is running smoothly and the results are accurate. JMeter, a popular open-source load testing tool, offers a PerfMon plugin that allows users to monitor CPU and memory usage during load tests. This plugin provides valuable insights into the health of the servers being tested, helping to identify any performance bottlenecks. By following the steps outlined in the documentation and configuring the necessary settings, users can effectively monitor CPU usage and make informed decisions to optimise their test environment.

shundigital

Using the PerfMon plugin

The PerfMon plugin in JMeter allows you to monitor the performance metrics of remote machines during load testing. With this plugin, you can collect metrics such as CPU usage, memory utilization, disk I/O, and network activity from the machine running your application or server. This information is crucial for understanding system performance characteristics, identifying bottlenecks, and analyzing the impact of load on system resources.

Step 1: Download the PerfMon Plugin

Go to the JMeter Plugins website (https://jmeter-plugins.org/) and navigate to the "Downloads" section. Download the PerfMon plugin that matches your JMeter version.

Step 2: Install the PerfMon Plugin

Extract the downloaded archive and locate the .jar file in the extracted folder. Paste this .jar file into your JMeter installation's lib/ext directory.

Step 3: Restart JMeter

Restart JMeter to load the newly installed PerfMon plugin.

Step 4: Add PerfMon Metrics Collector to the Test Plan

Open your JMeter test plan and right-click on the Test Plan element in the "Tree" view. Select "Add", then "Listener", and finally, select "jp@gc - PerfMon Metrics Collector".

Step 5: Configure PerfMon Metrics Collector

In the PerfMon Metrics Collector listener, click the "Add" button to add a server. Enter the server details, including the hostname/IP and port, for the machine from which you want to collect performance metrics. Select the desired metrics to collect, such as CPU, Memory, Disk, and Network. Configure the polling interval and other options according to your requirements.

Step 6: Start the PerfMon Metrics Collector

Start the execution of your test plan. The PerfMon Metrics Collector will now collect the performance metrics from the specified remote machine.

Step 7: View Performance Metrics

After completing the test run, you can view the collected performance metrics. You can either view the metrics in real time during the test execution or save them to a file for further analysis. Ensure that the remote machine has the necessary permissions and firewall settings to allow JMeter to connect and retrieve the performance metrics.

By following these steps, you can effectively utilize the PerfMon plugin in JMeter to monitor CPU usage and other performance metrics during load testing.

shundigital

Configuring the PerfMon Metrics Collector

To configure the PerfMon Metrics Collector, follow these steps:

Step 1: Download the PerfMon Plugin

Go to the JMeter Plugins website and navigate to the "Downloads" section. Download the PerfMon plugin that matches your JMeter version.

Step 2: Install the PerfMon Plugin

Extract the downloaded file and locate the .jar file from the extracted folder. Paste this file into your JMeter installation's lib/ext directory.

Step 3: Restart JMeter

Restart JMeter to load the newly installed plugin.

Step 4: Add PerfMon Metrics Collector to the Test Plan

Open the JMeter test plan and right-click on the Test Plan element in the "Tree" view. Select "Add", then "Listener", and finally "jp@gc - PerfMon Metrics Collector".

Step 5: Configure the PerfMon Metrics Collector

Click the "Add" button in the PerfMon Metrics Collector listener to add a server. Enter the server details, including the hostname/IP address and port, for the machine from which you want to collect performance metrics. Select the desired metrics to collect, such as CPU, Memory, Disk, and Network. Configure additional options, such as the polling interval, according to your requirements.

Step 6: Start the PerfMon Metrics Collector

Start the test plan execution, and the PerfMon Metrics Collector will begin collecting performance metrics from the specified remote machine.

Step 7: View Performance Metrics

Once the test run is complete, you can view the collected performance metrics. You can either view the metrics in real time during the test execution or save them to a file for further analysis. Ensure that the remote machine has the necessary permissions and firewall settings to allow JMeter to connect and collect the required data.

shundigital

Running JMeter in non-GUI mode

To run JMeter in non-GUI mode, go into the JMeter bin folder and enter the following command:

Jmeter -n -t test.jmx -l testresults.jtl

Here's what each part of the command means:

  • `-n`: Specifies that JMeter should run in non-GUI mode
  • `-t`: Name of the JMX file that contains the Test Plan
  • `-l`: Name of the JTL (JMeter text logs) file to log results

There are several other parameters that can be used for running in the non-GUI mode, such as:

  • `-R`: List of remote servers
  • `-H`: Proxy server hostname or IP address
  • `-P`: Proxy server port

After completing the test, a JTL file will be generated in the jmeter2.12/bin folder. To view the test results, open JMeter in GUI mode, add a listener (e.g. View Results Tree), click the Browse button of the file name field in the listener, and open the testresult.jtl file.

shundigital

Server monitoring

To set up server monitoring in JMeter, follow these steps:

  • Install the PerfMon Plugin: Download the PerfMon plugin from the JMeter-Plugins website and install it by unpacking the JMeterPlugins-x.x.x.zip file into the lib/ext directory inside JMeter. Restart JMeter to load the new plugins.
  • Configure the PerfMon Metrics Collector: In JMeter, add the PerfMon Metrics Collector listener to your test plan. Enter the IP address or hostname of your server and set the default port to 4444. Save the test plan.
  • Run the Server Agent: Download the ServerAgent-2.2.1.zip file from the JMeter-Plugins website and copy it to your server. Extract the file and open the folder. Run the startagent.bat file on your testing server—this will send server performance data to the PerfMon plugin.
  • Start the Test: Go back to your machine running JMeter and click the Run button. The PerfMon listener will start collecting data, and you will see the graph update in real time.
  • Save the Results: You can save the graph in image format or as a CSV or Excel file by right-clicking on the graph.

Note that the server will not send its readings without samples, so you need to record samples and ensure they have a green status before interpreting the results.

shundigital

Analysing the results

Once you have configured JMeter to monitor CPU usage, you can start to analyse the results. The results will be displayed in a real-time chart, which you can save in image format or as a CSV or Excel file. The chart will show the CPU usage of the servers involved in the load test over time.

To interpret the results, you need to understand the metrics being displayed. The CPU usage is typically shown as a percentage, with the Y-axis representing the percentage of CPU usage and the X-axis representing time in seconds. You can also monitor other metrics such as memory, swap, disk I/O and network I/O.

It is important to monitor the health of the servers during a load test to ensure that they are not performance bottlenecks. A high resource usage for a test engine might negatively influence the results of the load test. For example, if the CPU utilisation exceeds 75%, it may be necessary to increase the number of threads or test engines.

Additionally, you can compare the results with other tools such as Task Manager, which also displays CPU and memory usage. This can help you validate the accuracy of the results and gain a better understanding of the server's performance.

By analysing the results and interpreting the metrics, you can identify any issues or bottlenecks in your system and make informed decisions to optimise the performance of your application.

Frequently asked questions

Written by
Reviewed by
Share this post
Print
Did this article help you?

Leave a comment