简体   繁体   中英

How we check the past record of the usage of Memory and CPU by JVM

I want to write an admin tool for a website. In which i want to show the memory usage and CPU usage of the website in a graph. I read somewhere that JVM writes these data in a dump file which MAT tool use to show the result. So my question is where JVM dump this file and at what rate.

Because i want to show on the graph the last 24 hour usage. So how we can capture this data.

Looking for help

There's nothing at the moment inherent in the JVM that will produce the stream of data you want. You could leave a profiler such as JVisualVM hooked up to your app, but that might also slow it down considerably (that said, for memory profiling it's not so bad... depends on the non-functional requirements of your app).

Two further options:

Write your own code using MBean stuff

In a ScheduledExecutorService, run a periodic process that interrogates the JVM via the MBean interfaces . You can generate a heap dump that can be viewing in MAT.

Use cron and jmap

You can also use jmap to generate heap dumps and schedule that at the operating system level to run every once-in-a-while. This might be better if you don't want to, or can't, alter your code.

AFAIK, if you want historical data you must record this yourself. When you connect using VisualVM, you always start at the point you connected.

The MAT tool can be used to examine a heap dump. It only works on a memory snapshot and is painful to use IMHO.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM