Search in sources :

Example 1 with InfluxDbReporter

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

the class SendToLocalInfluxDB method startInfluxDbReporter.

private static InfluxDbReporter startInfluxDbReporter(MetricRegistry registry) throws Exception {
    final InfluxDbHttpSender influxDb = new InfluxDbHttpSender("http", "127.0.0.1", 8086, "dropwizard", "root", "root");
    final Map<String, String> tags = new HashMap<>();
    tags.put("host", "localhost");
    final InfluxDbReporter reporter = InfluxDbReporter.forRegistry(registry).withTags(tags).skipIdleMetrics(true).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL).build(influxDb);
    reporter.start(10, TimeUnit.SECONDS);
    return reporter;
}
Also used : InfluxDbHttpSender(io.dropwizard.metrics.influxdb.InfluxDbHttpSender) HashMap(java.util.HashMap) InfluxDbReporter(io.dropwizard.metrics.influxdb.InfluxDbReporter)

Example 2 with InfluxDbReporter

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

the class SendToLocalInfluxDB method main.

public static void main(String[] args) {
    InfluxDbReporter influxDbReporter = null;
    ScheduledReporter consoleReporter = null;
    Timer.Context context = null;
    try {
        final MetricRegistry registry = new MetricRegistry();
        consoleReporter = startConsoleReporter(registry);
        influxDbReporter = startInfluxDbReporter(registry);
        final Meter myMeter = registry.meter(MetricName.build("testMetric").tagged("env", "test"));
        final Timer myTimer = registry.timer("testTimer");
        context = myTimer.time();
        for (int i = 0; i < 5; i++) {
            myMeter.mark();
            myMeter.mark(Math.round(Math.random() * 100.0));
            Thread.sleep(2000);
        }
    } catch (Exception exc) {
        exc.printStackTrace();
        System.exit(1);
    } finally {
        if (context != null) {
            context.stop();
        }
        if (influxDbReporter != null) {
            influxDbReporter.report();
            influxDbReporter.stop();
        }
        if (consoleReporter != null) {
            consoleReporter.report();
            consoleReporter.stop();
        }
        System.out.println("Finished");
    }
}
Also used : Timer(io.dropwizard.metrics.Timer) Meter(io.dropwizard.metrics.Meter) MetricRegistry(io.dropwizard.metrics.MetricRegistry) InfluxDbReporter(io.dropwizard.metrics.influxdb.InfluxDbReporter) ScheduledReporter(io.dropwizard.metrics.ScheduledReporter)

Aggregations

InfluxDbReporter (io.dropwizard.metrics.influxdb.InfluxDbReporter)2 Meter (io.dropwizard.metrics.Meter)1 MetricRegistry (io.dropwizard.metrics.MetricRegistry)1 ScheduledReporter (io.dropwizard.metrics.ScheduledReporter)1 Timer (io.dropwizard.metrics.Timer)1 InfluxDbHttpSender (io.dropwizard.metrics.influxdb.InfluxDbHttpSender)1 HashMap (java.util.HashMap)1