I need to export counters and gauges to csv in order to process them later on. By using gradle I get the jars for codahale metrics 3.1.2:
compile('io.dropwizard.metrics:metrics-core:${metricsVersion}' )
compile('io.dropwizard.metrics:metrics-annotations:${metricsVersion}' )
For the csv export I created one reporter using these lines of code:
@Configuration
public class MetricsConfiguration {
@Autowired
MetricRegistry metricRegistry;
@Bean
public CsvReporter configureReporters() {
CsvReporter reporter = CsvReporter.forRegistry(metricRegistry).build(new File("C:/temp/metrics"));
reporter.start(5, TimeUnit.SECONDS);
return reporter;
}
}
I can see files are created and they contain a timestamp and value (in this example the values were set for a gauge):
1444137261,42.0
1444137266,42.0
1444137271,42.0
1444137276,1.0
1444137281,1.0
1444137286,1.0
The only problem with this is that the file repeats the last value set until it is overwritten by me using gaugeService.submit()
. In this scenario I set a gauge value of 42.0
once, waited several minutes and then set a new value of 1.0
.
This makes it difficult to parse the csv and create averages on my own or create histograms because I don't know if the 42.0
was submitted once or three times.
I had a look at these SO posts but they didn't help me solve my problem: