Counter - Reporter

> Monitoring Metrics (Perfcounter | Performance Metrics | Operational data)

1 - About

A reporter is a collector that runs on the client and will collect the metrics at regulier interval and send them to an output destination.

Advertising

3 - Example

3.1 - Dropwizard

Dropwizard has ScheduledReporter

Example:

// 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);