Java Monitoring Tools & Metrics
Dive into Java monitoring and learn how to keep peak application performance
To keep your users happy – and business going – your Java app needs to be up and running smoothly, at all times. It’s not enough to just have it installed. You must look beyond the code and into the workings of the Java Virtual Machine (JVM) on an ongoing basis. By monitoring the JVM with the help of powerful Java monitoring tools, you can measure performance and detect issues that might affect your users’ experiences.
In this guide, we will strip JVM monitoring to the basics. Find out what Java monitoring implies, what metrics you should keep track of, and what are the best tools available today to help you ensure peak JVM performance.
JVM Performance: Critical Metrics to Monitor
You can measure up to hundreds of metrics from one single Java application, but you don’t need all of them when monitoring availability and performance. Indeed, you’ll probably use more when it’s time to pinpoint what’s wrong with the app, but for monitoring, there are a handful of critical metrics you should focus on – memory usage, garbage collection, and thread counts, data that is available via JMX. Not to mention, since monitoring and tuning go hand in hand, understanding how these specific metrics work will help you with JVM performance tuning.
Sematext JVM Monitoring makes monitoring easy by giving you GC, thread, and memory usage monitoring out-of-the-box.
Start your 30-day free trial See our plans
No credit card required – Up and running in no time
Memory usage is one of the most important Java resources to monitor when you want to prevent leaks and be able to troubleshoot unexpected issues.
JVM memory is divided into two types: heap memory and non-heap memory.
Seeing as heap memory availability is closely related to garbage collection (GC), it’s critical to keep an eye for garbage collection overhead as well. JVM runs a GC whenever it needs to reclaim space for application use by discarding unused objects. This process can eat up a lot of computer resources when deciding which memory to free and can lead to overhead and poor performance.
In this case, you need to monitor how often the GC runs and how long each cycle takes. Frequent and long GC cycles, especially in the old generation space, are a sign of decreased performance or can hide memory leaks. At the same time, applications require different GC pause time, be it longer or shorter, and monitoring will help you tune the GC accordingly.
Read more about how GC logs can help with monitoring – and by extension, tuning – from our post on Understanding Java Garbage Collection logging: What are GC logs and how to analyze them and check out what are the best practices you should follow to get the most out of your Java logs.
Monitoring JVM threads is just as important to ensure optimum app performance. Threads are how your app does the work. Threads are to JVM what processes are for operating systems, and just like when you have too many processes running, too many active threads can cause spikes in CPU utilization, causing application – and even server – slowdown. At the same time, a higher number of active threads leads to context switching among the CPUs, which will require even more resources from your processor.
Too many active threads can also indicate a poorly responding – or non-responsive backend. The obvious solution is to limit the number of threads. However, if you expect to receive many concurrent requests, you’ll need to create more threads or change your architecture to use non-blocking approach, to keep the response time as low as possible.
Free Open Source Java Monitoring Tools You Should Know
Now that you know what to watch for when it comes to monitoring your Java app, you just have to choose the monitoring tool that fits your needs. Here are the type of JVM monitoring tools you should consider using for your monitoring strategy:
1. Standard Java Profilers
Standard Java Profilers gives you visibility into all the JVM details (memory, CPU, threads, garbage collection) and browse heap dumps for fine-grained memory analysis. They track all method calls and memory usage allowing developers to dive into the call structure to quickly point down the areas that require most CPU and memory space.
With standard Java profilers, you can track down memory leaks as they allow you to run GC manually. You can then analyze memory usage and easily detect the objects that caused the memory failure. On the other hand, for this high level of detail, profilers use significant resources leading to application slowdown. Not to mention, they need to be connected with the monitored JVM, which can tamper usage to development environments.
Among the most popular tools, we could name Java VisualVM, Oracle Java Mission Control, and NetBeans Profiler.
2. Lightweight Java Transaction Profilers
Unlike standard Java profilers that monitor the performance of all methods across the entire app, lightweight profilers track the performance of individual web requests or transactions by injecting themselves right into the code.
Transaction profilers extract in-depth data for everything JVM-related, enabling you to track the flow of request to detect what method calls influenced your response time. However, they can only monitor your app during development. You’ll need an APM tool to track it in the QA and production environments.
With Sematext JVM monitoring you can profile any Java app on demand and find bottlenecks in yours and 3rd party applications and services in real time.
Try it free for 30 days See our plans
No credit card required – Get started in seconds
3. Application Performance Management (APM)
As development and production environments have different requirements, it’s critical to see how your app performs live in production as well. They collect only information that is highly relevant for performance concerns by aggregating timing statistics and sampling traces.
With APM tools, you can detect issues before going into production by monitoring the QA and Staging environments and debug production live by analyzing traces and exceptions. On the downside, it can be expensive to run APM on all QA/Staging and production servers and can slow down your app if they are not tuned accurately.
You can find both open source and commercial APM tools and good ones at that. Below, we’ve gathered some of the most popular open source APM solutions, to get you started:
Glowroot is a fast, clean, and easy to use open source Java APM. It enables you to trace capture for slow requests and mistakes, as well as log time follow for every user action, SQL catch, and aggregation. The tool further features a historical roll-up of all information with configurable maintenance and provides charts to visualize time breakdown and response time percentiles. With its interactive UI, you can track your app from desktop and mobile devices alike.
A free and open source APM solution, Pinpoint can help you monitor the performance of complex distributed systems written in Java and PHP. It looks at the structure of your system and how its components are interconnected, by tracing transactions across distributed applications. You can track active threads in real time, see request count and response patterns, as well as JVM performance metrics such as CPU and memory usage, garbage collection and JVM arguments.
JavaMelody is a free and open source APM tool designed to monitor Java or Java EE applications in QA and production environments. Seeing as it doesn’t include a database or profiling, JavaMelody is a lightweight solution which can be easily integrated into most applications.
Scouter calls itself the free and open source alternative to New Relic and AppDynamics’ APM. It shows metrics like user activity, service activity (TPS, response time, SQL profiling, and more), and resource consumption metrics (CPU, memory usage, heap memory).
Stagemonitor is a community-developed tool designed for clustered application stack. That means that you can use it to monitor development, testing, and production of Java-based applications that are running on multiple servers while keeping a low overhead. It integrates with time series databases (TDSB) such as Elasticsearch, Graphite, and InfluxDB. With Stagemonitor, you can view historical or live data from the cluster or the developer server, create custom alerts, and set thresholds for each metric. It also allows you to create custom dashboards to visualize and analyze metrics.
MoSKito is a complete toolset for DevOps to monitor the performance and behavior of Java applications. It collects, analyzes, and stores in real time all critical performance metrics such as memory, CPU, threads, caches, load distribution, and many more. It works with all major app servers such as Tomcat, JBoss, Jetty, WebLogic, doesn’t require code change and keeps your data private. You can set thresholds and notification alerts, record user activity, and provides a clean dashboard to monitor all application processes in multi nodes production environments.
With Sematext JVM Monitoring you can set thresholds and receive notification alerts whenever anomalies are detected, making troubleshooting easier.
Get started See our plans
Free for 30 days. No credit card required
4. Real User Monitoring (RUM)
There are many real user monitoring tools you can pick from, both standalone and as part of an APM. With our real user monitoring solution, Sematext Experience, you can track app performance and receive alerts whenever it detects anomalies that affect end-user experience.
5. Logging Solutions
Java logs provide useful insight into executed code, errors, potential issues, and many more. For instance, if you’re using Nginx or Apache as proxy servers, access logs will help you see how long it takes for a request to be processed. By aggregating access logs, you can detect what are the most popular, fastest, as well as slowest endpoints, are.
Analyzing logs using the command line may take time and doing that on multiple servers may be problematic. Instead, you can use log analyzers that do the hard work for you. For small datasets, you can use desktop tools like AWStats or Apache Log Viewer. Otherwise, for staging and production environments you should turn to a hosted logging solution, such as Sematext Logs, which collects logs from multiple sources in real time and sends you notifications whenever your errors occur.
However, while logs point out potential issues in the Java code, you can’t diagnose the performance side of the application without metrics. Which is why you should look for an integrated tool that allows you to correlate logs, metrics and real user monitoring data – such as Sematext Cloud – as it gives you full view over what your application is doing.
6. Application Memory Analysis Tools
We’ve already established that monitoring memory usage is critical to ensure your Java application runs smoothly. Consequently, heap dumps can help diagnose issues such as memory leaks, GC problems, and java.lang.OutOfMemoryError, and optimize memory usage.
You can load the heap dump file into memory analyzers such as Eclipse MAT and BHeapSampler to help identify the cause of memory-related performance problems. Profilers like JProfiler and YourKit can also help monitor memory usage.
Eclipse Memory Analyzer Tool (MAT)
Eclipse MAT is a powerful Java heap analyzer that helps to detect memory leaks and high memory usage to improve app performance. With this tool you can analyze productive heap dumps, calculate the retained sizes of objects, run a report to automatically extract leak suspects, and identifying who keeps the GC from collecting objects.
JVM Performance Monitoring with Sematext
Without a doubt, keeping your Java application performance up to speed is easier with the proper tools.
Sematext’s Java monitoring tool gives you in-depth insights into JVM critical metrics such as memory usage, GC, and threads to help you fine-tune JVM performance. It helps to detect bottlenecks faster by profiling your app in real time and identify slow database operations with transaction tracing.
If you’re looking to track your whole application’s health, try an all-in-one solution such as Sematext Cloud. Sematext Cloud brings all types of monitoring solutions under one roof – log management, tracing, infrastructure monitoring, and real user monitoring – to help you find bottlenecks faster, optimize your webapp, and reduce costs. Read more about it in our review about the best cloud monitoring tools available today.