我正在嘗試爲DropWizard指標創建一個自定義記者,但無法找到任何資源或示例來展示如何通過擴展ScheduledReporter
來創建一個。我可以通過跟蹤現有的記者(CSV,SLF4J等)來擴展這個類,但是我在哪裏註冊?DropWizard Custom Reporter
這裏是習俗記者的摘錄,我嘗試註冊:
public class DbReporter extends ScheduledReporter {
private final Connection connection;
private final Clock clock;
public static DbReporter.Builder forRegistry(MetricRegistry registry) {
return new DbReporter.Builder(registry);
}
private DbReporter(MetricRegistry registry, Connection connection, Clock clock, MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit) {
super(registry, "db-reporter", filter, rateUnit, durationUnit);
this.connection = connection;
this.clock = clock;
}
//...
public static class Builder {
private final MetricRegistry registry;
private Connection connection;
private TimeUnit rateUnit;
private TimeUnit durationUnit;
private MetricFilter filter;
private Clock clock;
private Builder(MetricRegistry registry) {
this.registry = registry;
this.connection = null;
this.rateUnit = TimeUnit.SECONDS;
this.durationUnit = TimeUnit.MILLISECONDS;
this.filter = MetricFilter.ALL;
this.clock = Clock.defaultClock();
}
public DbReporter.Builder outputTo(Connection connection) {
this.connection = connection;
return this;
}
public DbReporter.Builder convertRatesTo(TimeUnit rateUnit) {
this.rateUnit = rateUnit;
return this;
}
public DbReporter.Builder convertDurationsTo(TimeUnit durationUnit) {
this.durationUnit = durationUnit;
return this;
}
public DbReporter.Builder filter(MetricFilter filter) {
this.filter = filter;
return this;
}
public DbReporter build() {
return new DbReporter(this.registry, this.connection, this.clock, this.filter, this.rateUnit, this.durationUnit);
}
}
}
而且,這是正確的方式來創建一個自定義的記者或者是有任何其他方式?
在此先感謝.-
是的,這是正確的做法。你註冊他們完全相同的方式註冊其他的(見指標文檔) – pandaadb
@pandaadb是的,但我沒有註冊任何東西。 –