diff --git a/bundles/org.openhab.core.io.monitor/bnd.bnd b/bundles/org.openhab.core.io.monitor/bnd.bnd index 36d286027be..f40f8337c3e 100644 --- a/bundles/org.openhab.core.io.monitor/bnd.bnd +++ b/bundles/org.openhab.core.io.monitor/bnd.bnd @@ -6,4 +6,6 @@ Import-Package: \ org.osgi.service.*,\ org.slf4j.*,\ com.google.gson.*;version="[2.8,3)" -Export-Package: io.micrometer.core.* +Export-Package: io.micrometer.core.*;-split-package:=merge-first,\ + org.HdrHistogram.*;-split-package:=merge-first,\ + org.LatencyUtils.*;-split-package:=merge-first diff --git a/bundles/org.openhab.core.io.monitor/pom.xml b/bundles/org.openhab.core.io.monitor/pom.xml index cb0d57b4452..206758bab9f 100644 --- a/bundles/org.openhab.core.io.monitor/pom.xml +++ b/bundles/org.openhab.core.io.monitor/pom.xml @@ -31,6 +31,24 @@ 1.6.3 compile + + org.hdrhistogram + HdrHistogram + 2.1.12 + compile + + + org.latencyutils + LatencyUtils + 2.0.3 + compile + + + org.hdrhistogram + HdrHistogram + + + diff --git a/bundles/org.openhab.core.io.monitor/src/main/java/org/openhab/core/io/monitor/internal/metrics/RuleMetric.java b/bundles/org.openhab.core.io.monitor/src/main/java/org/openhab/core/io/monitor/internal/metrics/RuleMetric.java index d0b811b25e0..3605eb1e86a 100644 --- a/bundles/org.openhab.core.io.monitor/src/main/java/org/openhab/core/io/monitor/internal/metrics/RuleMetric.java +++ b/bundles/org.openhab.core.io.monitor/src/main/java/org/openhab/core/io/monitor/internal/metrics/RuleMetric.java @@ -65,7 +65,7 @@ public RuleMetric(BundleContext bundleContext, Collection tags, RuleRegistr } @Override - public void bindTo(@io.micrometer.core.lang.NonNull MeterRegistry meterRegistry) { + public void bindTo(MeterRegistry meterRegistry) { unbind(); logger.debug("RuleMetric is being bound..."); this.meterRegistry = meterRegistry; @@ -77,18 +77,20 @@ public void bindTo(@io.micrometer.core.lang.NonNull MeterRegistry meterRegistry) @Override public void unbind() { - if (meterRegistry == null) { + MeterRegistry mReg = meterRegistry; + if (mReg == null) { return; - } - for (Meter meter : meterRegistry.getMeters()) { - if (meter.getId().getTags().contains(CORE_RULE_METRIC_TAG)) { - meterRegistry.remove(meter); + } else { + for (Meter meter : mReg.getMeters()) { + if (meter.getId().getTags().contains(CORE_RULE_METRIC_TAG)) { + mReg.remove(meter); + } + } + meterRegistry = null; + if (this.eventSubscriberRegistration != null) { + this.eventSubscriberRegistration.unregister(); + this.eventSubscriberRegistration = null; } - } - meterRegistry = null; - if (this.eventSubscriberRegistration != null) { - this.eventSubscriberRegistration.unregister(); - this.eventSubscriberRegistration = null; } } @@ -106,25 +108,27 @@ public Set getSubscribedEventTypes() { @Override public void receive(Event event) { - if (meterRegistry == null) { + MeterRegistry mReg = meterRegistry; + if (mReg == null) { logger.trace("Measurement not started. Skipping rule event processing"); return; - } - String topic = event.getTopic(); - String ruleId = topic.substring(RULES_TOPIC_PREFIX.length(), topic.indexOf(RULES_TOPIC_SUFFIX)); - if (!event.getPayload().contains(RuleStatus.RUNNING.name())) { - logger.trace("Skipping rule status info with status other than RUNNING {}", event.getPayload()); - return; - } + } else { + String topic = event.getTopic(); + String ruleId = topic.substring(RULES_TOPIC_PREFIX.length(), topic.indexOf(RULES_TOPIC_SUFFIX)); + if (!event.getPayload().contains(RuleStatus.RUNNING.name())) { + logger.trace("Skipping rule status info with status other than RUNNING {}", event.getPayload()); + return; + } - logger.debug("Rule {} RUNNING - updating metric.", ruleId); - Set tagsWithRule = new HashSet<>(tags); - tagsWithRule.add(Tag.of(RULE_ID_TAG_NAME, ruleId)); - String ruleName = getRuleName(ruleId); - if (ruleName != null) { - tagsWithRule.add(Tag.of(RULE_NAME_TAG_NAME, ruleName)); + logger.debug("Rule {} RUNNING - updating metric.", ruleId); + Set tagsWithRule = new HashSet<>(tags); + tagsWithRule.add(Tag.of(RULE_ID_TAG_NAME, ruleId)); + String ruleName = getRuleName(ruleId); + if (ruleName != null) { + tagsWithRule.add(Tag.of(RULE_NAME_TAG_NAME, ruleName)); + } + mReg.counter(METRIC_NAME, tagsWithRule).increment(); } - meterRegistry.counter(METRIC_NAME, tagsWithRule).increment(); } private String getRuleName(String ruleId) {