use of io.dropwizard.metrics.Snapshot in project light-4j by networknt.
the class ExponentiallyDecayingReservoirTest method aHeavilyBiasedReservoirOf100OutOf1000Elements.
@Test
public void aHeavilyBiasedReservoirOf100OutOf1000Elements() throws Exception {
final ExponentiallyDecayingReservoir reservoir = new ExponentiallyDecayingReservoir(1000, 0.01);
for (int i = 0; i < 100; i++) {
reservoir.update(i);
}
assertThat(reservoir.size()).isEqualTo(100);
final Snapshot snapshot = reservoir.getSnapshot();
assertThat(snapshot.size()).isEqualTo(100);
assertAllValuesBetween(reservoir, 0, 100);
}
use of io.dropwizard.metrics.Snapshot in project light-4j by networknt.
the class ExponentiallyDecayingReservoirTest method aReservoirOf100OutOf10Elements.
@Test
public void aReservoirOf100OutOf10Elements() throws Exception {
final ExponentiallyDecayingReservoir reservoir = new ExponentiallyDecayingReservoir(100, 0.99);
for (int i = 0; i < 10; i++) {
reservoir.update(i);
}
final Snapshot snapshot = reservoir.getSnapshot();
assertThat(snapshot.size()).isEqualTo(10);
assertThat(snapshot.size()).isEqualTo(10);
assertAllValuesBetween(reservoir, 0, 10);
}
use of io.dropwizard.metrics.Snapshot in project light-4j by networknt.
the class HistogramTest method returnsTheSnapshotFromTheReservoir.
@Test
public void returnsTheSnapshotFromTheReservoir() throws Exception {
final Snapshot snapshot = mock(Snapshot.class);
when(reservoir.getSnapshot()).thenReturn(snapshot);
assertThat(histogram.getSnapshot()).isEqualTo(snapshot);
}
use of io.dropwizard.metrics.Snapshot in project light-4j by networknt.
the class InfluxDbReporter method reportTimer.
private void reportTimer(MetricName name, Timer timer, long now) {
if (canSkipMetric(name, timer)) {
return;
}
final Snapshot snapshot = timer.getSnapshot();
Map<String, String> apiTags = new HashMap<>(name.getTags());
String apiName = apiTags.remove("apiName");
Map<String, String> clientTags = new HashMap<>(name.getTags());
String clientId = clientTags.remove("clientId");
influxDb.appendPoints(new InfluxDbPoint(apiName + "." + name.getKey() + ".min", apiTags, now, format(convertDuration(snapshot.getMin()))));
influxDb.appendPoints(new InfluxDbPoint(apiName + "." + name.getKey() + ".max", apiTags, now, format(convertDuration(snapshot.getMax()))));
influxDb.appendPoints(new InfluxDbPoint(apiName + "." + name.getKey() + ".mean", apiTags, now, format(convertDuration(snapshot.getMean()))));
if (clientId != null) {
influxDb.appendPoints(new InfluxDbPoint(clientId + "." + name.getKey() + ".min", clientTags, now, format(convertDuration(snapshot.getMin()))));
influxDb.appendPoints(new InfluxDbPoint(clientId + "." + name.getKey() + ".max", clientTags, now, format(convertDuration(snapshot.getMax()))));
influxDb.appendPoints(new InfluxDbPoint(clientId + "." + name.getKey() + ".mean", clientTags, now, format(convertDuration(snapshot.getMean()))));
}
}
use of io.dropwizard.metrics.Snapshot in project light-4j by networknt.
the class InfluxDbReporter method reportHistogram.
private void reportHistogram(MetricName name, Histogram histogram, long now) {
if (canSkipMetric(name, histogram)) {
return;
}
final Snapshot snapshot = histogram.getSnapshot();
Map<String, String> apiTags = new HashMap<>(name.getTags());
String apiName = apiTags.remove("apiName");
Map<String, String> clientTags = new HashMap<>(name.getTags());
String clientId = clientTags.remove("clientId");
influxDb.appendPoints(new InfluxDbPoint(apiName + "." + name.getKey() + ".count", apiTags, now, format(histogram.getCount())));
influxDb.appendPoints(new InfluxDbPoint(apiName + "." + name.getKey() + ".min", apiTags, now, format(snapshot.getMin())));
influxDb.appendPoints(new InfluxDbPoint(apiName + "." + name.getKey() + ".max", apiTags, now, format(snapshot.getMax())));
influxDb.appendPoints(new InfluxDbPoint(apiName + "." + name.getKey() + ".mean", apiTags, now, format(snapshot.getMean())));
if (clientId != null) {
influxDb.appendPoints(new InfluxDbPoint(clientId + "." + name.getKey() + ".count", clientTags, now, format(histogram.getCount())));
influxDb.appendPoints(new InfluxDbPoint(clientId + "." + name.getKey() + ".min", clientTags, now, format(snapshot.getMin())));
influxDb.appendPoints(new InfluxDbPoint(clientId + "." + name.getKey() + ".max", clientTags, now, format(snapshot.getMax())));
influxDb.appendPoints(new InfluxDbPoint(clientId + "." + name.getKey() + ".mean", clientTags, now, format(snapshot.getMean())));
}
}
Aggregations