Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JVM] Fix maximum/total memory calculation #3125

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -47,8 +47,8 @@ public Map<String, Metric> getMetrics() {
mxBean.getNonHeapMemoryUsage().getInit());
gauges.put("total.used", (Gauge<Long>) () -> mxBean.getHeapMemoryUsage().getUsed() +
mxBean.getNonHeapMemoryUsage().getUsed());
gauges.put("total.max", (Gauge<Long>) () -> mxBean.getHeapMemoryUsage().getMax() +
mxBean.getNonHeapMemoryUsage().getMax());
gauges.put("total.max", (Gauge<Long>) () -> mxBean.getNonHeapMemoryUsage().getMax() == -1 ?
-1 : mxBean.getHeapMemoryUsage().getMax() + mxBean.getNonHeapMemoryUsage().getMax());
gauges.put("total.committed", (Gauge<Long>) () -> mxBean.getHeapMemoryUsage().getCommitted() +
mxBean.getNonHeapMemoryUsage().getCommitted());

Expand All @@ -72,7 +72,7 @@ protected Ratio getRatio() {
@Override
protected Ratio getRatio() {
final MemoryUsage usage = mxBean.getNonHeapMemoryUsage();
return Ratio.of(usage.getUsed(), usage.getMax());
return Ratio.of(usage.getUsed(), usage.getMax() == -1 ? usage.getCommitted() : usage.getMax());
}
});

Expand Down
Expand Up @@ -130,6 +130,16 @@ public void hasAGaugeForTotalMax() {
.isEqualTo(44L);
}

@Test
public void hasAGaugeForTotalMaxWhenNonHeapMaxUndefined() {
when(nonHeap.getMax()).thenReturn(-1L);

final Gauge gauge = (Gauge) gauges.getMetrics().get("total.max");

assertThat(gauge.getValue())
.isEqualTo(-1L);
}

@Test
public void hasAGaugeForHeapCommitted() {
final Gauge gauge = (Gauge) gauges.getMetrics().get("heap.committed");
Expand Down Expand Up @@ -210,6 +220,15 @@ public void hasAGaugeForNonHeapUsage() {
.isEqualTo(0.75);
}

@Test
public void hasAGaugeForNonHeapUsageWhenNonHeapMaxUndefined() {
when(nonHeap.getMax()).thenReturn(-1L);
final Gauge gauge = (Gauge) gauges.getMetrics().get("non-heap.usage");

assertThat(gauge.getValue())
.isEqualTo(3.0);
}

@Test
public void hasAGaugeForMemoryPoolUsage() {
final Gauge gauge = (Gauge) gauges.getMetrics().get("pools.Big-Pool.usage");
Expand Down