4

Small question regarding Spring Boot, and how to get the http response status code and display them into Grafana please.

Setup: a Java SpringBoot application at 2.5.1 (relevant to any SpringBoot 2.x.x). The app has actuator and micrometer dependencies. App generates prometheus metrics fine.

I am very interested in this one dashboard: The https response status code. Not the time elapsed, not the count, just the http status code response (responded with 200, 401, 503, etc). Because of the dependencies, I see those metrics!

http_server_requests_seconds

Hence, I first tried this:

increase(http_server_requests_seconds{_ws_="my_workspace",_ns_="my_namespace",_source_="my_source", _bucket_="+Inf"}[15m])

This seems to yield something:

enter image description here

I am able to see some http 200, some http 503. But for some reason, I am also seeing not only one 200, but bunch of them with what seems to be a time elapsed.

My question is, the query is not correct? What would be the most appropriate query in order to get the different http status code response over time please?

Most of all, what would be the best visualization dashboard to represents the difference HTTP status code response?

Thank you

4

1 回答 1

4

Grafana 将为您在 Prometheus 查询中找到的每个不同标签添加一行。当您定义不包含所有不同标签的图例时,您将看到具有相同图例的多行。

increase(http_server_requests_seconds_count{}[1m])与传说{{status}}

示例相同的传说

如果您删除图例的定义,您应该能够看到所有标签以确定哪些标签创建了重复值。

increase(http_server_requests_seconds_count{}[1m])没有图例定义:

示例-1

如果您对查询进行更多限制,例如通过添加条件{method="POST"},则行数也会减少:

示例-2

另一种选择是聚合您的结果以消除标签。根据问题,您希望查看每个 HTTP 状态代码的总增长量。这是我找到一种可视化的好方法的示例:

sum(increase(http_server_requests_seconds_count{}[1m])) by (status)与传说{{status}}

示例聚合

于 2021-07-07T06:10:12.683 回答