You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置Stagemonitor仅采集指定方法的指标,屏蔽不需要的方法?

How to Exclude Specific Method/Endpoint Metrics in Stagemonitor

Absolutely, you can filter out unwanted metrics in Stagemonitor so only your target methods' data shows up—perfect for your PetClinic testing scenario. Here are three reliable approaches to hide that /owners/test endpoint's metrics:

1. Use Stagemonitor's Built-in Configuration Filters (No Code Changes Needed)

This is the simplest way if you don't want to modify your controller code. Just add exclusion rules to your configuration file (either stagemonitor.properties or Spring Boot's application.properties):

Exclude by HTTP Endpoint

To block metrics for the /owners/test path specifically:

stagemonitor.instrument.http.exclude-paths=/owners/test

You can also use wildcards if you need to exclude multiple similar paths, like */test*.

Exclude by Java Method Signature

If you want to target the exact testing method regardless of its endpoint mapping:

stagemonitor.instrument.method.exclude-methods=com.yourpackage.OwnerController.testing(java.util.Map)

Replace com.yourpackage.OwnerController with the actual full class path of your controller. Wildcards work here too—for example, *Controller.testing* would match any controller's testing method.

2. Mark the Method as Unmonitored with an Annotation

Stagemonitor provides a @NotMonitored annotation that tells the agent to skip collecting metrics for the annotated method. Just add it directly to your test method:

@NotMonitored
@RequestMapping(value = "/owners/test", method = RequestMethod.GET)
public String testing(Map<String, Object> model) {
    Owner owner = new Owner();
    model.put("owner", owner);
    return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
}

This makes the exclusion explicit right in your code, which is great for clarity.

3. Custom Monitoring Interceptor (For Advanced Filtering)

If you need more complex logic (like excluding methods based on dynamic conditions), you can create a custom interceptor to control what gets monitored:

import org.stagemonitor.core.monitor.MonitorInterceptor;
import org.stagemonitor.core.monitor.MonitorRequest;

public class CustomMetricFilter implements MonitorInterceptor {
    @Override
    public boolean preMonitor(MonitorRequest monitorRequest) {
        // Skip monitoring for the "testing" method
        return !monitorRequest.getMethodName().equals("testing");
    }
}

Then register this interceptor in your Stagemonitor configuration to activate it.

Verify the Fix

After applying any of these changes, restart your PetClinic application, trigger the /owners/test endpoint, and check the Stagemonitor browser widget—you should no longer see metrics for that method, while your desired methods' data remains visible.

内容的提问来源于stack exchange,提问作者Shehan Perera

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:46:26