我正在尝试为我的Spring Boot(2.1.0.RELEASE)应用程序收集指标。具体来说,我想知道
执行器/actuator/metrics
端点提供了很多信息,但是我不确定这些信息是否对我的情况有用。另外,有人可以告诉我们是否可以使用@Timed(或任何其他现成的注释)来实现这些统计信息,或者我必须在每个控制器方法中使用类似以下的内容:
Timer timer = new SimpleMeterRegistry().timer("timer.name");
timer.record(() -> {
// all logic here
});
我尝试在控制器方法上使用@Timed,但是它没有向/actuator/metrics
端点添加任何新响应。
答案 0 :(得分:5)
您可以使用Spring Boot /actuator/metrics/http.server.requests
获取执行的所有端点,这些端点的计数,异常,结果,状态,总时间等如下。
如果您想查看特定端点的详细信息,则可以通过按以下方式调用请求来实现
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
适用于特定的端点以及整个端点
应用localhost: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"
]
}
]
}
localhost: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"
]
}
]
}
答案 1 :(得分:0)
另一种方法是使用 Spring Boot Admin 。为此,我们必须配置客户端服务器。为避免该错误,请确保客户端-服务器依赖性的版本相同。我们可以从下拉列表中添加所需的指标,如图所示。
pom.xml
sender = df1.sender
recipient = df1.recipient
subject = df1.subject
n = 0
for i in sender:
df.loc[df["subject"] == str(i) and df["subject"] == str(i) , "email_id"] = n
n=n+1
application.properties
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.1.4</version>
</dependency>
application.properties
spring.boot.admin.api-path=/instances
spring.boot.admin.client.url=http://localhost:6699
management.endpoints.web.exposure.include=*
pom.xml
server.port = 6699
spring.boot.admin.server.url=http://localhost:8889
添加 <dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.1.4</version>
</dependency>
@EnableAdminServer