Skip to content

Commit

Permalink
Merge pull request #786 from Menthalion/used-aftergc
Browse files Browse the repository at this point in the history
Add CollectionUsage.getUsed() to MemoryPool gauges
  • Loading branch information
ryantenney committed Apr 24, 2015
2 parents 948a686 + 991fa8d commit 86f4974
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
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
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

0 comments on commit 86f4974

Please sign in to comment.