使用 jmx 和 java 5 以编程方式获取堆信息

发布于 2024-07-12 08:02:48 字数 101 浏览 4 评论 0原文

我知道使用 jconsole 附加到 java 进程来获取内存信息。 具体来说,我正在以编程方式获取有关各种内存池的信息,以便我可以将其绑定到监视应用程序。

谢谢!

I am aware of using jconsole to attach to a java process to get memory information. Specifically I'm after getting information on the various memory pools programatically so I can tie it to a monitoring application.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜雨飘雪 2024-07-19 08:02:48

谢谢 mattk - 我基本上就是这样做的:-)

List memBeans = ManagementFactory.getMemoryPoolMXBeans();           
for (Iterator i = memBeans.iterator(); i.hasNext(); ) {

    MemoryPoolMXBean mpool = (MemoryPoolMXBean)i.next();
    MemoryUsage usage = mpool.getUsage();

    String name = mpool.getName();      
    float init = usage.getInit()/1000;
    float used = usage.getUsed()/1000;
    float committed = usage.getCommitted()/1000;
    float max = usage.getMax()/1000;
    float pctUsed = (used / max)*100;
    float pctCommitted = (committed / max)*100;

}

Thanks mattk - I wound up doing basically this :-)

List memBeans = ManagementFactory.getMemoryPoolMXBeans();           
for (Iterator i = memBeans.iterator(); i.hasNext(); ) {

    MemoryPoolMXBean mpool = (MemoryPoolMXBean)i.next();
    MemoryUsage usage = mpool.getUsage();

    String name = mpool.getName();      
    float init = usage.getInit()/1000;
    float used = usage.getUsed()/1000;
    float committed = usage.getCommitted()/1000;
    float max = usage.getMax()/1000;
    float pctUsed = (used / max)*100;
    float pctCommitted = (committed / max)*100;

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文