Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP][prometheusexporter] Initial contribution #9726

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
/bundles/org.openhab.binding.plclogo/ @falkena
/bundles/org.openhab.binding.plugwise/ @wborn
/bundles/org.openhab.binding.powermax/ @lolodomo
/bundles/org.openhab.binding.prometheusexporter/ @pravussum
/bundles/org.openhab.binding.pulseaudio/ @peuter
/bundles/org.openhab.binding.pushbullet/ @hakan42
/bundles/org.openhab.binding.pushover/ @cweitkamp
Expand Down
5 changes: 5 additions & 0 deletions bom/openhab-addons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,11 @@
<artifactId>org.openhab.binding.powermax</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.prometheusexporter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.pulseaudio</artifactId>
Expand Down
13 changes: 13 additions & 0 deletions bundles/org.openhab.binding.prometheusexporter/NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
This content is produced and maintained by the openHAB project.

* Project home: https://www.openhab.org

== Declared Project Licenses

This program and the accompanying materials are made available under the terms
of the Eclipse Public License 2.0 which is available at
https://www.eclipse.org/legal/epl-2.0/.

== Source Code

https://github.com/openhab/openhab-addons
150 changes: 150 additions & 0 deletions bundles/org.openhab.binding.prometheusexporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# PrometheusExporter Binding

The PrometheusExporter binding provides openHAB internals like event counts, thread pool statistics, item states and JVM metrics in a [Prometheus](https://prometheus.io/) compatible format.
This allows for monitoring and alerting of the openHAB instance and for creation of monitoring dashboards using e. g. [Grafana](https://grafana.com)

![img.png](screenshot_grafana_jvm_and_events.png)
![img_1.png](screenshot_grafana_internals.png)
![img_2.png](screenshot_grafana_operational.png)

## Supported Things

There is only a single thing.
### TODO

## Discovery

### TODO implement and describe

_Describe the available auto-discovery features here. Mention for what it works and what needs to be kept in mind when using it._

## Binding Configuration

_If your binding requires or supports general configuration settings, please create a folder ```cfg``` and place the configuration file ```<bindingId>.cfg``` inside it. In this section, you should link to this file and provide some information about the options. The file could e.g. look like:_

```
# Configuration for the Philips Hue Binding
#
# Default secret key for the pairing of the Philips Hue Bridge.
# It has to be between 10-40 (alphanumeric) characters
# This may be changed by the user for security reasons.
secret=openHABSecret
```

_Note that it is planned to generate some part of this based on the information that is available within ```src/main/resources/OH-INF/binding``` of your binding._

_If your binding does not offer any generic configurations, you can remove this section completely._

## Thing Configuration

_Describe what is needed to manually configure a thing, either through the (Paper) UI or via a thing-file. This should be mainly about its mandatory and optional configuration parameters. A short example entry for a thing file can help!_

_Note that it is planned to generate some part of this based on the XML files within ```src/main/resources/OH-INF/thing``` of your binding._

## Channels


<table>
<thead>
<td><b>channel</b></td>
<td><b>type</b></td>
<td><b>description</b></td>
</thead>
<tbody>
<tr>
<td>bundlestate</td>
<td>String</td>
<td>This channel provides bundle state metrics for the bundles in the openHAB instance. By default, only org.openhab.* bundles are monitored. This can be configured. The name of the metric is <tt>openhab_bundle_state</tt> (Gauge).</td>
</tr>
<tr>
<td>eventcount</td>
<td>String</td>
<td>This channel provides event count metrics per topic under the metric name <tt>event_count</tt> (Counter). The topic name is added as label <tt>topic</tt>.</td>
</tr>
<tr>
<td>jvm</td>
<td>String</td>
<td><p>This channels provides exhaustive JVM metrics.</p>
The Following metrics are provided:
<ul>
<li>process_cpu_seconds_total</li>
<li>process_start_time_seconds</li>
<li>process_open_fds</li>
<li>process_max_fds</li>
<li>process_virtual_memory_bytes</li>
<li>process_resident_memory_bytes</li>
<li>jvm_memory_bytes_used</li>
<li>jvm_memory_bytes_committed</li>
<li>jvm_memory_bytes_max</li>
<li>jvm_memory_bytes_init</li>
<li>jvm_memory_pool_bytes_used</li>
<li>jvm_memory_pool_bytes_committed</li>
<li>jvm_memory_pool_bytes_max</li>
<li>jvm_memory_pool_bytes_init</li>
<li>jvm_memory_pool_allocated_bytes_total</li>
<li>jvm_buffer_pool_used_bytes</li>
<li>jvm_buffer_pool_capacity_bytes</li>
<li>jvm_buffer_pool_used_buffers</li>
<li>jvm_gc_collection_seconds</li>
<li>jvm_threads_current</li>
<li>jvm_threads_daemon</li>
<li>jvm_threads_peak</li>
<li>jvm_threads_started_total</li>
<li>jvm_threads_deadlocked</li>
<li>jvm_threads_deadlocked_monitor</li>
<li>jvm_threads_state</li>
<li>jvm_classes_loaded</li>
<li>jvm_classes_loaded_total</li>
<li>jvm_classes_unloaded_total</li>
<li>jvm_info</li>
</ul>
</td>
</tr>
<tr>
<td>inboxcount</td>
<td>String</td>
<td>This channel provides the inbox count under a metric named <tt>openhab_inbox_count</tt> (Gauge). </td>
</tr>
<tr>
<td>thingstate</td>
<td>String</td>
<td>This channel provides things state metrics. The name of the metric is <tt>openhab_thing_state</tt> (Gauge)</td>
</tr>
<tr>
<td>threadpools</td>
<td>String</td>
<td>This channel provides extensive thread pool metrics for the thread pools in use by the openHAB instance.<br>
Each metric is labeled with the name of the corresponding thread pool under the <tt>pool</tt> label.<br>
The following metrics are provided:<ul>
<li><tt>openhab_pool_threads_count_active</tt></li>
<li><tt>openhab_pool_threads_count_current</tt></li>
<li><tt>openhab_pool_tasks_count_completed</tt></li>
<li><tt>openhab_pool_threads_count_largest</tt></li>
<li><tt>openhab_pool_size_max</tt></li>
<li><tt>openhab_pool_tasks_count_total</tt></li>
<li><tt>openhab_pool_size</tt></li>
<li><tt>openhab_pool_queue_count</tt></li>
<li><tt>openhab_pool_keepalive_time_seconds</tt></li>
</ul>
</td>
</tr>
<tr>
<td>all</td>
<td>String</td>
<td>This channel provides all of the above metrics.</td>
</tr>
</tbody>
</table>

## Full Example

_Provide a full usage example based on textual configuration files (*.things, *.items, *.sitemap)._

## Compatibility notes

There used to be a binding providing Prometheus metrics, which isn't compatible with current openHAB versions.
I tried to keep the metric names as close as possible to the this one in order to not break too many existing dashboards.
There are some differences, though:

* the metric `smarthome_event_count` doesn't exist. The metric `event_count` provides something similar. Instead of a `source` label it provides a `topic` label which contains the originating topic name. Events are not filtered (they used to be filtered by the "smarthome/" prefix in the old binding).

39 changes: 39 additions & 0 deletions bundles/org.openhab.binding.prometheusexporter/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.addons.reactor.bundles</artifactId>
<version>3.1.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.binding.prometheusexporter</artifactId>

<name>openHAB Add-ons :: Bundles :: PrometheusExporter Binding</name>

<properties>
<bnd.importpackage>com.sun.management;resolution:=optional</bnd.importpackage>
</properties>

<dependencies>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_hotspot</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_common</artifactId>
<version>0.9.0</version>
</dependency>
</dependencies>

</project>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

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

-->
<features name="org.openhab.binding.prometheusexporter-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features</repository>

<feature name="openhab-binding-prometheusexporter" description="PrometheusExporter Binding" version="${project.version}">
<feature>openhab-runtime-base</feature>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.prometheusexporter/${project.version}</bundle>
</feature>
</features>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* 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.binding.prometheusexporter;

import java.util.Map;
import java.util.Set;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.prometheusexporter.internal.PrometheusExporterBindingConstants;
import org.openhab.core.config.discovery.AbstractDiscoveryService;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
import org.openhab.core.config.discovery.DiscoveryService;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* The {@link PrometheusExportDiscoveryService} class ...
*
* @author Robert Bach - Initial contribution
*/
@Component(service = DiscoveryService.class)
@NonNullByDefault
public class PrometheusExportDiscoveryService extends AbstractDiscoveryService {

private final Logger logger = LoggerFactory.getLogger(PrometheusExportDiscoveryService.class);

public PrometheusExportDiscoveryService() {
super(PrometheusExporterBindingConstants.SUPPORTED_THING_TYPES_UIDS, 15);
}

@Override
protected void startScan() {
logger.debug("Adding prometheus exporter generic thing to inbox...");
ThingUID uid = new ThingUID(PrometheusExporterBindingConstants.THING_TYPE_GENERIC,
"prometheus-exporter-generic");
DiscoveryResult result = DiscoveryResultBuilder.create(uid).withLabel("Generic Prometheus exporter")
.withProperties(Map.of("bundleStatePackageFilter", "org.openhab", "refreshInterval", 60)).build();
thingDiscovered(result);
}

@Override
public Set<ThingTypeUID> getSupportedThingTypes() {
return PrometheusExporterBindingConstants.SUPPORTED_THING_TYPES_UIDS;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* 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.binding.prometheusexporter.internal;

import java.util.Collections;
import java.util.Set;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.ThingTypeUID;

/**
* The {@link PrometheusExporterBindingConstants} class defines common constants, which are
* used across the whole binding.
*
* @author Robert Bach - Initial contribution
*/
@NonNullByDefault
public class PrometheusExporterBindingConstants {

private static final String BINDING_ID = "prometheusexporter";

// List of all Thing Type UIDs
public static final ThingTypeUID THING_TYPE_GENERIC = new ThingTypeUID(BINDING_ID, "generic");

// The thing type as a set
public static Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_GENERIC);

// List of all Channel ids
public static final String CHANNEL_BUNDLE_STATE = "bundlestate";
public static final String CHANNEL_EVENT_COUNT = "eventcount";
public static final String CHANNEL_JVM = "jvm";
public static final String CHANNEL_INBOX_COUNT = "inboxcount";
public static final String CHANNEL_THING_STATE = "thingstate";
public static final String CHANNEL_THREAD_POOLS = "threadpools";
public static final String CHANNEL_ALL = "all";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* 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.binding.prometheusexporter.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;

/**
* The {@link PrometheusExporterConfiguration} class contains fields mapping thing configuration parameters.
*
* @author Robert Bach - Initial contribution
*/
@NonNullByDefault
public class PrometheusExporterConfiguration {

@Nullable
public String bundleStatePackageFilter;
@Nullable
public Integer refreshInterval;
}
Loading