Search code examples
javarestinstrumentationstatsdmicrometer

How to measure http requests per second using micrometer


We have a rest service developed using vert.x with large number of requests coming every seconds. I am using StatsdMeterRegistry for other metrics like Timer to measure taken to process different business logics. How do i gauge http requests coming every second using micrometer. on my local I have installed statsd agent and carbon/graphite/whisper but in production it will be statsd and sysdig. Not using spring framework or spring boot. I can't use vertx in built support for micrometer as it doesn't support statsd. Does micrometer provide inbuilt Meters for http requests rate. Or any different way you can suggest.


Solution

  • Micrometer is a simple facade for metrics. You should be able to leverage the built in micrometer support and just plug in the correct backend.

    Here is how you would create the statsd registry and register it with vertx:

    StatsdConfig config = new StatsdConfig() {
        @Override
        public String get(String k) {
            return null;
        }
    
    
        @Override
        public StatsdFlavor flavor() {
            return StatsdFlavor.Etsy;
        }
    };
    
    MeterRegistry registry = new StatsdMeterRegistry(config, Clock.SYSTEM);
    
    Vertx vertx = Vertx.vertx(new VertxOptions()
      .setMetricsOptions(new MicrometerMetricsOptions()
        .setMicrometerRegistry(registry)
        .setEnabled(true)));
    

    Docs: http://micrometer.io/docs/registry/statsD#_configuring and https://vertx.io/docs/vertx-micrometer-metrics/java/#_other_backends_or_combinations