我正在尝试为我的Spring Boot(2.1.0.RELEASE)应用程序收集指标。具体来说,我想知道
执行器/actuator/metrics端点提供了很多信息,但是我不确定这些信息是否对我的情况有用。此外,有人可以告诉@Timed(或任何其他现成的注释)是否可用于实现这些统计信息,或者我必须在每个控制器方法中使用类似以下的内容:
/actuator/metrics
Timer timer = new SimpleMeterRegistry().timer("timer.name"); timer.record(() -> { // all logic here });
我尝试在控制器方法上使用@Timed,但它没有向/actuator/metrics端点添加任何新响应。
您可以使用Spring Boot /actuator/metrics/http.server.requests获取执行的所有端点,这些端点的计数,异常,结果,状态,总时间等如下。
/actuator/metrics/http.server.requests
如果您想查看特定端点的详细信息,则可以通过调用request来完成
localhost:8889/actuator/metrics/http.server.requests?tag=uri:<endPoint> localhost:8889/actuator/metrics/http.server.requests?tag=uri:/user/asset/getAllAssets localhost:8889/actuator/metrics/http.server.requests?tag=uri:/user/asset/getAllAssets&tag=status:200
COUNT
您将获得COUNT以 特定状态 调用特定端点的次数。 __
要获取执行端点的平均时间,您可以 TOTAL_TIME/COUNT对特定端点以及整个应用程序执行
TOTAL_TIME/COUNT
本地主机:8889 / actuator / metrics / http.server.requests
{ "name": "http.server.requests", "description": null, "baseUnit": "seconds", "measurements": [ { "statistic": "COUNT", "value": 3 }, { "statistic": "TOTAL_TIME", "value": 0.21817219999999998 }, { "statistic": "MAX", "value": 0.1379249 } ], "availableTags": [ { "tag": "exception", "values": [ "MethodArgumentTypeMismatchException", "None" ] }, { "tag": "method", "values": [ "GET" ] }, { "tag": "uri", "values": [ "/{id}.*", "/user/asset/getAsset/{assetId}", "/user/asset/getAllAssets" ] }, { "tag": "outcome", "values": [ "CLIENT_ERROR", "SUCCESS" ] }, { "tag": "status", "values": [ "400", "404", "200" ] } ] }
本地主机:8889 / actuator / metrics / http.server.requests?tag = uri:/ user / asset / getAllAssets
{ "name": "http.server.requests", "description": null, "baseUnit": "seconds", "measurements": [ { "statistic": "COUNT", "value": 1 }, { "statistic": "TOTAL_TIME", "value": 0.1379249 }, { "statistic": "MAX", "value": 0 } ], "availableTags": [ { "tag": "exception", "values": [ "None" ] }, { "tag": "method", "values": [ "GET" ] }, { "tag": "outcome", "values": [ "SUCCESS" ] }, { "tag": "status", "values": [ "200" ] } ] }