以编程方式获取类似jmap(即堆使用情况)的信息?

发布于 2024-10-15 21:30:45 字数 1962 浏览 2 评论 0原文

我想以编程方式获取以下信息(特别是当前使用情况),以便我可以将其显示在应用程序的“健康状态”页面中(是的,我知道它经常更改)。该代码在 JBoss 5.1 内运行。

$ jmap -heap 25837

[...]
Heap Configuration:
   MinHeapFreeRatio = 40
   MaxHeapFreeRatio = 70
   MaxHeapSize      = 1572864000 (1500.0MB)
   NewSize          = 1048576 (1.0MB)
   MaxNewSize       = 4294901760 (4095.9375MB)
   OldSize          = 4194304 (4.0MB)
   NewRatio         = 2
   SurvivorRatio    = 8
   PermSize         = 16777216 (16.0MB)
   MaxPermSize      = 268435456 (256.0MB)

Heap Usage:
PS Young Generation
Eden Space:
   capacity = 332005376 (316.625MB)
   used     = 314099536 (299.5486602783203MB)
   free     = 17905840 (17.076339721679688MB)
   94.60676203026303% used
From Space:
   capacity = 42008576 (40.0625MB)
   used     = 5472256 (5.21875MB)
   free     = 36536320 (34.84375MB)
   13.026521060842434% used
To Space:
   capacity = 43122688 (41.125MB)
   used     = 0 (0.0MB)
   free     = 43122688 (41.125MB)
   0.0% used
PS Old Generation
   capacity = 456589312 (435.4375MB)
   used     = 316167864 (301.5211715698242MB)
   free     = 140421448 (133.91632843017578MB)
   69.24556832377189% used
PS Perm Generation
   capacity = 153092096 (146.0MB)
   used     = 93768952 (89.42504119873047MB)
   free     = 59323144 (56.57495880126953MB)
   61.25002821830854% used

我检查了 JMX 控制台,希望有一个包含此信息的 MBean,但是 javax.management.j2ee.statistics.Stats 的信息非常薄弱:

org.jboss.management.j2ee.statistics.JVMStatsImpl [ {UpTime=[ 1097449:UpTime(description: Time the VM has been running, units: MILLISECOND, startTime: 1296748847668, lastSampleTime: 1296749945117) ], HeapSize=BoundedRangeStatistics[ [low: 0, high: 828243968, current: 828243968]HeapSize(description: Size of the VM's heap, units: Bytes, startTime: 1296748847672, lastSampleTime: 1296749945117), BoundryStatistics[ 0, 0, HeapSize(description: Size of the VM's heap, units: Bytes, startTime: 1296748847670, lastSampleTime: 0) ] ]} ]  

I'd like to get the following information (particularly the current usage) programmatically so I can display it in a "health status" page in the application (and yes, I know it changes frequently). The code runs inside JBoss 5.1.

$ jmap -heap 25837

[...]
Heap Configuration:
   MinHeapFreeRatio = 40
   MaxHeapFreeRatio = 70
   MaxHeapSize      = 1572864000 (1500.0MB)
   NewSize          = 1048576 (1.0MB)
   MaxNewSize       = 4294901760 (4095.9375MB)
   OldSize          = 4194304 (4.0MB)
   NewRatio         = 2
   SurvivorRatio    = 8
   PermSize         = 16777216 (16.0MB)
   MaxPermSize      = 268435456 (256.0MB)

Heap Usage:
PS Young Generation
Eden Space:
   capacity = 332005376 (316.625MB)
   used     = 314099536 (299.5486602783203MB)
   free     = 17905840 (17.076339721679688MB)
   94.60676203026303% used
From Space:
   capacity = 42008576 (40.0625MB)
   used     = 5472256 (5.21875MB)
   free     = 36536320 (34.84375MB)
   13.026521060842434% used
To Space:
   capacity = 43122688 (41.125MB)
   used     = 0 (0.0MB)
   free     = 43122688 (41.125MB)
   0.0% used
PS Old Generation
   capacity = 456589312 (435.4375MB)
   used     = 316167864 (301.5211715698242MB)
   free     = 140421448 (133.91632843017578MB)
   69.24556832377189% used
PS Perm Generation
   capacity = 153092096 (146.0MB)
   used     = 93768952 (89.42504119873047MB)
   free     = 59323144 (56.57495880126953MB)
   61.25002821830854% used

I checked the JMX console in the hope there is an MBean with this info, but javax.management.j2ee.statistics.Stats is very thin on information:

org.jboss.management.j2ee.statistics.JVMStatsImpl [ {UpTime=[ 1097449:UpTime(description: Time the VM has been running, units: MILLISECOND, startTime: 1296748847668, lastSampleTime: 1296749945117) ], HeapSize=BoundedRangeStatistics[ [low: 0, high: 828243968, current: 828243968]HeapSize(description: Size of the VM's heap, units: Bytes, startTime: 1296748847672, lastSampleTime: 1296749945117), BoundryStatistics[ 0, 0, HeapSize(description: Size of the VM's heap, units: Bytes, startTime: 1296748847670, lastSampleTime: 0) ] ]} ]  

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

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

发布评论

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

评论(1

唔猫 2024-10-22 21:30:45

期间发现的。

List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean pool : pools) {
    System.out.println (pool.getName() + ": " + pool.getUsage());
}

给出如下输出:

Pool: Code Cache: usage = init = 2359296(2304K) used = 11777408(11501K) committed = 11862016(11584K) max = 50331648(49152K)
Pool: PS Eden Space: usage = init = 33554432(32768K) used = 83991760(82023K) committed = 138280960(135040K) max = 138280960(135040K)
Pool: PS Survivor Space: usage = init = 5570560(5440K) used = 0(0K) committed = 35717120(34880K) max = 35717120(34880K)
Pool: PS Old Gen: usage = init = 89522176(87424K) used = 419430168(409599K) committed = 419430400(409600K) max = 419430400(409600K)
Pool: PS Perm Gen: usage = init = 16777216(16384K) used = 118636528(115855K) committed = 122028032(119168K) max = 197132288(192512K)

Found out in the meantime.

List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean pool : pools) {
    System.out.println (pool.getName() + ": " + pool.getUsage());
}

gives an output such as:

Pool: Code Cache: usage = init = 2359296(2304K) used = 11777408(11501K) committed = 11862016(11584K) max = 50331648(49152K)
Pool: PS Eden Space: usage = init = 33554432(32768K) used = 83991760(82023K) committed = 138280960(135040K) max = 138280960(135040K)
Pool: PS Survivor Space: usage = init = 5570560(5440K) used = 0(0K) committed = 35717120(34880K) max = 35717120(34880K)
Pool: PS Old Gen: usage = init = 89522176(87424K) used = 419430168(409599K) committed = 419430400(409600K) max = 419430400(409600K)
Pool: PS Perm Gen: usage = init = 16777216(16384K) used = 118636528(115855K) committed = 122028032(119168K) max = 197132288(192512K)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文