forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[metrics] Add Java Management Extensions (JMX) metrics exporter (open…
…hab#11249) * Add Java Management Extensions (JMX) metrics exporter * Use groups in metrics add-on configuration * Improve null annotations * Update documentation Signed-off-by: Wouter Born <github@maindrain.net> Signed-off-by: Dave J Schoepel <dave@theschoepels.com>
- Loading branch information
Showing
8 changed files
with
152 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...openhab.io.metrics/src/main/java/org/openhab/io/metrics/exporters/JmxMetricsExporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* Copyright (c) 2010-2021 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.io.metrics.exporters; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.openhab.io.metrics.MetricsConfiguration; | ||
import org.openhab.io.metrics.MetricsExporter; | ||
|
||
import io.micrometer.core.instrument.Clock; | ||
import io.micrometer.core.instrument.composite.CompositeMeterRegistry; | ||
import io.micrometer.jmx.JmxConfig; | ||
import io.micrometer.jmx.JmxMeterRegistry; | ||
|
||
/** | ||
* The {@link JmxMetricsExporter} class implements a MetricsExporter for Java Management Extensions (JMX). | ||
* | ||
* @author Wouter Born - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class JmxMetricsExporter extends MetricsExporter { | ||
|
||
private @Nullable JmxMeterRegistry jmxMeterRegistry; | ||
private @Nullable CompositeMeterRegistry meterRegistry; | ||
|
||
@Override | ||
public void start(CompositeMeterRegistry meterRegistry, MetricsConfiguration metricsConfiguration) { | ||
jmxMeterRegistry = new JmxMeterRegistry(getJmxConfig(), Clock.SYSTEM); | ||
meterRegistry.add(jmxMeterRegistry); | ||
} | ||
|
||
@Override | ||
public void shutdown() { | ||
JmxMeterRegistry jmxMeterRegistry = this.jmxMeterRegistry; | ||
if (jmxMeterRegistry != null) { | ||
jmxMeterRegistry.stop(); | ||
this.jmxMeterRegistry = null; | ||
} | ||
|
||
CompositeMeterRegistry meterRegistry = this.meterRegistry; | ||
if (meterRegistry != null) { | ||
meterRegistry.remove(jmxMeterRegistry); | ||
this.meterRegistry = null; | ||
} | ||
} | ||
|
||
private JmxConfig getJmxConfig() { | ||
return new JmxConfig() { | ||
@Override | ||
@io.micrometer.core.lang.Nullable | ||
@Nullable | ||
public String get(@Nullable String k) { | ||
return null; // accept the rest of the defaults | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
protected boolean isEnabled(MetricsConfiguration config) { | ||
return config.jmxMetricsEnabled; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters