About
A reporter is a collector that:
- runs in the instrumented application
- will collect the metrics at regulier interval from a registry
- send them to an output destination, mostly a backend metrics server.
Example
Dropwizard
Dropwizard has ScheduledReporter
Example:
- slf4j has the destination with the Slf4jReporter
// Initialize Dropwizard metric registry
String registryName = "registry";
MetricRegistry registry = SharedMetricRegistries.getOrCreate(registryName);
SharedMetricRegistries.setDefault(registryName);
// Initialize Dropwizard reporter
Logger dropWizardlogger = LoggerFactory.getLogger(DropWizard.class);
// The reporter
Slf4jReporter reporter = Slf4jReporter.forRegistry(registry)
.outputTo(dropWizardlogger)
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.build();
reporter.start(1, TimeUnit.MINUTES);
- with the CsvReporter, it doesn't write to a file, but instead writes a series of files to a specified directory.
String registryName = "vertx";
MetricRegistry registry = SharedMetricRegistries.getOrCreate(registryName);
SharedMetricRegistries.setDefault(registryName);
// A directory path
Path csvPath = Paths.get("logs");
// The reporter
CsvReporter reporter = CsvReporter.forRegistry(registry)
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.build(csvPath.toFile());
// Start
reporter.start(1, TimeUnit.MINUTES);