Search in sources :

Example 16 with Snapshot

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);
}
Also used : Snapshot(io.dropwizard.metrics.Snapshot) ExponentiallyDecayingReservoir(io.dropwizard.metrics.ExponentiallyDecayingReservoir) Test(org.junit.Test)

Example 17 with Snapshot

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);
}
Also used : Snapshot(io.dropwizard.metrics.Snapshot) ExponentiallyDecayingReservoir(io.dropwizard.metrics.ExponentiallyDecayingReservoir) Test(org.junit.Test)

Example 18 with Snapshot

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);
}
Also used : Snapshot(io.dropwizard.metrics.Snapshot) Test(org.junit.Test)

Example 19 with 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()))));
    }
}
Also used : Snapshot(io.dropwizard.metrics.Snapshot) InfluxDbPoint(io.dropwizard.metrics.influxdb.data.InfluxDbPoint)

Example 20 with Snapshot

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())));
    }
}
Also used : Snapshot(io.dropwizard.metrics.Snapshot) InfluxDbPoint(io.dropwizard.metrics.influxdb.data.InfluxDbPoint)

Aggregations

Snapshot (io.dropwizard.metrics.Snapshot)33 Test (org.junit.Test)28 WeightedSnapshot (io.dropwizard.metrics.WeightedSnapshot)8 UniformSnapshot (io.dropwizard.metrics.UniformSnapshot)6 Histogram (io.dropwizard.metrics.Histogram)4 Timer (io.dropwizard.metrics.Timer)4 InfluxDbPoint (io.dropwizard.metrics.influxdb.data.InfluxDbPoint)4 ExponentiallyDecayingReservoir (io.dropwizard.metrics.ExponentiallyDecayingReservoir)3 WeightedSample (io.dropwizard.metrics.WeightedSnapshot.WeightedSample)2 UniformReservoir (io.dropwizard.metrics.UniformReservoir)1 Before (org.junit.Before)1