![](/img/trans.png)
[英]How to show Dropwizard Metrics Servlet with spring-boot?
[英]Dropwizard metrics annotations are not working in Spring Boot 1.5
我已經將基於Spring Boot(1.5)的應用程序與Dropwizard Metrics&Prometheus集成在一起。 當我在Controller類中使用“ metricRegistry.mark()”方法時,可以在Prometheus中看到DropWizard指標。
現在,我想顯示與異常相關的指標,因此我添加了:
@ExceptionMetered(name="getMessages", cause=Exception.class)
@Counted(name = "getMessages")
public ResponseEntity<List<Message>> getMessages() {
但是當我點擊時,沒有任何與異常相關的東西出現: http:// localhost:9001 / metrics http:// localhost:9001 / prometheus
我也嘗試啟用ConsoleReporter:
@PostConstruct
public void startConsoleReporter() {
consoleReporter = ConsoleReporter.forRegistry(dropwizardMetricRegistry)
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.build();
consoleReporter.start(5, TimeUnit.SECONDS);
}
但是它一直顯示:
-- Meters ----------------------------------------------------------------------
myMeter
count = 0
mean rate = 0.00 events/second
1-minute rate = 0.00 events/second
5-minute rate = 0.00 events/second
15-minute rate = 0.00 events/second
如何獲得DropWizard注釋以與Sprint Boot 1.5一起使用?
為了使Dropwizard注釋在Spring Boot中工作,您需要一個類似Spring的Metrics的附加組件。 我已經在一個項目中成功地使用它來連接Dropwizard,Spring和Prometheus。
您將在此存儲庫中找到一個最小的版本v0.1版本: https : //github.com/ahus1/prometheusspringbootminimal/tree/v0.1
請注意,該存儲庫中的更高版本已通過Spring Boot 1.5遷移到Micrometer,后來又通過Spring Boot 2.0遷移到Micrometer。 我建議使用千分尺代替Dropwizard將有關度量描述的其他信息添加到Prometheus中。 如果您希望獲得支持以說服您的管理層,請使用直接郵件聯系。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.