[metrics] Catch any Throwable during initialization (#2480)

Signed-off-by: Fabian Wolter <github@fabian-wolter.de>
This commit is contained in:
Fabian Wolter 2021-09-11 15:20:49 +02:00 committed by GitHub
parent ff2f90684f
commit c2a41549c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -83,6 +83,7 @@ public class DefaultMetricsRegistration implements ReadyService.ReadyTracker, Me
}
private void registerMeters() {
try {
logger.debug("Registering meters...");
Set<Tag> tags = Set.of(OH_CORE_METRIC_TAG);
meters.add(new JVMMetric(tags));
@ -94,10 +95,19 @@ public class DefaultMetricsRegistration implements ReadyService.ReadyTracker, Me
meters.add(new ThreadPoolMetric(tags));
meters.forEach(m -> m.bindTo(registry));
} catch (Throwable e) {
// handle exceptions gracefully to not break StartLevelService run
logger.error("Exception caught during meter registration", e);
}
}
private void unregisterMeters() {
this.meters.forEach(OpenhabCoreMeterBinder::unbind);
try {
meters.forEach(OpenhabCoreMeterBinder::unbind);
} catch (Throwable e) {
// handle exceptions gracefully to not break StartLevelService run
logger.error("Exception caught during meter de-registration", e);
}
}
@Override