0

I have a Micronaut application that uses Micrometer to report metrics to InfluxDB with the micronaut-micrometer project. Currently it is using the Statsd Registry provided via the io.micronaut.configuration:micronaut-micrometer-registry-statsd dependency.

I would like to instead output metrics in Influx Line Protocol (ILP), but the micronaut-micrometer project does not offer an Influx Registry currently. I tried to work around this by importing the io.micrometer:micrometer-registry-influx dependency and configuring an InfluxMeterRegistry manually like this:

@Factory
public class MyMetricRegistryConfigurer implements MeterRegistryConfigurer {
  @Bean
  @Primary
  @Singleton
  public MeterRegistry getMeterRegistry() {
    InfluxConfig config = new InfluxConfig() {
      @Override
      public Duration step() {
        return Duration.ofSeconds(10);
      }

      @Override
      public String db() {
        return "metrics";
      }

      @Override
      public String get(String k) {
        return null; // accept the rest of the defaults
      }
    };
    return new InfluxMeterRegistry(config, Clock.SYSTEM);
  }

  @Override
  public boolean supports(MeterRegistry meterRegistry) {
    return meterRegistry instanceof InfluxMeterRegistry;
  }
}

When the application runs, the metrics are exposed on my /metrics endpoint as I would expect, but nothing gets written to InfluxDB. I confirmed that my local InfluxDB accepts metrics at the expected localhost:8086/write?db=metrics endpoint using curl. Can anyone give me some pointers to get this working? I'm wondering if I need to manually define a reporter somewhere...

Mike Muske
  • 323
  • 1
  • 16

1 Answers1

1

After playing around for a bit, I got this working with the following code:

@Factory
public class InfluxMeterRegistryFactory {
  @Bean
  @Singleton
  @Requires(property = MeterRegistryFactory.MICRONAUT_METRICS_ENABLED, value = 
StringUtils.TRUE, defaultValue = StringUtils.TRUE)
  @Requires(beans = CompositeMeterRegistry.class)
  public InfluxMeterRegistry getMeterRegistry() {
    InfluxConfig config = new InfluxConfig() {
      @Override
      public Duration step() {
        return Duration.ofSeconds(10);
      }

      @Override
      public String db() {
        return "metrics";
      }

      @Override
      public String get(String k) {
        return null; // accept the rest of the defaults
      }
    };
    return new InfluxMeterRegistry(config, Clock.SYSTEM);
  }
}

I also noticed that an InfluxMeterRegistry will be available out of the box in the future for micronaut-micrometer as of v1.2.0.

Mike Muske
  • 323
  • 1
  • 16