Advertisements

Continued from:

Metrics

How would you like to know things like how many times a service has been called, or how many concurrent executions a service has at this moment, or how long it takes a command to be executed? 

The MicroProfile Metrics module provides a simple and unified way to publish those and other metrics that you can use to monitor the performance of the application. They are exported in Prometheus format, which means you can use tools like Prometheus or Grafana dashboards to display the data and alerts. 

Advertisements

We can get some metrics in our code using the annotations: @Counted, @Timed, @Metered, and @Gauge. We can also create custom metrics by using the annotation @Metric and creating custom histograms.

@Counted(name="StockService.getAll_counter")
@Timed(name="StockService.getAll_timer")
public List getAll(){
   //some code here
}
    
@Timed
public List getByStatus(String status){
   //some code here
}

@Metered
public Optional findById(String id){
   //some code here
}

Finally, we can access the endpoint /metrics/application to get all the metrics exposed by our application. http://localhost:8080/metrics/application

MicroProfile Metrics
Table of contents:

Advertisements

Pages: 1 2 3 4 5 6 7 8

Leave a Reply

Your email address will not be published. Required fields are marked *