到目前为止,为了使用微米获取Quarkus上的百分位数,需要使用计时注释,如下所示
@GET
@Produces(MediaType.TEXT_PLAIN)
@Timed(percentiles = {0.5,0.7,0.9})
public String hello() {
return "Hello RESTEasy";
}我对此行为的主要问题是,有必要在每个Rest端点上放置此计时注释。有没有办法使用来自quarkus的微米将一些百分比设置为Rest端点的默认值?(我知道使用microprofiler是可行的,但他们建议使用测微仪)
发布于 2021-06-02 09:53:58
Quarkus测微器支持已经为所有rest端点发送计时器(除非您已禁用该功能)。您需要显式地使用MeterFilter (一般绑定或仅绑定到注册表类型)为现有的http服务器请求计时器启用额外数据的收集。类似这样的内容,例如:
/** Enable histogram buckets for a specific timer */
@Produces
@Singleton
public MeterFilter enableHistogram() {
return new MeterFilter() {
@Override
public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) {
if(id.getName().startsWith("http.server.requests")) {
return DistributionStatisticConfig.builder()
.percentiles(0.5, 0.95) // median and 95th percentile, not aggregable
.percentilesHistogram(true) // histogram buckets (e.g. prometheus histogram_quantile)
.build()
.merge(config);
}
return config;
}
};
}查看发出的指标以确保存在http服务器请求指标(它们在此过程中没有被禁用),然后考虑应该应用于预收集直方图或百分位数据的条件(因为它可能很昂贵)。
参考文献:
https://stackoverflow.com/questions/65306016
复制相似问题