Java Application Performance monitoring using JAMon

Java Application Performance monitoring using JAMon

In this post we will discuss about Java Application Performance monitoring using JAMon API.

With growing data, performance of applications in production environment becomes important. Monitoring the performance of applications is essential to find out performance issues such as a transaction taking too long to complete. With performance monitoring we can find the methods which are taking a long time and those methods can be analysed for performance tuning.

What is JAMon?

The Java Application Monitor (JAMon) is a free Java API that can be used to easily monitor Java applications. Here is a link to a short video that gives an overview of JAMon.

JAMon can be used to determine application performance bottlenecks, user/application interactions, and application scalability. JAMon gathers summary statistics such as number of hits, execution times and simultaneous application requests. JAMon statistics are displayed in the sortable JAMon report.

JAMon API can be downloaded  here.

Advantages of JAMon

  • JAMon allows developers to track their applications performance and behavior using predefined modules. There are modules that automatically monitor : SQL, HTTP page requests, Spring beans, method invocations, Log4j, and Exceptions. Other modules are often easy to build.
  • In addition to using modules developers can monitor anything the modules don’t cover by using JAMon’s simple API methods ‘start/stop’ and ‘add’. Just place JAMon.jar in your classpath, and surround the code that you wish to monitor with the JAMon API’s start() and stop() methods.
  • Monitoring production systems is important because it is the only way we can see the frequency that our code is being executed by real users. Also, many times the configuration of the production environment is different from the test environment, so the performance numbers between the two environments may be considerably different. For both these reasons monitoring only the test environment is not enough. Unlike many monitoring tools, JAMon, due to its minimal performance overhead and multi-threaded capabilities, can be used in production systems. JAMon can be disabled at runtime, further reducing performance overhead. JAMon is also fast and doesn’t consume much memory and so it is suitable for production environments.

Monitoring your application

JAMon comes with several ways to monitor your application that require no application code changes. Usually all that is required is to…

  • add a line to an xml file,
  • put the jamon jar file in your classpath,
  • and install the JAMon war to view JAMon metrics/monitors (or you can view the metrics in a JMX console like jconsole).

Maven

The Maven pom dependency follows (substitute the appropriate version):

JAMon Example

JAMon gathers statistics for any code that comes between start() and stop() methods. Here is a simple example using JAMon API.

Below is the output of running the above program.

Here,

Hits=10 – A hit occurs whenever the start() method is called with an identical label. This can also be mapped to the number of times a method was called.

Avg =105.6 ms. – Total execution time / number of hits(i.e. Total/Hits)

Total=1056.0 ms. – Total execution time of all the hits

Min = 101.0 – Minimum execution time of a hit

Max = 110.0 – Minimum execution time of a hit

Interface monitoring example

You can monitor any java interface simply by passing an implementation of the interface to the JAMon monitor method, and then call methods on the object as you would if the object wasn’t monitored.  The class and method signature will appear as a label in the JAMon reports. Here is a sample program.

Here is the output of the above program.

Display Method
Display Method
Print Method
Print Method

LabelHitsAvgTotalStdDevLastValueMinMaxActiveAvgActiveMaxActiveFirstAccessLastAccessEnabledPrimaryHasListenersLabel
MonProxy-Interface (class=test.JamonInterfaceMonitoring): public abstract void test.TestInterface.display(), ms.2.01014.52029.00.70710678118654761015.01014.01015.00.01.01.0Wed Mar 30 15:43:06 IST 2016Wed Mar 30 15:43:07 IST 2016truefalsefalseMonProxy-Interface (class=test.JamonInterfaceMonitoring): public abstract void test.TestInterface.display(), ms.
MonProxy-Interface (class=test.JamonInterfaceMonitoring): public abstract void test.TestInterface.print(), ms.2.01015.02030.00.01015.01015.01015.00.01.01.0Wed Mar 30 15:43:08 IST 2016Wed Mar 30 15:43:09 IST 2016truefalsefalseMonProxy-Interface (class=test.JamonInterfaceMonitoring): public abstract void test.TestInterface.print(), ms.

Note: I have just made the output of the last println() to display in a table format. The actual output will be a string of HTML tags.

JAMon can be used for more than just monitoring the performance. For further study checkout the below links,

http://jamonapi.sourceforge.net/

http://www.javaperformancetuning.com/tools/jamon/

 

Thanks for reading. If you have any comments, post it in the comments section.

The following two tabs change content below.
Working as a Java developer since 2010. Passionate about programming in Java. I am a part time blogger.
One comment
  1. If we dont call monitor.stop() for 2 out of 10 hits in that case what will happen..? do the values for these 2 missing stop calls also add up or it is not added?

Add Comment

Required fields are marked *. Your email address will not be published.