Java® was presented as a no-cost solution with the benefit of being a “Write Once, Run Anywhere” language when it was released publicly in 1995 by Sun Microsystems®. Many years and almost as many versions later, Java is now one of the most prominent computer languages in the industry. Java-based applications power banking, commerce, and a host of other sectors.
As with any computer system, Java applications and services are invaluable when running as they should, and as engineers, it is our job to ensure that they are robust and keep running as efficiently and effectively as possible. In this article, we’re going to look at one key element of keeping your Java applications operating properly. Monitoring is the process whereby a computer system is configured to report on key metrics, which are analyzed to display the near real-time health of the system, and integrated with logic constraints to alert operations personnel when the system begins trending towards less-than-optimal performance.
Developing a Solid Monitoring Plan
Whether you are implementing a new system or maintaining an existing Java-based ecosystem, having a comprehensive and well thought-out monitoring plan is vital to the success of your project. There are two types of metrics that we need to be concerned with—those related to the Java Virtual Machine (JVM), and those related to the underlying infrastructure.
Specific Considerations for Java
Let’s look at specific metrics that should be monitored on a Java-based system, as well as the reasons why they are important.
Java Heap Usage
The Heap is the allocated portion of the computer’s memory for the creation and storage of objects. The JVM will be unable to create additional objects if this space has already been consumed. At the very least, the JVM may pause and experience a degradation in performance, or the JVM may abruptly terminate.
Potential problems in the application (which can result in problems for Heap usage) are the inadequate allocation of Heap memory when the application is started, or a memory leak. In the case of the latter, a constant increase in Heap usage over time is often observed.
Garbage Collection
Closely related to the Heap is the Garbage Collector (GC). This process is responsible for identifying objects that are no longer in use, and can be removed to free up space for the application. This necessary process is very resource-intensive, so if the JVM is initiating it too often, or if it is being run for extended periods, it can be indicative of a memory leak, or simply necessary additional tuning.
GC metrics are different for each application, and monitoring them over time will help to identify trends and indicate when improvements may be needed.
Active Threads
Threads are how applications process their work. Highly performant applications can complete their work quickly and free up their threads. A high count of active threads may indicate that the system is processing a higher-than-expected load, and may lead to decreased performance over time.
Response Time
Computer applications are written to perform tasks quickly and efficiently. Response time is a direct measurement of how quickly an application is responding to requests. Analyzing this metric over time allows you to create a performance baseline, and deviations from this baseline may indicate that something is wrong—either with the load being processed by the server, or there could be an internal issue.
Key Infrastructure Metrics
In addition to monitoring the health of the JVM, it is also important to monitor the supporting infrastructure and any supporting systems. For a Java application, this would include the application server as well. Some examples would be Jetty®, Netty, or Tomcat®.
Infrastructure Specific Metrics
- CPU Utilization
- Memory Usage/RAM
- Available Threads
- Open File Descriptors
- Database Connections
- SLA
- Latency
- Success of API Endpoints
- Average Response Times
- Errors and Exceptions
- Health and Status of Dependencies