Search in sources :

Example 6 with InfluxDbPoint

use of io.dropwizard.metrics.influxdb.data.InfluxDbPoint in project light-4j by networknt.

the class InfluxDbReporterTest method reportsHistograms.

@Test
public void reportsHistograms() throws Exception {
    final Histogram histogram = mock(Histogram.class);
    when(histogram.getCount()).thenReturn(1L);
    final Snapshot snapshot = mock(Snapshot.class);
    when(snapshot.getMax()).thenReturn(2L);
    when(snapshot.getMean()).thenReturn(3.0);
    when(snapshot.getMin()).thenReturn(4L);
    when(snapshot.getStdDev()).thenReturn(5.0);
    when(snapshot.getMedian()).thenReturn(6.0);
    when(snapshot.get75thPercentile()).thenReturn(7.0);
    when(snapshot.get95thPercentile()).thenReturn(8.0);
    when(snapshot.get98thPercentile()).thenReturn(9.0);
    when(snapshot.get99thPercentile()).thenReturn(10.0);
    when(snapshot.get999thPercentile()).thenReturn(11.0);
    when(histogram.getSnapshot()).thenReturn(snapshot);
    reporter.report(this.map(), this.map(), this.map("histogram", histogram), this.map(), this.map());
    final ArgumentCaptor<InfluxDbPoint> influxDbPointCaptor = ArgumentCaptor.forClass(InfluxDbPoint.class);
    Mockito.verify(influxDb, atLeastOnce()).appendPoints(influxDbPointCaptor.capture());
    InfluxDbPoint point = influxDbPointCaptor.getValue();
/*
        assertThat(point.getMeasurement()).isEqualTo("histogram");
        assertThat(point.getFields()).isNotEmpty();
        assertThat(point.getFields()).hasSize(13);
        assertThat(point.getFields()).contains(entry("max", 2L));
        assertThat(point.getFields()).contains(entry("mean", 3.0));
        assertThat(point.getFields()).contains(entry("min", 4L));
        assertThat(point.getFields()).contains(entry("std-dev", 5.0));
        assertThat(point.getFields()).contains(entry("median", 6.0));
        assertThat(point.getFields()).contains(entry("75-percentile", 7.0));
        assertThat(point.getFields()).contains(entry("95-percentile", 8.0));
        assertThat(point.getFields()).contains(entry("98-percentile", 9.0));
        assertThat(point.getFields()).contains(entry("99-percentile", 10.0));
        assertThat(point.getFields()).contains(entry("999-percentile", 11.0));
        */
}
Also used : Snapshot(io.dropwizard.metrics.Snapshot) Histogram(io.dropwizard.metrics.Histogram) InfluxDbPoint(io.dropwizard.metrics.influxdb.data.InfluxDbPoint) Test(org.junit.Test)

Example 7 with InfluxDbPoint

use of io.dropwizard.metrics.influxdb.data.InfluxDbPoint in project light-4j by networknt.

the class InfluxDbReporter method reportMeter.

private void reportMeter(MetricName name, Metered meter, long now) {
    if (canSkipMetric(name, meter)) {
        return;
    }
    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(meter.getCount())));
    if (clientId != null) {
        influxDb.appendPoints(new InfluxDbPoint(clientId + "." + name.getKey() + ".count", clientTags, now, format(meter.getCount())));
    }
}
Also used : InfluxDbPoint(io.dropwizard.metrics.influxdb.data.InfluxDbPoint)

Example 8 with InfluxDbPoint

use of io.dropwizard.metrics.influxdb.data.InfluxDbPoint in project light-4j by networknt.

the class InfluxDbReporter method reportCounter.

private void reportCounter(MetricName name, Counter counter, long now) {
    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(counter.getCount())));
    if (clientId != null) {
        influxDb.appendPoints(new InfluxDbPoint(clientId + "." + name.getKey() + ".count", clientTags, now, format(counter.getCount())));
    }
}
Also used : InfluxDbPoint(io.dropwizard.metrics.influxdb.data.InfluxDbPoint)

Example 9 with InfluxDbPoint

use of io.dropwizard.metrics.influxdb.data.InfluxDbPoint in project light-4j by networknt.

the class InfluxDbReporter method reportGauge.

private void reportGauge(MetricName name, Gauge<?> gauge, long now) {
    final String value = format(gauge.getValue());
    if (value != null) {
        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(), apiTags, now, value));
        if (clientId != null) {
            influxDb.appendPoints(new InfluxDbPoint(clientId + "." + name.getKey(), clientTags, now, value));
        }
    }
}
Also used : InfluxDbPoint(io.dropwizard.metrics.influxdb.data.InfluxDbPoint)

Example 10 with InfluxDbPoint

use of io.dropwizard.metrics.influxdb.data.InfluxDbPoint 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)

Aggregations

InfluxDbPoint (io.dropwizard.metrics.influxdb.data.InfluxDbPoint)14 Test (org.junit.Test)9 Snapshot (io.dropwizard.metrics.Snapshot)4 Counter (io.dropwizard.metrics.Counter)1 Histogram (io.dropwizard.metrics.Histogram)1 Meter (io.dropwizard.metrics.Meter)1 Timer (io.dropwizard.metrics.Timer)1