use of io.dropwizard.metrics.Meter in project light-4j by networknt.
the class InfluxDbReporterTest method reportsMeters.
@Test
public void reportsMeters() throws Exception {
final Meter meter = mock(Meter.class);
when(meter.getCount()).thenReturn(1L);
when(meter.getOneMinuteRate()).thenReturn(2.0);
when(meter.getFiveMinuteRate()).thenReturn(3.0);
when(meter.getFifteenMinuteRate()).thenReturn(4.0);
when(meter.getMeanRate()).thenReturn(5.0);
reporter.report(this.map(), this.map(), this.map(), this.map("meter", meter), 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("meter");
assertThat(point.getFields()).isNotEmpty();
assertThat(point.getFields()).hasSize(5);
assertThat(point.getFields()).contains(entry("count", 1L));
assertThat(point.getFields()).contains(entry("one-minute", 2.0));
assertThat(point.getFields()).contains(entry("five-minute", 3.0));
assertThat(point.getFields()).contains(entry("fifteen-minute", 4.0));
assertThat(point.getFields()).contains(entry("mean-rate", 5.0));
*/
}
use of io.dropwizard.metrics.Meter 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");
}
}
use of io.dropwizard.metrics.Meter in project light-4j by networknt.
the class Slf4jReporterTest method reportsMeterValuesAtError.
@Test
public void reportsMeterValuesAtError() throws Exception {
final Meter meter = mock(Meter.class);
when(meter.getCount()).thenReturn(1L);
when(meter.getMeanRate()).thenReturn(2.0);
when(meter.getOneMinuteRate()).thenReturn(3.0);
when(meter.getFiveMinuteRate()).thenReturn(4.0);
when(meter.getFifteenMinuteRate()).thenReturn(5.0);
when(logger.isErrorEnabled(marker)).thenReturn(true);
errorReporter.report(this.map(), this.map(), this.map(), map("test.meter", meter), this.map());
verify(logger).error(marker, "type={}, name={}, count={}, mean_rate={}, m1={}, m5={}, m15={}, rate_unit={}", "METER", "test.meter", 1L, 2.0, 3.0, 4.0, 5.0, "events/second");
}
Aggregations