firstpostcommenter
firstpostcommenter

Reputation: 2911

Get the count per status in micrometer @Timed annotation

I am using @Timed annotation in SpringBoot application to monitor a method. I also want to know the count of response per status.

@GetMapping("/status/{productNumber}", produces = [MediaType.APPLICATION_JSON_VALUE])
@Timed(value = "status.productnumber", description = "Timed information retrieveProduct()")
fun retrieveProduct(@PathVariable productNumber: String): ResponseEntity {

When I open http://localhost:8080/actuator/metrics/status.productnumber I see:

{
    "name": "status.productnumber",
    "description": "Timed information retrieveProduct()",
    "base_unit": "seconds",
    "measurements": [
        {
            "statistic": "COUNT",
            "value": 3.0
        },
        {
            "statistic": "TOTAL_TIME",
            "value": 0.515840608
        },
        {
            "statistic": "MAX",
            "value": 0.006641343
        }
    ],
    "available_tags": [
        {
            "tag": "exception",
            "values": [
                "None",
                "RuntimeException"
            ]
        },
        {
            "tag": "method",
            "values": [
                "GET"
            ]
        },
        {
            "tag": "uri",
            "values": [
                "/status/{productNumber}"
            ]
        },
        {
            "tag": "outcome",
            "values": [
                "SERVER_ERROR",
                "SUCCESS"
            ]
        },
        {
            "tag": "status",
            "values": [
                "500",
                "200"
            ]
        }
    ]
}

Here the COUNT statistic shows the total number of times this endpoint or method is accessed. Can I know the count per status? I want to know how many times 500 status code has occurred

Upvotes: 2

Views: 3019

Answers (1)

Jonatan Ivanov
Jonatan Ivanov

Reputation: 6863

You can query the tags this way: /actuator/metrics/status.productnumber?tag=status:500, please see the docs.

A couple of side notes:

  • The metrics endpoint is for metrics debugging/troubleshooting purposes, it does not substitute a metrics backend, it should not be used instead of it in prod
  • I'm not sure I get what is the purpose of status.productnumber by reading its name

Upvotes: 3

Related Questions