A library for retrieving JVM related resource usage and configuration information.
Report Bug/Request Feature
Table of Contents
This library retrieves the following JVM related information:
- Thread Information (Name, Priority, ID, Stack, CPU usage etc)
- Heap usage information
- Non heap usage information
- VM options
- Heap dump
This project is to be used as a dependency to other projects. Adding this project as a dependency is as follows:
- Download the latest jar for this project from GitHub packages and place it within the dependant project.
- Add the following dependency tag to the pom.xml of the dependant project:
NOTE: Refer the GitHub packages / releases section for this repo to know the latest released version of this project.
<dependency> <groupId>org.java.padaiyal.utilities</groupId> <artifactId>vaidhiyar</artifactId> <version>2021.02.09</version> <scope>system</scope> <systemPath>${basedir}/<PATH_TO_JAR></systemPath> </dependency>
Here's a sample snippet showing the usage of JvmUtility:
// Get the heap or non heap memory info.
ExtendedMemoryUsage extendedMemoryUsage = JvmUtility.getHeapMemoryUsage(); // Or JvmUtility.getNonHeapMemoryUsage()
double memoryUsagePercentage = extendedMemoryUsage.getMemoryUsagePercentage();
long initMemoryInBytes = extendedMemoryUsage.getInit();
long committedMemoryInBytes = extendedMemoryUsage.getCommitted();
long maxMemoryInBytes = extendedMemoryUsage.getMax();
// Get the configured VM options.
JsonArray vmOptions = JvmUtility.getAllVmOptions();
// Information on the most recent garbage collection.
GarbageCollectionInfo[] gcInfos = JvmUtility.getGarbageCollectionInfo();
// IDs of all threads running in the JVM.
long[] threadIds = JvmUtility.getAllThreadsId();
// Get information on JVM threads.
int threadStackDepth = 10;
ExtendedThreadInfo[] extendedThreadInfos = JvmUtility.getAllExtendedThreadInfo(threadStackDepth);
double threadCpuUsage = extendedThreadInfos[0].getCpuUsage();
ThreadInfo threadInfo = extendedThreadInfos[0].getThreadInfo();
long threadMemoryAllocatedInBytes = extendedThreadInfos[0].getMemoryAllocatedInBytes();
// Generate a heap dump.
Path destinationDirectory = ...;
String heapDumpFileName = "heapDump.hprof";
boolean dumpOnlyLiveObjects = false;
JvmUtility.generateHeapDump(
destinationDirectory,
heapDumpFileName,
dumpOnlyLiveObjects
);
...
For more such examples, checkout JvmUtilityTest
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project.
- Create your branch. (
git checkout -b contribution/AmazingContribution
) - Commit your changes. (
git commit -m 'Add some AmazingContribution'
) - Push to the branch. (
git push origin contribution/AmazingContribution
) - Open a Pull Request.
Distributed under the Apache License. See LICENSE
for more information.