| 知乎专栏 |
package cn.netkiller.config;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.context.annotation.Configuration;
import java.util.*;
@Configuration
@Endpoint(id = "netkiller")
public class TestEndpoint {
@ReadOperation
public Map<String, Object> threadPoolsMetric() {
Map<String, Object> metricMap = new HashMap<>();
List<Map> threadPools = new ArrayList<>();
Map<String, Object> poolInfo = new HashMap<>();
poolInfo.put("thread.pool.name", "netkiller");
poolInfo.put("thread.pool.core.size", 100);
poolInfo.put("thread.pool.time", new Date());
threadPools.add(poolInfo);
metricMap.put("netkiller", threadPools);
return metricMap;
}
}
验证
neo@MacBook-Pro-M2 ~> curl -s http://www.netkiller.cn:8080/actuator/netkiller | jq
{
"netkiller": [
{
"thread.pool.time": "2023-04-24T09:08:14.407+00:00",
"thread.pool.core.size": 100,
"thread.pool.name": "netkiller"
}
]
}