Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
876 views
in Technique[技术] by (71.8m points)

spring-boot - 在Spring-boot 2中如何使用Actuator修改Prometheus公开的度量标准名称(How to modify prometheus exposed metric names using Actuator in Spring-boot 2)

I am using Actuator in springboot 2 to expose /actuator/prometheus endpoint from which a prometheus instance will pull metrics.

(我在springboot 2中使用Actuator公开了/ actuator / prometheus端点,prometheus实例将从该端点提取指标。)

Everithing works perfect except because I am in need of tweak the metric names.

(一切都很完美,除了因为我需要调整度量标准名称。)

I mean not the suffix (_count, _total, _bucket, ...) which are meaningful for Prometheus but something like:

(我的意思不是对Prometheus有意义的后缀(_count,_total,_bucket等),而是类似:)

http_server_requests_seconds_count -> http_server_requests_count http_server_requests_seconds_max -> latency_seconds_max http_server_requests_seconds_sum -> latency_seconds_sum http_server_requests_seconds_bucket -> latency_seconds_bucket

(http_server_requests_seconds_count-> http_server_requests_count http_server_requests_seconds_max->等待时间_seconds_max http_server_requests_seconds_sum->等待时间_seconds_sum http_server_requests_seconds_bucket-> delay_seconds_bucket)

Is there any better approach to this?

(有什么更好的办法吗?)

PS

(聚苯乙烯)

I know i can use

(我知道我可以用)

management.metrics.web.server.requests-metric-name=different

to get

(要得到)

different_seconds_count
different_seconds_max 
different_seconds_sum 
different_seconds_bucket

but it would be difficult to:

(但是很难:)

1o remove the _seconds suffix

(1o删除_seconds后缀)

2o use a different base name for only one of them

(2o仅对其中一个使用不同的基本名称)

I am guessing i could write an alternative PrometheusRenameFilter but not sure how to configure it to the default registry.

(我猜我可以写一个替代的PrometheusRenameFilter但不确定如何将其配置为默认注册表。)

  ask by Rafael translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Now I know how I can customize the global registry:

(现在,我知道如何自定义全局注册表了:)

eg to set a custom meter filter:

(例如,设置自定义仪表过滤器:)

@Configuration
public class MetricsConfig {
    @Bean
    MeterRegistryCustomizer<MeterRegistry> metricsConfig() {
        return registry -> registry.config().meterFilter(new CustomRenameFilter());
    }
}

However, setting a custom rename filter in the registry only allow to rename the base metric name.

(但是,在注册表中设置自定义重命名过滤器仅允许重命名基本度量标准名称。)

It does not act on the suffixes nor allow to act on specific metric belonging a set eg generated by the summary.

(它不作用于后缀,也不允许作用于属于一组(例如,由摘要生成)的特定度量。)

with a custom NamingConvention I can add suffixes to convention base name ... I could even alter existing suffixes or replace convention base name.

(使用自定义NamingConvention我可以将后缀添加到约定的基础名称中...甚至可以更改现有后缀或替换约定的基础名称。)

Finally please note that Histogram prometheus metric type expects the creation of

(最后请注意,直方图普罗米修斯度量标准类型期望创建)

<basename>_bucket
<basename>_sum
<basename>_count

with those specific names so it might be incorrect to tweak the component in the way I want because that would be a diferent component.

(使用这些特定的名称,因此按照我想要的方式来调整组件可能是不正确的,因为那将是不同的组件。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...