【发布时间】:2020-07-05 13:28:25
【问题描述】:
我有许多 REST API 端点,我想分别测量每个端点的计时指标。使用 @PerformanceMonitor 注释方法是可行的,但是 recorderSource 字段需要一个类,并且无法为每个方法传递唯一的 forWhat 描述符。我是否需要为每个端点 + HTTP 方法创建一个子类来定义一个唯一的 forWhat 字符串?这似乎不可扩展。我错过了什么吗?
以下是特定记录器源的示例:
import org.spf4j.annotations.RecorderSourceInstance;
import org.spf4j.perf.MeasurementRecorderSource;
import org.spf4j.perf.impl.RecorderFactory;
public static final class GetAllProductsRecorderSource extends RecorderSourceInstance {
public static final MeasurementRecorderSource INSTANCE;
static {
Object forWhat = "GetAllProducts";
INSTANCE = RecorderFactory.createScalableMinMaxAvgRecorderSource(forWhat, unitOfMeasurement, sampleTimeMillis);
}
}
这是带有注释的 REST 端点:
import org.spf4j.annotations.PerformanceMonitor;
@PerformanceMonitor(warnThresholdMillis=1, errorThresholdMillis=100, recorderSource=GetAllProductsRecorderSource.class)
@GetMapping("/products")
public List<Product> getAllProducts() throws IOException {
return productRepository.findAll();
}
【问题讨论】: