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

Add CollectionUsage.getUsed() to MemoryPool gauges #786

Merged
merged 2 commits into from
Apr 24, 2015
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ public Long getValue() {
}
});

gauges.put(name(poolName, "used-after-gc"),new Gauge<Long>() {
@Override
public Long getValue() {
return pool.getCollectionUsage().getUsed();
}
});

gauges.put(name(poolName, "init"),new Gauge<Long>() {
@Override
public Long getValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class MemoryUsageGaugeSetTest {
private final MemoryUsage nonHeap = mock(MemoryUsage.class);
private final MemoryUsage pool = mock(MemoryUsage.class);
private final MemoryUsage weirdPool = mock(MemoryUsage.class);
private final MemoryUsage weirdCollection = mock(MemoryUsage.class);
private final MemoryMXBean mxBean = mock(MemoryMXBean.class);
private final MemoryPoolMXBean memoryPool = mock(MemoryPoolMXBean.class);
private final MemoryPoolMXBean weirdMemoryPool = mock(MemoryPoolMXBean.class);
Expand Down Expand Up @@ -48,13 +49,16 @@ public void setUp() throws Exception {
when(weirdPool.getUsed()).thenReturn(300L);
when(weirdPool.getMax()).thenReturn(-1L);

when(weirdCollection.getUsed()).thenReturn(290L);

when(mxBean.getHeapMemoryUsage()).thenReturn(heap);
when(mxBean.getNonHeapMemoryUsage()).thenReturn(nonHeap);

when(memoryPool.getUsage()).thenReturn(pool);
when(memoryPool.getName()).thenReturn("Big Pool");

when(weirdMemoryPool.getUsage()).thenReturn(weirdPool);
when(weirdMemoryPool.getCollectionUsage()).thenReturn(weirdCollection);
when(weirdMemoryPool.getName()).thenReturn("Weird Pool");
}

Expand All @@ -81,9 +85,11 @@ public void hasASetOfGauges() throws Exception {
"pools.Big-Pool.used",
"pools.Big-Pool.usage",
"pools.Big-Pool.max",
"pools.Big-Pool.used-after-gc",
"pools.Weird-Pool.init",
"pools.Weird-Pool.committed",
"pools.Weird-Pool.used",
"pools.Weird-Pool.used-after-gc",
"pools.Weird-Pool.usage",
"pools.Weird-Pool.max");
}
Expand Down Expand Up @@ -248,6 +254,14 @@ public void hasAGaugeForWeirdMemoryPoolMax() throws Exception {
.isEqualTo(-1L);
}

@Test
public void hasAGaugeForWeirdCollectionPoolUsed() throws Exception {
final Gauge gauge = (Gauge) gauges.getMetrics().get("pools.Weird-Pool.used-after-gc");

assertThat(gauge.getValue())
.isEqualTo(290L);
}

@Test
public void autoDetectsMemoryUsageBeanAndMemoryPools() throws Exception {
assertThat(new MemoryUsageGaugeSet().getMetrics().keySet())
Expand Down