Monitor the Health of Your System
Monitor the Health of Your System
If you are relatively inexperienced with performance, like this author was, here are some performance analysis programs to get you started.
Join the DZone community and get the full member experience.Join For Free
xMatters delivers integration-driven collaboration that relays data between systems, while engaging the right people to proactively resolve issues. Read the Monitoring in a Connected Enterprise whitepaper and learn about 3 tools for resolving incidents quickly.
When I first got a requirement to pick up tools in "Performance Monitoring" of any application, I thought it was an ardent task due to my unfamiliarity with this area. Primarily one gets overwhelmed by the expensive tools in the market and also lot of jargon floating around the internet which can keep someone away. Nevertheless, I decided to chalk out a plan to pick up the fundamentals of performance monitoring and tuning. In this article, some of the open source tools available to easily check the memory/CPU/thread usage for an application are discussed
First things first: This article assumes that the application is hosted on any Java based server (JBoss, WebLogic etc) which internally uses JVM to run and execute the programs. Basic knowledge of heap, stack, CPU usage must be familiar to the user.
Let's take a tour of some command line that is available by default with Oracle/SUN JDK.
Also, we will discuss GUI-based performance monitoring tools available as plugins in Eclipse IDE.
Assume a Java process is running on the system, you can find out the Java process using the command: jps -l. For example:
It is clear from the above example there are a few processes and the ID is shown mapped to the process. Once the Java process ID is obtained, we can use a variety of tools to get health of that particular process in terms of memory, CPU, and thread usage.
In the below example, the heap usage is shown at that particular instant of time using the "jmap" command.
The Eden Space section explains the used heap size by the Java process mentioned in the command which is 1145 MB out of available 1364MB. Note heap can resize based on the usage by JVM and the maxiumum heap as shown above is 4GB. The only issue with JMap is the command is intrusive that it temporarily stops the JVM to obtain the stats on the heap.
Alternatively, JStat command can also be used to get a snapshot of the heap usage in a similar way as JMap.
The heap utilization is the sum of the following parameters: OU+EU+S0U+S1U, where the variables mean the following:
OU — Old Space Utilization
EU — Eden Space Utilization
S0U — Survivor Space1 Utilization
S1U — Survivor Space2 Utilization
JStack Command: To get an idea of stack utilization by the process, we can use this command. Recall that JVM allocates stack space for function level variables and thread related parameters. All objects are however assigned space within the heap memory. Hence this command gives information stack memory usage.
For eg: jstack <javapid>
Let's now move on to GUI-based monitoring tools. One frequently-used tool is JConsole which gives a real time monitoring of the health of the system based on the process ID. Type jconsole on the command prompt that will open up the "Java Monitoring and Management Console."
In the captured screenshot, the memory usage graph is clearly shown with time on the X-axis and usage in MB on Y-axis, as well as information on the GC mechanism. Note the green boxes on the bottom. These are very helpful to give old, eden, and survivor space utilization. Clicking on the first bar above the "Heap" gives the Old Generation usage, the second gives Eden Usage, and third box gives Survivor Space utilization. Similarly the other tabs like "Threads" and "Classes" give the usage of the same on the system. The "VM Summary" gives overall summary about the JVM and is quite helpful in terms of live memory usage, committed memory, and threads running.
This is yet another interesting GUI tool that helps the developer monitor the health of the system. It is an Eclipse plugin and can be downloaded and updated in Eclipse. Visual VM is similar to JConsole except that the representation is quite clear and in a presentable format.
With the above discussed tools the developer can understand resource usage in terms of memory, threads, and stack usage. Since all these tools are open source and easily available, the first level analysis and debugging can be done using these. There are other tools like Memory Analyzer that can be downloaded from Eclipse marketplace which can give deep drive into resource usage on method level and can be quite useful. Using these tools can give the developer unusual resource usage, detect memory leaks over time and help avoid application crashes on the live system. Further, these tools can help developer point any code level mishaps that can be potential issue in the future. Hope these tools help others as much as it helped me in picking up this topic.
Opinions expressed by DZone contributors are their own.