title: querying data with micrometer
body: <p>We have this fancy monitoring system to which our spring-boot services are posting metrics to an influx DB with micrometer. There's a nice grafana frontend, but the problem is that we're now at a stage where we have to have some of these metrics available in other services to reason on.
  The whole system was set up by my predecessor, and my current understanding of it is practically zero. I can add and post new metrics, but I can't for the life of me get anything <em>out</em> of it.</p>
  
  <p>Here's a short example: 
  Our gateway increments the counter for each image that a camera posts to it. The definition of the counter looks like this:</p>
  
  <pre><code>private val imageCounters = mutableMapOf&lt;String, Counter&gt;()
  private val imageCounter = { camera: String -&gt;
      imageCounters.getOrPut(camera) {
          registry.counter("gateway.image.counter", "camera", camera)
      }
  </code></pre>
  
  <p>And the counter is incremented in the code like this:</p>
  
  <pre><code>imageCounter("placeholder-id").increment()
  </code></pre>
  
  <p>Now we're improving our billing, and the billing service needs to know how many images for a certain camera went through the gateway. So naturally the first thing I try looks like this:</p>
  
  <pre><code>class MonitoringService(val metrics: MeterRegistry) {
  
      private val log = logger()
      private val imageCounters = mutableMapOf&lt;String, Counter&gt;()
      private val imageCounter = { camera: String -&gt;
          imageCounters.getOrPut(camera) {
              metrics.counter("gateway.image.counter", "camera", camera)
          }
      }
  
      fun test() {
          val test = imageCounter("16004").count()
          val bugme = true
          log.info("influx test: $test")
      }
  }
  </code></pre>
  
  <p>There's two problems with this: First off it always returns zero, so obviously I'm doing it wrong. I just can't figure out what it is.
  Second, even if it would return a reasonable value, I don't see a way to limit this by time (I'll usually need the number of images uploaded during the current month).</p>
  
  <p>What worries me is that while I can find a lot of documentation on how to post data with micrometer, I can't seem to find any documentation on how to query. Is Micrometer only designed to post monitoring data, but not query it? the .getOrPut() method would indicate it can do both, but since querying data seems undocumented as far as I can tell, that might be a misconception on my part.</p>
  
  <p>There is an influx-db client for Java, which I'll try next, but at the end of the day I don't want multiple components in my application doing the same thing just because I'm not familiar with the tools I inherited.</p>