JBoss application server tutorials

  • Full Screen
  • Wide Screen
  • Narrow Screen
  • Increase font size
  • Default font size
  • Decrease font size

Monitor JBoss AS with Jolokia

 

Jolokia is a cool monitoring solution for accessing JMX MBeans remotely. It is different to JSR-160 connectors in so far as it is an agent based approach which uses JSON over HTTP for its communication in a REST-stylish way.

As any monitoring solution, an agent is required to interact with the application. Multiple agents are provided for different environments:

  • WAR Agent for deployment as web application in a JEE Server.
  • OSGi Agent for deployment in an OSGi container. This agent is packaged as a bundle and comes in two flavors (minimal, all-in-one).
  • Mule Agent for usage within a Mule ESB
  • JVM Agent which can be used with any Oracle/Sun JVM, Version 6

In this tutorial we will deploy the WAR agent on JBoss AS 7 and access the JMX deployed on the server. So as first step, move to the download page and download the WAR Agent. Once downloaded renamed it for your convenience as jolokia.war and drop it into the deployments folder of your standalone server.

First test: let's see if Jolokia responds correctly: issue the following GET request:

http://localhost:8080/jolokia/

You should see the following JSON response:

{
   "timestamp":1341845890,
   "status":200,
   "request":{
      "type":"version"
   },
   "value":{
      "protocol":"6.1",
      "agent":"1.0.4",
      "info":{
         "product":"jboss",
         "vendor":"RedHat",
         "version":"7"
      }
   }
}

Now let's try something more complex, but we need to know how the application server MBeans tree looks like. For this purpose you can issue the following GET request: http://127.0.0.1:8080/jolokia/list

This will produce a quite verbose list of the MBeans running on the server. However, it would be easier to grasp it with the JConsole tools which shows in the Mbeans tab all the Mbeans in a tree-like structure.
jolokia tutorial jboss
In order to read an MBean property you can use the REST's read path as in the following example, where we are investigating on the ExampleDS Datasource (Use the ignoreErrors=true argument in order to avoid failures if some attributes are unreadable).

http://localhost:8080/jolokia/read/jboss.as:subsystem=datasources,data-source=ExampleDS?ignoreErrors=true

{
   "timestamp":1341843446,
   "status":200,
   "request":{
      "mbean":"jboss.as:data-source=ExampleDS,subsystem=datasources",
      "type":"read"
   },
   "value":{
      "validConnectionCheckerProperties":null,
      "allocationRetryWaitMillis":null,
      "preparedStatementsCacheSize":null,
      "trackStatements":"\"NOWARN\"",
     . . . . .
      "setTxQueryTimeout":false,
      "backgroundValidationMillis":null,
      "maxPoolSize":null,
      "minPoolSize":null,
      "connectionUrl":"jdbc:h2:mem:test;DB_CLOSE_DELAY=-1",
      "jndiName":"java:jboss\/datasources\/ExampleDS",
      "newConnectionSql":null
   }
}

Another example, which digs into the AS Thread pool:

http://localhost:8080/jolokia/read/java.lang:type=Threading

{
   "timestamp":1341843401,
   "status":200,
   "request":{
      "mbean":"java.lang:type=Threading",
      "type":"read"
   },
   "value":{
      "ThreadContentionMonitoringSupported":true,
      "SynchronizerUsageSupported":true,
      "ThreadAllocatedMemoryEnabled":true,
      "ThreadCpuTimeEnabled":true,
      "PeakThreadCount":83,
      "CurrentThreadCpuTime":3884424900,
      "DaemonThreadCount":25,
      "CurrentThreadCpuTimeSupported":true,
      "TotalStartedThreadCount":96,
      "AllThreadIds":[
         101,
. . . . .
         8,
         5,
         4,
         3,
         2
      ],
      "ThreadContentionMonitoringEnabled":false,
      "ObjectMonitorUsageSupported":true,
      "ThreadAllocatedMemorySupported":true,
      "CurrentThreadUserTime":3775224200,
      "ThreadCount":43,
      "ThreadCpuTimeSupported":true
   }
}


In the following example we are using the exec command to execute an MBean command: in this case we will issue a redeploy command on the web application named myapp.war: http://localhost:8080/jolokia/exec/jboss.as:deployment=myapp.war/redeploy
Advertisement



Francesco Google+
Top Programming Sites
You are here Home