English 中文(简体)
• 如何在微米分配中标出动态值
原标题:How to log dynamic values for the tags in micrometer DistributionSummary

I would like to log dynamic tag values for the DistrbutionSummary metric, how can I do that?

在以下例子中,有一个称为“我方”的标签,我希望根据所收到的数据,将标记的价值记录在传单上。 我可能想把分发摘要记录下来的多个方面,除非实时,否则我不会知道这些标签价值。

DistributionSummary histogram = DistributionSummary.builder("my_histogram")
            .description("Example histogram")
            .baseUnit("ms")
            .publishPercentiles(0.5, 0.95)
            .tags("myTag", "myTagVal")
            .serviceLevelObjectives(100.0, 500.0, 1000.0)
            .distributionStatisticExpiry(Duration.ofMinutes(5))
            .distributionStatisticBufferLength(3)
            .register(meterRegistry);

For eg., Metrics.counter from micrometer has a way to pass the value for the tags on the fly while incrementing or recording the value. how can we do the same in DistributionSummary?

Metrics.counter("eventsProcessed", "myTag", anyValue).increment(count);
问题回答

你在你的问题中采取同样的方式:

DistributionSummary.builder("test.distribution")
        .tag("static", "abc")
        .tag("dynamic", tagValue) // comes from a variable dynamically
        .register(meterRegistry)
        .record(value);

<编码>register Basic means create NewOrGetExmain。 而且,自微观参数1.12.0以来,我们有。 为此:

MeterProvider<DistributionSummary> distributionProvider = DistributionSummary.builder("test.distribution")
        .tag("static", "abc")
        .withRegistry(registry);

// [...]

distributionProvider.withTags(Tags.of("dynamic", tagValue)).record(value);

其他几个想法:

我曾遇到过这一问题,并通过阅读源码找到解决办法。 你们可以采用以下方法实现动态调整。 The pseudocode:

private final String LISTED_MARKET_SSE = "SSE";
private final String LISTED_MARKET_SZE = "SZE";

@Override
public void bindTo(@NonNull MeterRegistry meterRegistry) {
    String tagListedMarket = "listed_market";
    String upstream7101LatencyName = "kafkaConsumer.upstream.7101.latency";
    upstream7101LatencySummary = DistributionSummary.builder(upstream7101LatencyName)
            .baseUnit("ms")
            .tag(tagListedMarket, "")
            .publishPercentiles(0.99, 0.95, 0.5)
            .register(meterRegistry);
    upstream7101LatencySummarySZE = DistributionSummary.builder(upstream7101LatencyName)
            .baseUnit("ms")
            .tag(tagListedMarket, LISTED_MARKET_SZE)
            .publishPercentiles(0.99, 0.95, 0.5)
            .register(meterRegistry);
    upstream7101LatencySummarySSE = DistributionSummary.builder(upstream7101LatencyName)
            .baseUnit("ms")
            .tag(tagListedMarket, LISTED_MARKET_SSE)
            .publishPercentiles(0.99, 0.95, 0.5)
            .register(meterRegistry);
}

然后使用:

    if (LISTED_MARKET_SSE.equals(listedMarket)) {
        upstream7101LatencySummarySSE.record(amount);
    }
    else if (LISTED_MARKET_SZE.equals(listedMarket)) {
        upstream7101LatencySummarySZE.record(amount);
    }
    else {
        upstream7101LatencySummary.record(amount);
    }




相关问题
Prometheus Java client manually exposing prometheus end point

I have a spring boot application where for certain legacy reasons I cannot use spring actuator. I was able to expose a prometheus end point and see a lot of default metrics. But I am not able to see ...

Grafana interval variable: minimum threshold function?

I m adding an interval variable to a dashboard to allow averaging some prometheus time series over an interval to get cleaner looking graphs. But I want to leave in the base sample rate (15s) so the ...

How to specify time range in {aggregate}_over_time?

I have a Grafana chart that makes use of the sum_over_time(data_source[$__interval]) and count_over_time(data_source[$__interval]) command in Prometheus. Normally, it is working fine. But, the ...

how to regex path in prometheus relabel_configs

i have a metric and label like this: namedprocess_namegroup_num_procs{groupname:"/data/home/user01/app.service.1/service"}, i want to get the last field: service, and the number in last but ...

Omit labels from series results PromQL

Suppose I write a basic PromQL query like this Query: kube_deployment_spec_replicas{} Result: kube_deployment_spec_replicas{deployment="mydeployment",endpoint="myendpoint",instance="myinstance",...

Last known timestamp of a metric sample?

How do I get the timestamp of the last known sample of a metric? I want to display a table that lists when was the last time a specific service was running before it disappeared (died or whatever). ...

热门标签