Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.
/ jVaidhiyar Public archive
generated from padaiyal/jMavenProjectTemplate

A library for retrieving JVM related resource usage and configuration information.

License

Notifications You must be signed in to change notification settings

padaiyal/jVaidhiyar

Repository files navigation

jVaidhiyar

A library for retrieving JVM related resource usage and configuration information.
Report Bug/Request Feature

Contributors Forks Stargazers Issues Apache License
Maven build - Ubuntu latest Maven build - Windows latest Maven build - MacOS latest Publish to GitHub packages

Table of Contents
  1. About The Project
  2. Usage
  3. Roadmap
  4. Contributing
  5. License

About The Project

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

Usage

This project is to be used as a dependency to other projects. Adding this project as a dependency is as follows:

  1. Download the latest jar for this project from GitHub packages and place it within the dependant project.
  2. Add the following dependency tag to the pom.xml of the dependant 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>
    
    NOTE: Refer the GitHub packages / releases section for this repo to know the latest released version of this project.

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

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

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.

  1. Fork the Project.
  2. Create your branch. (git checkout -b contribution/AmazingContribution)
  3. Commit your changes. (git commit -m 'Add some AmazingContribution')
  4. Push to the branch. (git push origin contribution/AmazingContribution)
  5. Open a Pull Request.

License

Distributed under the Apache License. See LICENSE for more information.