Skip to content

Commit

Permalink
Merge branch 'pre-release' into 'master'
Browse files Browse the repository at this point in the history
Add threads, logs etc.

See merge request openhab/prometheus-metrics!2
  • Loading branch information
Hanno - Felix Wagner committed Aug 7, 2018
2 parents 616cab6 + 18b29a3 commit bca3467
Show file tree
Hide file tree
Showing 38 changed files with 864 additions and 385 deletions.
2 changes: 2 additions & 0 deletions com.kuguhome.openhab.prometheusmetrics.p2site/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<artifact><id>net.sdruskat:net.sdruskat.fragment.sun.misc:1.0.0</id></artifact>
<artifact><id>io.prometheus:simpleclient:0.4.0</id></artifact>
<artifact><id>io.prometheus:simpleclient_common:0.4.0</id></artifact>
<artifact><id>io.prometheus:simpleclient_hotspot:0.4.0</id></artifact>
<artifact><id>com.neuronrobotics:nrjavaserial:3.14.0</id></artifact>
</artifacts>
</configuration>
</execution>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
20 changes: 16 additions & 4 deletions com.kuguhome.openhab.prometheusmetrics/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,31 @@ Bundle-SymbolicName: com.kuguhome.openhab.prometheusmetrics;singleton:=true
Bundle-Vendor: openHAB
Bundle-Version: 2.4.0.qualifier
Import-Package:
ch.qos.logback.classic;version="1.0.7";resolution:=optional,
ch.qos.logback.classic.spi;version="1.0.7";resolution:=optional,
ch.qos.logback.core;version="1.0.7";resolution:=optional,
ch.qos.logback.core.spi;version="1.0.7";resolution:=optional,
io.prometheus.client;version="0.4.0",
io.prometheus.client.exporter.common;version="0.4.0",
io.prometheus.client.hotspot;version="0.4.0",
io.swagger.annotations;version="1.5.7.SNAPSHOT",
javax.annotation.security;version="1.2.0",
javax.servlet;version="3.1.0",
javax.servlet.http;version="3.1.0",
javax.ws.rs;version="2.0.1",
javax.ws.rs.core;version="2.0.1",
org.apache.commons.collections;version="3.2.0",
org.apache.logging.log4j;version="2.8.1",
org.apache.logging.log4j.core;version="2.8.2",
org.apache.logging.log4j.core.appender;version="2.8.2",
org.apache.logging.log4j.core.config.plugins;version="2.8.2",
org.apache.logging.log4j.core.config.status;version="2.8.2",
org.apache.logging.log4j.spi;version="2.8.1",
org.apache.logging.log4j.status;version="2.8.1",
org.eclipse.jdt.annotation;resolution:=optional,
org.eclipse.smarthome.config.core,
org.eclipse.smarthome.config.discovery,
org.eclipse.smarthome.config.discovery.dto,
org.eclipse.smarthome.config.discovery.inbox,
org.eclipse.smarthome.config.discovery.inbox.events,
org.eclipse.smarthome.core.auth,
org.eclipse.smarthome.core.common,
org.eclipse.smarthome.core.common.registry,
org.eclipse.smarthome.core.events,
org.eclipse.smarthome.core.items.events,
Expand All @@ -49,8 +54,13 @@ Import-Package:
org.eclipse.smarthome.core.types,
org.eclipse.smarthome.io.rest,
org.openhab.ui.dashboard,
org.ops4j.pax.logging;version="1.10.1",
org.ops4j.pax.logging.avalon;version="1.10.1",
org.ops4j.pax.logging.slf4j;version="1.10.1",
org.ops4j.pax.logging.spi;version="1.10.1",
org.osgi.framework,
org.osgi.framework.launch;version="1.2.0",
org.osgi.service.cm;version="1.5.0",
org.osgi.service.component;version="1.3.0",
org.osgi.service.component.annotations;version="1.3.0";resolution:=optional,
org.osgi.service.event;version="1.3.1",
Expand All @@ -60,5 +70,7 @@ Service-Component: OSGI-INF/*.xml
Automatic-Module-Name: com.kuguhome.openhab.prometheusmetrics
Require-Bundle: system.bundle,
org.slf4j.log4j;resolution:=optional
Export-Package: com.kuguhome.openhab.prometheusmetrics.api
Bundle-Activator: com.kuguhome.openhab.prometheusmetrics.internal.PrometheusMetricsActivator


Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" deactivate="deactivate" name="com.kuguhome.openhab.prometheusmetrics.api.DefaultMetricManager">
<service>
<provide interface="com.kuguhome.openhab.prometheusmetrics.api.DefaultMetricManager"/>
<provide interface="com.kuguhome.openhab.prometheusmetrics.api.MetricManager"/>
</service>
<implementation class="com.kuguhome.openhab.prometheusmetrics.api.DefaultMetricManager"/>
</scr:component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" deactivate="deactivate" name="com.kuguhome.openhab.prometheusmetrics.exposable.InboxCountMetric">
<service>
<provide interface="com.kuguhome.openhab.prometheusmetrics.exposable.InboxCountMetric"/>
<provide interface="com.kuguhome.openhab.prometheusmetrics.api.RESTExposable"/>
</service>
<reference bind="setInbox" cardinality="1..1" interface="org.eclipse.smarthome.config.discovery.inbox.Inbox" name="Inbox" policy="dynamic" unbind="unsetInbox"/>
<implementation class="com.kuguhome.openhab.prometheusmetrics.exposable.InboxCountMetric"/>
</scr:component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="com.kuguhome.openhab.prometheusmetrics.exposable.LoggerMetric">
<service>
<provide interface="com.kuguhome.openhab.prometheusmetrics.exposable.LoggerMetric"/>
<provide interface="com.kuguhome.openhab.prometheusmetrics.api.RESTExposable"/>
</service>
<implementation class="com.kuguhome.openhab.prometheusmetrics.exposable.LoggerMetric"/>
</scr:component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" deactivate="deactivate" name="com.kuguhome.openhab.prometheusmetrics.exposable.OpenHABBundleStateMetric">
<service>
<provide interface="com.kuguhome.openhab.prometheusmetrics.exposable.OpenHABBundleStateMetric"/>
<provide interface="com.kuguhome.openhab.prometheusmetrics.api.RESTExposable"/>
</service>
<implementation class="com.kuguhome.openhab.prometheusmetrics.exposable.OpenHABBundleStateMetric"/>
</scr:component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" deactivate="deactivate" name="com.kuguhome.openhab.prometheusmetrics.exposable.OpenHABThingStateMetric">
<service>
<provide interface="com.kuguhome.openhab.prometheusmetrics.exposable.OpenHABThingStateMetric"/>
<provide interface="com.kuguhome.openhab.prometheusmetrics.api.RESTExposable"/>
</service>
<reference bind="setThingRegistry" cardinality="1..1" interface="org.eclipse.smarthome.core.thing.ThingRegistry" name="ThingRegistry" policy="dynamic" unbind="unsetThingRegistry"/>
<implementation class="com.kuguhome.openhab.prometheusmetrics.exposable.OpenHABThingStateMetric"/>
</scr:component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" deactivate="deactivate" name="com.kuguhome.openhab.prometheusmetrics.exposable.SmarthomeEventCountMetric">
<service>
<provide interface="com.kuguhome.openhab.prometheusmetrics.exposable.SmarthomeEventCountMetric"/>
<provide interface="com.kuguhome.openhab.prometheusmetrics.api.RESTExposable"/>
<provide interface="org.eclipse.smarthome.core.events.EventSubscriber"/>
</service>
<implementation class="com.kuguhome.openhab.prometheusmetrics.exposable.SmarthomeEventCountMetric"/>
</scr:component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" activate="activate" deactivate="deactivate" name="com.kuguhome.openhab.prometheusmetrics.exposable.ThreadPoolMetric">
<service>
<provide interface="com.kuguhome.openhab.prometheusmetrics.exposable.ThreadPoolMetric"/>
<provide interface="com.kuguhome.openhab.prometheusmetrics.api.RESTExposable"/>
</service>
<reference cardinality="1..1" field="threadPoolManager" interface="com.kuguhome.openhab.prometheusmetrics.internal.KuguThreadPoolManager" name="threadPoolManager"/>
<implementation class="com.kuguhome.openhab.prometheusmetrics.exposable.ThreadPoolMetric"/>
</scr:component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" name="com.kuguhome.openhab.prometheusmetrics.internal.KuguAppender">
<service>
<provide interface="org.ops4j.pax.logging.spi.PaxAppender"/>
</service>
<implementation class="com.kuguhome.openhab.prometheusmetrics.internal.KuguAppender"/>
</scr:component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="com.kuguhome.openhab.prometheusmetrics.internal.KuguThreadPoolManager">
<service>
<provide interface="com.kuguhome.openhab.prometheusmetrics.internal.KuguThreadPoolManager"/>
<provide interface="org.eclipse.smarthome.core.common.ThreadPoolManager"/>
</service>
<implementation class="com.kuguhome.openhab.prometheusmetrics.internal.KuguThreadPoolManager"/>
</scr:component>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" deactivate="deactivate" name="com.kuguhome.openhab.prometheusmetrics.rest.PrometheusMetricsRESTResource">
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" activate="activate" deactivate="deactivate" name="com.kuguhome.openhab.prometheusmetrics.rest.PrometheusMetricsRESTResource">
<service>
<provide interface="org.eclipse.smarthome.core.events.EventSubscriber"/>
<provide interface="org.osgi.service.event.EventHandler"/>
<provide interface="org.eclipse.smarthome.io.rest.RESTResource"/>
<provide interface="com.kuguhome.openhab.prometheusmetrics.rest.PrometheusMetricsRESTResource"/>
</service>
<reference bind="setEventSubscriber" interface="org.eclipse.smarthome.core.events.EventSubscriber" name="EventSubscriber"/>
<reference bind="setHttpService" interface="org.osgi.service.http.HttpService" name="HttpService" unbind="unsetHttpService"/>
<reference bind="setInbox" cardinality="0..1" interface="org.eclipse.smarthome.config.discovery.inbox.Inbox" name="Inbox" policy="dynamic" unbind="unsetInbox"/>
<reference bind="setThingRegistry" interface="org.eclipse.smarthome.core.thing.ThingRegistry" name="ThingRegistry" unbind="unsetThingRegistry"/>
<reference cardinality="1..1" field="httpService" interface="org.osgi.service.http.HttpService" name="httpService"/>
<reference cardinality="1..1" field="inboxCountMetric" interface="com.kuguhome.openhab.prometheusmetrics.exposable.InboxCountMetric" name="inboxCountMetric" policy="dynamic"/>
<reference cardinality="1..1" field="metricManager" interface="com.kuguhome.openhab.prometheusmetrics.api.DefaultMetricManager" name="metricManager"/>
<reference cardinality="1..1" field="openHABBundleStateMetric" interface="com.kuguhome.openhab.prometheusmetrics.exposable.OpenHABBundleStateMetric" name="openHABBundleStateMetric" policy="dynamic"/>
<reference cardinality="1..1" field="openHABThingStateMetric" interface="com.kuguhome.openhab.prometheusmetrics.exposable.OpenHABThingStateMetric" name="openHABThingStateMetric" policy="dynamic"/>
<reference cardinality="1..1" field="smarthomeEventCountMetric" interface="com.kuguhome.openhab.prometheusmetrics.exposable.SmarthomeEventCountMetric" name="smarthomeEventCountMetric" policy="dynamic"/>
<reference cardinality="1..1" field="threadPoolMetric" interface="com.kuguhome.openhab.prometheusmetrics.exposable.ThreadPoolMetric" name="threadPoolMetric" policy="dynamic"/>
<implementation class="com.kuguhome.openhab.prometheusmetrics.rest.PrometheusMetricsRESTResource"/>
</scr:component>
17 changes: 17 additions & 0 deletions com.kuguhome.openhab.prometheusmetrics/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
cd ..
mvn clean
cd com.kuguhome.openhab.prometheusmetrics.p2site/
mvn p2:site
cd ..
mvn install
cd com.kuguhome.openhab.prometheusmetrics/
echo "Copying artifact to Raspberry Pi..."
scp target/*.jar kugu-sz-roman:/usr/share/openhab2/addons
echo "Deploying artifact to Raspberry Pi..."
ssh kugu-sz-roman sudo systemctl restart openhab2
echo "Waiting till application being started..."
sleep 30s
sleep 60s
echo "Fetching Rasberry Pi endpoint $1"
curl $1
35 changes: 35 additions & 0 deletions com.kuguhome.openhab.prometheusmetrics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,34 @@
<version>2.11.0</version>
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.ops4j.pax.logging/pax-logging-service -->
<dependency>
<groupId>org.ops4j.pax.logging</groupId>
<artifactId>pax-logging-service</artifactId>
<version>1.10.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.ops4j.pax.logging/pax-logging-api -->
<dependency>
<groupId>org.ops4j.pax.logging</groupId>
<artifactId>pax-logging-api</artifactId>
<version>1.10.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.ops4j.pax.logging/pax-logging-log4j2 -->
<dependency>
<groupId>org.ops4j.pax.logging</groupId>
<artifactId>pax-logging-log4j2</artifactId>
<version>1.10.1</version>
</dependency>


<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
Expand All @@ -98,6 +126,13 @@
<artifactId>simpleclient_common</artifactId>
<version>0.4.0</version>
</dependency>

<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_hotspot</artifactId>
<version>0.4.0</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.kuguhome.openhab.prometheusmetrics.api;

import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This class describes the default implementation of MetricManager
*
* @author Roman Malyugin
*
*/

@Component(service = { DefaultMetricManager.class, MetricManager.class })
public class DefaultMetricManager implements MetricManager {

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

private List<RESTExposable> exposables = new CopyOnWriteArrayList<>();

@Override
public List<RESTExposable> getExposables() {
return Collections.unmodifiableList(exposables);
}

@Activate
protected void activate() {
logger.info(DefaultMetricManager.class.getName() + " activated.");
}

@Deactivate
protected void deactivate() {
logger.info(DefaultMetricManager.class.getName() + " deactivated.");
}

@Override
public void registerMetric(RESTExposable exposable) {
exposables.add(exposable);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.kuguhome.openhab.prometheusmetrics.api;

import java.util.List;

/**
* This interface describes the interaction between metrics and REST service
*
* @author Roman Malyugin
*
*/

public interface MetricManager {

List<RESTExposable> getExposables();

void registerMetric(RESTExposable exposable);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.kuguhome.openhab.prometheusmetrics.api;

import java.util.Map;

public interface MetricSettable extends RESTExposable {

void set(String metricName, double metricValue, Map<String, Double> labelsValues);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.kuguhome.openhab.prometheusmetrics.api;

import io.prometheus.client.CollectorRegistry;

/**
* This interface describes exposure of metric to REST service
*
* @author Roman Malyugin
*
*/

public interface RESTExposable {

static final CollectorRegistry restRegistry = CollectorRegistry.defaultRegistry;

void expose();

}
Loading

0 comments on commit bca3467

Please sign in to comment.