简体   繁体   English

我们如何检查JVM过去的内存和CPU使用情况记录

[英]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. 我想在其中以图表形式显示网站的内存使用率和CPU使用率。 I read somewhere that JVM writes these data in a dump file which MAT tool use to show the result. 我在某处读到JVM将这些数据写入转储文件中,MAT工具使用该数据来显示结果。 So my question is where JVM dump this file and at what rate. 所以我的问题是,JVM在哪里以什么速率转储该文件。

Because i want to show on the graph the last 24 hour usage. 因为我想在图表上显示最近24小时的使用情况。 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. JVM中目前没有任何东西可以生成所需的数据流。 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). 您可以将诸如JVisualVM之类的探查器连接到您的应用程序,但这也可能会大大降低它的速度(也就是说,对于内存分析来说,它还不错...取决于您应用程序的非功能性要求)。

Two further options: 另外两个选择:

Write your own code using MBean stuff 使用MBean编写自己的代码

In a ScheduledExecutorService, run a periodic process that interrogates the JVM via the MBean interfaces . 在ScheduledExecutorService中,运行一个定期过程,该过程通过MBean接口询问JVM。 You can generate a heap dump that can be viewing in MAT. 您可以生成可以在MAT中查看的堆转储。

Use cron and jmap 使用cron和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. 您还可以使用jmap生成堆转储,并安排它在操作系统级别上一次运行一次。 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. AFAIK,如果要历史数据,则必须自己记录下来。 When you connect using VisualVM, you always start at the point you connected. 使用VisualVM进行连接时,始终从连接点开始。

The MAT tool can be used to examine a heap dump. MAT工具可用于检查堆转储。 It only works on a memory snapshot and is painful to use IMHO. 它仅适用于内存快照,并且难以使用IMHO。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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