Skip to content

Commit

Permalink
Merge pull request #262 from dmuino/distSummaryMin
Browse files Browse the repository at this point in the history
Add min gauge to distribution summary
  • Loading branch information
brharrington committed Jul 16, 2014
2 parents bd949ad + a323824 commit 1df3974
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ public class BasicDistributionSummary
private static final Tag STAT_TOTAL = Tags.newTag(STATISTIC, "totalAmount");
private static final Tag STAT_COUNT = Tags.newTag(STATISTIC, "count");
private static final Tag STAT_MAX = Tags.newTag(STATISTIC, "max");
private static final Tag STAT_MIN = Tags.newTag(STATISTIC, "min");

private final StepCounter totalAmount;
private final StepCounter count;
private final MaxGauge max;
private final MinGauge min;

private final List<Monitor<?>> monitors;

Expand All @@ -49,8 +51,9 @@ public BasicDistributionSummary(MonitorConfig config) {
totalAmount = new StepCounter(config.withAdditionalTag(STAT_TOTAL));
count = new StepCounter(config.withAdditionalTag(STAT_COUNT));
max = new MaxGauge(config.withAdditionalTag(STAT_MAX));
min = new MinGauge(config.withAdditionalTag(STAT_MIN));

monitors = ImmutableList.<Monitor<?>>of(totalAmount, count, max);
monitors = ImmutableList.<Monitor<?>>of(totalAmount, count, max, min);
}

/**
Expand All @@ -69,6 +72,7 @@ public void record(long amount) {
totalAmount.increment(amount);
count.increment();
max.update(amount);
min.update(amount);
}
}

Expand Down Expand Up @@ -97,6 +101,13 @@ public Long getCount() {
return count.getCurrentCount(0);
}

/**
* Get the min value since the last polling interval.
*/
public Long getMin() {
return min.getCurrentValue(0);
}

/**
* Get the max value since the last polling interval.
*/
Expand All @@ -113,6 +124,7 @@ public String toString() {
.add("config", config)
.add("totalAmount", totalAmount)
.add("count", count)
.add("min", min)
.add("max", max).toString();
}

Expand All @@ -121,7 +133,7 @@ public String toString() {
*/
@Override
public int hashCode() {
return Objects.hashCode(config, totalAmount, count, max);
return Objects.hashCode(config, totalAmount, count, max, min);
}

/**
Expand All @@ -141,6 +153,7 @@ public boolean equals(Object obj) {
return config.equals(m.getConfig())
&& totalAmount.equals(m.totalAmount)
&& count.equals(m.count)
&& max.equals(m.max);
&& max.equals(m.max)
&& min.equals(m.min);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@ public void testGetValue() throws Exception {
assertEquals(m.getCount().longValue(), 0L);
assertEquals(m.getTotalAmount().longValue(), 0L);
assertEquals(m.getMax().longValue(), 0L);
assertEquals(m.getMin().longValue(), 0L);

m.record(42);
assertEquals(m.getValue().longValue(), 42L);
assertEquals(m.getTotalAmount().longValue(), 42L);
assertEquals(m.getCount().longValue(), 1L);
assertEquals(m.getMax().longValue(), 42L);
assertEquals(m.getMin().longValue(), 42L);

m.record(21);
assertEquals(m.getValue().longValue(), 31L);
assertEquals(m.getTotalAmount().longValue(), 63L);
assertEquals(m.getCount().longValue(), 2L);
assertEquals(m.getMax().longValue(), 42L);
assertEquals(m.getMin().longValue(), 21L);
}
}

0 comments on commit 1df3974

Please sign in to comment.