Example for using Axon Metrics with Spring Boot

Hey Guys,

can someone provide me an example how to register metrics with spring boot acutator ?

Greets.

Hi Patrick,

which part of registering Metrics do you need help with?

If you already have your metrics, check out https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-metrics.html#production-ready-dropwizard-metrics to see how to register them with Spring Boot.

To register the metrics measurements in Axon, check out the axon-metrics component. It contains a “org.axonframework.metrics.GlobalMetricRegistry” class that allows you to register metrics implementations of MessageMonitors for your components. If you autowire your (Axon) Configurer, MetricsRegistry (the one from dropwizard), you can instantiate a GlobalMetricRegistry instance and tell it to configure the Configurer to use the Metrics implementations. Tip: you can use @Autowired methods in your Spring Configuration classes to do these kind of things easily.

Cheers,

Allard

Hi Allard,

thanks for your answer.
I forgot to mention that i have something like this:

@Autowired
private MetricRegistry metricRegistry;

@Bean
public GlobalMetricRegistry globalMetricRegistry() {
    GlobalMetricRegistry globalMetricRegistry = new GlobalMetricRegistry(this.metricRegistry);
    globalMetricRegistry.registerEventBus("eventBus");
    return globalMetricRegistry;
}

And then i see some new metrics like these:

  • eventBus.messageTimer.ignoredTimer.fifteenMinuteRate: 0,

  • eventBus.messageTimer.successTimer.snapshot.999thPercentile: 0,

  • eventBus.messageTimer.allTimer.fifteenMinuteRate: 0,

  • eventBus.messageTimer.successTimer.snapshot.99thPercentile: 0,

  • eventBus.messageTimer.failureTimer.snapshot.max: 0,

  • eventBus.messageTimer.failureTimer.oneMinuteRate: 0,

  • eventBus.messageTimer.ignoredTimer.snapshot.98thPercentile: 0,

  • eventBus.messageTimer.failureTimer.snapshot.min: 0,


  • But after firing some events and commands the counter stays the same…

So i think there is a missing link that i didn’t consider…

Greets

Patrick

Hi Patrick,

the “registerEventBus” method registers the metrics with the MetricsRegistry, and returns an EventMonitor instance to use. That instance still needs to be registered with the EventBus itself to have the counters (and timers, etc) triggered.

For that, you can add the Configurer as a parameter, and do:

MessageMonitor<Message<?>> eventBusMonitor = globalMetricRegistry.registerEventBus(“eventBus”);
configurer.configureMessageMonitor(EventBus.class, (config, type, name) -> eventBusMonitor);

Also note that you can add dependencies as method parameters in Spring @Bean methods.

Cheers,

Allard

Hey Allard,

thank you.
Now it works…

I had some trouble because i use the axon spring autoconfiguration and the code above throws the Exception: “this builder has already been built”
So i moved to my own configuration for the EventBus and EventStore.

Greets

Patrick

Hello Patrick,

I too am having problems getting the axon-metrics up and running on the event bus and we are using a spring boot autoconfigure approach as well. What I also tried is to define the eventStorageEngine myself, rather than relying on the autoconfigure feature. However, all metrics remain stuck at 0.
We were able to register the distinct registerEventProcessors, but this is quite overwhelming in the information it provides. Moreover, I’d settle for an overview of the metrics on the eventBus,

Could you send an excerpt of code that is actually working?

Kind regards,
Patrick

Hi,

there seems to be an ordering issue in the definition of beans. In my experience, configuring the monitoring the main application context file solves this issue.
Meanwhile, we’ll be looking for better ways to work around this problem).

Cheers,

Allard

Hi Java Developer,

The metrics exposed by an Axon Framework application or only captured on sending and receiving messages.
Thus, you can define metrics for CommandBus (sending and receiving command metrics), EventBus (sending event metrics), QueryBus (sending and receiving query metrics), Event Processor (receiving event metrics) and the QueryUpdateEmitter (specific for update metrics on the subscription query).
Having said that, there is no means through which an Axon Framework application will share the amount of snapshots provided, as there is no place to tie a MessageMonitor to the snapshotting process.

There is some additional information available through Axon Server (of which I am uncertain if you are using it).
Specifics on how to consume these and what can be consumed, can be found here.

Trusting this will help you further!

Cheers,
Steven

PS. It is important to note that this mailing list will be discontinued as specified in this thread.
Instead of this mailing list we have moved to use a forum style of communication, at https://discuss.axoniq.io/.

Hope to see you there!