【问题标题】:How to set name for MeterRegistry httpRequest metrics?如何为 MeterRegistry httpRequest 指标设置名称?
【发布时间】:2019-12-02 13:32:29
【问题描述】:

大家晚上好。 我已经创建了 GraphiteMeterRegistry bean。

@Bean
    public GraphiteMeterRegistry meterRegistry(GraphiteConfig graphiteConfig) {
        String host;
        try {
            host = InetAddress.getLocalHost().getHostName().replaceAll("\\.","_");
        } catch (UnknownHostException e) {
            host = "test";
            log.warn("Host wasn't found", e);
        }

        String prefix = "lm." + host + ".";

        return new GraphiteMeterRegistry(graphiteConfig, Clock.SYSTEM,
                (id, convention) -> prefix + HierarchicalNameMapper.DEFAULT.toHierarchicalName(id, convention));
    }

它会发送默认的 stas、jvm、hiharicp、http 和 e.t.c,这很好。但是,当我想获取有关 httpRequests 到我的端点(称为“myendpoint”)的信息时,我发现它不是存储在 myendpoint 文件夹中,而是存储在每个 id 的百万个文件夹中(作为参数获取)。例如:

myendpoint&id=12345679
myendpoint&id=12345672
myendpoint&id=12345673
myendpoint&id=12345671 

但我希望这个名称对于同一个端点是相同的。你是怎么配置的?

【问题讨论】:

  • 在这种情况下这个 id 是路径/查询参数吗?这不应该添加到 Spring Boot 中的指标名称中。你能分享一下你是如何定义其余端点的吗?你的控制器类?

标签: spring-boot graphite micrometer


【解决方案1】:

春季文档说:

要自定义标签,根据您选择的客户端,您可以 提供一个实现 RestTemplateExchangeTagsProvider 的 @Bean 或 WebClientExchangeTagsProvider。

这里的问题是,如果你使用 servlet,而不是响应式,你需要实现的不是WebClientExchangeTagsProvider,而是WebMvcTagsProvider@Bean。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-20
    • 1970-01-01
    相关资源
    最近更新 更多