繁体   English   中英

使用 SPF4J Java Profiler 监控 REST API 端点的性能

[英]Monitor performance of REST API endpoints using the SPF4J Java Profiler

我有许多 REST API 端点,我想分别测量每个端点的时序指标。 使用 @PerformanceMonitor 注释方法有效,但 recorderSource 字段采用 class 并且无法为每个方法传递唯一的forWhat描述符。 我是否需要为每个端点创建一个子 class + 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();
}

如果您使用 recorderSource=RecorderSourceInstance.Rs15m.class

在您的情况下,forWhat 将是“RecorderSourceInstance.Rs15m,YourClassName.getAllProducts”

因此,您不需要为每个方法创建自定义 RecorderSourceInstance。

您可以选择的另一个选择是在较低级别测量您的指标,例如在 servlet 过滤器 这将使您更全面地了解服务器端执行时间(将包括 ser/deser、io...)。

您可以prometheus 格式或以prometheus 格式查看此指标。 此现场演示在 GKE 上运行,源代码位于. 有关此演示中展示的一些想法的更多详细信息,请参阅 wiki

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM