Add memory and processor metrics to JvmInformation
This commit is contained in:
parent
ae04896e76
commit
76b2a08804
1 changed files with 68 additions and 0 deletions
|
@ -25,6 +25,7 @@ import de.staropensource.sosengine.base.types.CodePart;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.MemoryUsage;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -117,4 +118,71 @@ public final class JvmInformation {
|
|||
public static List<@NotNull String> getArguments() {
|
||||
return ManagementFactory.getRuntimeMXBean().getInputArguments();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total amount of memory used by the JVM and the running application.
|
||||
* <p>
|
||||
* Note: This is an estimate.
|
||||
*
|
||||
* @return estimated total amount of used memory
|
||||
* @since 1-alpha1
|
||||
*/
|
||||
public static long getMemoryTotal() {
|
||||
return Runtime.getRuntime().totalMemory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum amount of memory usable by the running application.
|
||||
*
|
||||
* @return maximum amount of usable memory
|
||||
* @since 1-alpha1
|
||||
*/
|
||||
public static long getMemoryMax() {
|
||||
return Runtime.getRuntime().maxMemory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of free memory available to the running application.
|
||||
*
|
||||
* @return amount of free memory
|
||||
* @since 1-alpha1
|
||||
*/
|
||||
public static long getMemoryFree() {
|
||||
return Runtime.getRuntime().freeMemory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the memory usage of the heap.
|
||||
*
|
||||
* @return heap usage
|
||||
* @since 1-alpha1
|
||||
*/
|
||||
public static MemoryUsage getMemoryHeap() {
|
||||
return ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the memory usage of the stack.
|
||||
*
|
||||
* @return stack usage
|
||||
* @since 1-alpha1
|
||||
*/
|
||||
public static MemoryUsage getMemoryStack() {
|
||||
return ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of processors used by the JVM.
|
||||
* <p>
|
||||
* Note: The amount of processors used may change rapidly.
|
||||
* If your application scales resources based on the output of
|
||||
* this method, consider checking it's output often and scaling
|
||||
* resources accordingly.
|
||||
*
|
||||
* @return amount of available processors
|
||||
* @since 1-alpha1
|
||||
*/
|
||||
public static int getAvailableProcessors() {
|
||||
return Runtime.getRuntime().availableProcessors();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue