There are actually many free and opensource tools for monitoring the jboss/wildfly application server. In this article we will learn how to create a monitoring shell using as little as jboss cli and bash and awk.

In some scenarios you have to monitor one or two key attributes of the application server configuration and receive an alert if the attribute has reached a critical value. In such scenario it is not worthy installing a complex tool, especially if you have some basic linux shell scripting.

We will learn how to monitor a few key attributes such as the available datasources and the free heap memory on the application server.

Let's start from the CLI commands. Here is how to monitor the number of available connections in a DB pool: 

/ -c "/subsystem=datasources/data-source=MYDS/statistics=pool:read-attribute(name="AvailableCount")" 


    "outcome" => "success",

    "result" => "100"


So, what we want to capture is the value of "result". With as little as some awk skills we can do that:

availpool=$(./ -c "/subsystem=datasources/data-source=MYDS/statistics=pool:read-attribute(name="AvailableCount")" | awk '/result/{gsub("\"", "", $3); print $3}')

if [ $availpool -le 5 ]


  echo "Database Connections Pool getting low! Reamining connections : $availpool" | mail -s "JBoss AS Alert"


Sometimes metrics can be calculated by simple arithmetic of other metrics. For example, if you want to be informed about the free memory on a server, you have to compute: max memory - memory used as follows:

[standalone@ /] /core-service=platform-mbean/type=memory:read-attribute(name=heap-memory-usage)


    "outcome" => "success",

    "result" => {

        "init" => 67108864L,

        "used" => 158278728L,

        "committed" => 341835776L,

        "max" => 477102080L



We will need to variables for this purpose:

heapused=$(./ -c "/core-service=platform-mbean/type=memory:read-attribute(name=heap-memory-usage)" | grep "used" | awk '{print $3}' | sed 's/L,//')

heapmax=$(./ -c "/core-service=platform-mbean/type=memory:read-attribute(name=heap-memory-usage)" | grep "max" | awk '{print $3}' | sed 's/L//')

freememory=$((heapmax - heapused))

if [ $freememory -le 128000000 ]


  echo "JVM Heap memory getting low: Remaining: $freememory bytes" | mail -s "JBoss AS Alert"


In the above script, we are sending an alert by mail if the amount of free heap memory drops below 128 MB. Easy peasy !

Please note that we have assumed that the script is going to connect automatically to the loopback address. If you don't want to include the IP Address and port of the Management interface in the script, we suggest entering the default value for it in jboss-cli.xml


Related articles available on

How to monitor JBoss CPU usage ?

  JBoss AS 7 users and WildFly can use JConsole in order to moni

How to monitor jboss graphically ?

  You’ve been using the JMX Console to access yourMBeans. In thi

How to monitor JBoss with snapshots?

  JBoss gives you the ability to capture data not only in real t

JBoss Alarm configuration

An Alarm indicates that an event (generally an error) has happene

Monitoring JBoss EJB Container

In this article we will show how easily you can write an Intercep

Monitor JBoss AS with Jolokia

Jolokia is a cool monitoring solution for accessing JMX MBeans re