We are monitoring jvm metrics like heap, metaspace, threads and gc count and we are able to push these metrics to monitorng server like prometheus. Similarly we wanted to track Java native memory metrics(output of jcmd VM.sumary). My question is, is it possible to get these metrics by calling any jvm runtime classes?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Yes, it is possible to get NativeMemoryTracking summary directly from a Java application:
You'll have to parse the text output though.
Note that the most important parts of the NMT report can be tracked separately with the designated MBeans, including
See MemoryPoolMXBean and BufferPoolMXBean.
As I told in the comments, monitoring NMT output is not always helpful in practice, since it does not directly reflect the actual physical memory used by the process. NMT can report much less memory than the actual usage, or it can also report more memory than the process consumes from the OS perspective.
Since NMT can miss the large amount of OS memory consumed by a Java process, it's also useful to monitor the process' resident set size (RSS). On Linux this can be done by parsing
/proc/[pid]/stat
or/proc/[pid]/status
.I don't think there's a Java API for that. Your best bet might be to invoke the
jcmd <PID> VM.native_memory
command and parse its output. Of course, you need to enable native memory tracking for your process first.You can find many things you want in JMX. One of the answers to question "Why Use JMX Technology?" is "Monitor and manage the Java VM". In Oracle doc:
Allthough you don't mention
Micrometer
, I'd like to point out a little support library I have written for getting ahold of the procfs information like Resident Set Size (RSS). Perhaps you can extract some useful code out of it. Actually the procfs-code is not Micrometer-related (allthough not considered public API). Here it is: https://github.com/mweirauch/micrometer-jvm-extras