Prometheus is nice open-source monitoring tools which covers applications and infrastructures. Prometheus has many client libraries that matches the language in which your application is written.(See here).
Prometheus client libraries include Java client library which supports spring framework, spring boot.
The instrument by Spring AOP is nice solution,
however, it is a lot of cost to implement for collecing duration metrics of all methods in all RestController
or Controller
classes.
This repository is a spring boot library for this solution to make it easy and simple.
You only add dependency and one annotation,
then, you can collect the duration metrics of all methods in all RestController
or Controller
classes.
Now, this library is not uploaded in maven repository.(You make issue if you want. I'll upload soon.)
As a temporary measure, you must install library as follows.
$ git clone https://github.com/aha-oretama/prometheus_auto_timing.git
$ cd prometheus_auto_timing.git
$ mvn install
You only add dependency.
<dependency>
<groupId>jp.aha-oretama</groupId>
<artifactId>prometheus_auto_timing</artifactId>
<version>0.1.0-RELEASE</version>
</dependency>
And you only add one annotaion @EnablePrometheusAutoTiming
.
@SpringBootApplication
@EnablePrometheusEndpoint
@EnableSpringBootMetricsCollector
@EnablePrometheusAutoTiming
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Notification: You do not need to implement for collecting duration metrics of all methods in all RestController
or Controller
classes, but you need to implement for exposing prometheus API by spring boot. It is realised by simpleclient_spring_boot.