title: How to have spring boot metrics export averages and absolute values to csv
body: <p>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:</p>
  
  <pre><code>compile('io.dropwizard.metrics:metrics-core:${metricsVersion}' )
  compile('io.dropwizard.metrics:metrics-annotations:${metricsVersion}' )
  </code></pre>
  
  <p>For the csv export I created one reporter using these lines of code:</p>
  
  <pre><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;
      }
  }
  </code></pre>
  
  <p>I can see files are created and they contain a timestamp and value (in this example the values were set for a gauge):</p>
  
  <pre><code>1444137261,42.0
  1444137266,42.0
  1444137271,42.0
  1444137276,1.0
  1444137281,1.0
  1444137286,1.0
  </code></pre>
  
  <p>The only problem with this is that the file repeats the last value set until it is overwritten by me using <code>gaugeService.submit()</code>. In this scenario I set a gauge value of <code>42.0</code> once, waited several minutes and then set a new value of <code>1.0</code>.</p>
  
  <p>This makes it difficult to parse the csv and create averages on my own or create histograms because I don't know if the <code>42.0</code> was submitted once or three times.</p>
  
  <p>I had a look at these SO posts but they didn't help me solve my problem:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/32215723/exporting-spring-boot-actuator-metrics-dropwizard-metrics-to-statsd">Exporting Spring Boot Actuator Metrics (&amp; Dropwizard Metrics) to Statsd</a></li>
  <li><a href="https://stackoverflow.com/questions/32382349/how-to-get-metrics-from-spring-boot-actuator-programmatically">how to get metrics from spring-boot-actuator programmatically?</a></li>
  </ul>