将@Value传递给直方图存储桶时为Nullpointer

时间:2019-02-23 07:40:13

标签: spring-boot prometheus

如何将@Value从Yaml文件传递到Histogram.build()。buckets?

Yaml:histogram_buckets:[0.05、0.1、0.25、0.5、1.0]

代码:

import org.springframework.beans.factory.annotation.value;
import org.springframework.stereotype.Component;

import io.prometheus.client.Histogram;
import io.prometheus.client.spring.boot.EnablePrometheusEndpoint;
import io.prometheus.client.spring.boot.EnableSpringBootMetricsCollector;

@EnablePrometheusEndpoint
@EnableSpringBootMetricsCollector
@Component

public class QueryStats {

@Value("${histogram_buckets}") private static double[] histogram_buckets;

private QueryStats(){}

public static final Histogram requestLatency = Histogram.build().buckets(histogram_buckets).name("request_time").help("time in servicing request").labelNames("service").register();

}

控制台:

原因:java.lang.NullPointerException:null     在io.prometheus.client.Histogram $ Builder.create(Histogram.java:77)〜[simpleclient-0.4.0.jar:na]     在io.prometheus.client.Histogram $ Builder.create(Histogram.java:72)〜[simpleclient-0.4.0.jar:na]

0 个答案:

没有答案