Search in sources :

Example 6 with Gauge

use of io.dropwizard.metrics.Gauge in project light-4j by networknt.

the class ConsoleReporterTest method reportsGaugeValues.

@Test
public void reportsGaugeValues() throws Exception {
    final Gauge gauge = mock(Gauge.class);
    when(gauge.getValue()).thenReturn(1);
    reporter.report(map("gauge", gauge), this.map(), this.map(), this.map(), this.map());
    assertThat(consoleOutput()).isEqualTo(lines("3/17/13 6:04:36 PM =============================================================", "", "-- Gauges ----------------------------------------------------------------------", "gauge", "             value = 1", "", ""));
}
Also used : Gauge(io.dropwizard.metrics.Gauge) Test(org.junit.Test)

Example 7 with Gauge

use of io.dropwizard.metrics.Gauge in project light-4j by networknt.

the class InfluxDbReporter method report.

@Override
public void report(final SortedMap<MetricName, Gauge> gauges, final SortedMap<MetricName, Counter> counters, final SortedMap<MetricName, Histogram> histograms, final SortedMap<MetricName, Meter> meters, final SortedMap<MetricName, Timer> timers) {
    final long now = System.currentTimeMillis();
    if (logger.isDebugEnabled())
        logger.debug("InfluxDbReporter report is called with counter size " + counters.size());
    try {
        influxDb.flush();
        for (Map.Entry<MetricName, Gauge> entry : gauges.entrySet()) {
            reportGauge(entry.getKey(), entry.getValue(), now);
        }
        for (Map.Entry<MetricName, Counter> entry : counters.entrySet()) {
            reportCounter(entry.getKey(), entry.getValue(), now);
        }
        for (Map.Entry<MetricName, Histogram> entry : histograms.entrySet()) {
            reportHistogram(entry.getKey(), entry.getValue(), now);
        }
        for (Map.Entry<MetricName, Meter> entry : meters.entrySet()) {
            reportMeter(entry.getKey(), entry.getValue(), now);
        }
        for (Map.Entry<MetricName, Timer> entry : timers.entrySet()) {
            reportTimer(entry.getKey(), entry.getValue(), now);
        }
        if (influxDb.hasSeriesData()) {
            influxDb.writeData();
        }
        // reset counters
        for (Map.Entry<MetricName, Counter> entry : counters.entrySet()) {
            Counter counter = entry.getValue();
            long count = counter.getCount();
            counter.dec(count);
        }
    } catch (Exception e) {
        logger.error("Unable to report to InfluxDB. Discarding data.", e);
    }
}
Also used : Histogram(io.dropwizard.metrics.Histogram) Meter(io.dropwizard.metrics.Meter) Gauge(io.dropwizard.metrics.Gauge) MetricName(io.dropwizard.metrics.MetricName) Counter(io.dropwizard.metrics.Counter) Timer(io.dropwizard.metrics.Timer)

Example 8 with Gauge

use of io.dropwizard.metrics.Gauge in project light-4j by networknt.

the class JvmAttributeGaugeSetTest method hasAGaugeForTheJVMUptime.

@Test
public void hasAGaugeForTheJVMUptime() throws Exception {
    final Gauge gauge = (Gauge) gauges.getMetrics().get(MetricName.build("uptime"));
    assertThat(gauge.getValue()).isEqualTo(100L);
}
Also used : Gauge(io.dropwizard.metrics.Gauge) Test(org.junit.Test)

Example 9 with Gauge

use of io.dropwizard.metrics.Gauge in project light-4j by networknt.

the class InfluxDbReporterTest method gauge.

private <T> Gauge gauge(T value) {
    final Gauge gauge = mock(Gauge.class);
    when(gauge.getValue()).thenReturn(value);
    return gauge;
}
Also used : Gauge(io.dropwizard.metrics.Gauge)

Aggregations

Gauge (io.dropwizard.metrics.Gauge)9 Test (org.junit.Test)6 MetricName (io.dropwizard.metrics.MetricName)2 Counter (io.dropwizard.metrics.Counter)1 Histogram (io.dropwizard.metrics.Histogram)1 JmxReporter (io.dropwizard.metrics.JmxReporter)1 JvmAttributeGaugeSet (io.dropwizard.metrics.JvmAttributeGaugeSet)1 Meter (io.dropwizard.metrics.Meter)1 Timer (io.dropwizard.metrics.Timer)1