Linux Monitor

GC stats, CPU, Swap In, Threads, Network etc.

 Download jmeter script here

Put these extensions under jmeter/lib/ext: jmeter

Before downloading, please read our terms and conditions

NOTE: This project has been developed over several years in my spare time and whilst working for several different clients. This is open source and has no commercial ties to any company I have worked for. Screen shots may reflect this as they are home made and may not be truly representative of a full commercial environment. However, these solutions have been used commercially and are known to work in those environments.

UPDATE: The CPU module uses TOP and I wasn’t running enough iterations to get proper CPU info. This has been fixed. If you don’t want average load (a better metric for measuring server load) I recommend not using this module anyway. Use the memory module instead, which uses vmstat and also gives CPU usage

I often need a quick look at a linux box in detail but only have access to more coarse metrics, gathered for general use, things like CPU sampled every 15 minutes or network bandwidth use, again with very course time scales. When using LoadRunner I will setup SiteScope and have a whole bank of servers to monitor. But this jmeter script is for a quick look on an ad-hoc basis at any server you have access to. It uses ssh with a key (so for jstat does need root access or similar) and can be setup in a jiffy.


Can collect and graph:

  1. Full set of GC stats if you have root access
  2. Memory including swap in from disk (indicative of performance issues)
  3. CPU including load average and CPU usage (100 - idle)
  4. Number of threads
  5. Network sent and received bytes/s


  • This jmeter script has been written for windows but will run on  linux. You may need to change some of the paths from using \ to /
  • Groovy
  • jmeter plugins
  • jmeter 2.9 (recommended) or 2.7 (minimum) 
  • ssh installed
  • The network module uses sleep for 1 second to get the delta over that period. Sleep is known not to be very accurate so bear this in mind.


Screenshots below show:

  1. The modules available
  2. The metrics collected under each module
  3. How to select metrics to be displayed
  4. How to configure the script

[I’ve appended the basic code on the bottom of this page so you can try out some of the calls immediately on your linux box.]

Available Modules


Metrics collected

GC Module output:


Memory module:


CPU module:



Threads module:


Network module:


Controlling metrics

You can turn whole modules on or off:


Or you can select which particular metrics to be displayed within a module:


Configuring the script

At the top of the script you need to supply a few details: the server to point to, what to grep for to find your application (defaults to java),  your ssh key location and whether to output data to csv files as well as display:


Under the main thread you can set up how often to run:


And linked to this is the data collection frequency setting, found at the bottom of the script:



Garbage collection

jstat -gc ${processId}

[you can get the process id of your java app by running ‘ps -ef | grep java’ or ‘pgrep java’ but watch out if you have more than one app running, you may want to be more selective with the grep term]

//info on gc data per index into array:
0,1 The output above contains the size of each survivor space (S0C && S1C)
2,3 the utilization of each survivor space (S0U && S1U)
4 the capacity of eden (EC)
5 the utilization of eden (EU)
6 the capacity of the old generation (OC)
7 the utilization of the old generation (OU)
8 the permanent generation capacity (PC)
9 the permanent generation utilization (PU)
10 the total number of young generation garbage collection events (YGC)
11 the total amount of time spent collecting objects in the new generation (YGCT)
12 the total number of old generation garbage collection events that have occurred (FGC)
13 the total amount of time spent collecting objects in the old generation (FGCT)
14 and the total time spent performing garbage collection.


vmstat 1 2

//watch out! First line gives values since boot time. Use second line (usage since delay= 1 second)

//info on vmstat data per index into array:
0 r: The number of processes waiting for run time.
1 b: The number of processes in uninterruptible sleep.
2 swpd: the amount of virtual memory used.
3 free: the amount of idle memory.
4 buff: the amount of memory used as buffers.
5 cache: the amount of memory used as cache.
6 si: Amount of memory swapped in from disk (/s).
7 so: Amount of memory swapped to disk (/s).
8 bi: Blocks received from a block device (blocks/s).
9 bo: Blocks sent to a block device (blocks/s).
10 in: The number of interrupts per second, including the clock.
11 cs: The number of context switches per second.
12 us: Time spent running non-kernel code. (user time, including nice time)
13 sy: Time spent running kernel code. (system time)
14 id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
15 wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle.

CPU (Using top)

//Again, top needs two iterations to give accurate data

top -b -n 2 -p 1 | tail -n 10

//put the top data we are interested in into an array
//info on top data per index into array:
0 Average load 1 minute
1 Average load 5 minutes
2 Average load 15 minutes
3 CPU Idle
4 Mem Total
5 Mem Used
6 Mem Free
7 Mem buffers


ps -eLf | wc -l

//info on ps data per index into array:
0 total number of threads


ifconfig eth0;sleep 1;ifconfig eth0

//received and transmitted worked out by diffing the two calls, which are made 1 second apart.

//info on data per index into array:
0 Receive (bytes/s)
1Transmit (bytes/s)

[Home] [About (CV)] [Contact Us] [JMeter Cloud] [webPageTest] [_64 images] [asset moniitor] [Linux Monitor] [Splunk ETL] [Splunk API] [AWS bash] [LR Rules OK] [LR Slave] [LR CI Graphs] [LoadRunner CI] [LR CI Variables] [LR Bamboo] [LR Methods] [LR CI BASH] [Bash methods] [Jenkins V2] [Streaming vid] [How fast] [Finding Issues] [Reporting] [Hand over] [VB Scripts] [JMeter tips] [JMeter RAW] [Dynatrace] [Documents] [FAQ] [Legal]

In the Cartesian Elements Ltd group of companies