karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject [karaf-decanter] branch master updated: [KARAF-4777] Add InfluxDB appender
Date Fri, 15 Mar 2019 06:30:55 GMT
This is an automated email from the ASF dual-hosted git repository.

jbonofre pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/karaf-decanter.git


The following commit(s) were added to refs/heads/master by this push:
     new d1ebb47  [KARAF-4777] Add InfluxDB appender
     new b975738  Merge pull request #75 from jbonofre/KARAF-4777
d1ebb47 is described below

commit d1ebb47051301c003f3653b3ccf65cd4bb224a53
Author: Jean-Baptiste Onofré <jbonofre@apache.org>
AuthorDate: Wed Mar 13 18:57:11 2019 +0100

    [KARAF-4777] Add InfluxDB appender
---
 appender/influxdb/pom.xml                          | 103 ++++++++++++++++++++
 ...org.apache.karaf.decanter.appender.influxdb.cfg |  34 +++++++
 .../appender/influxdb/InfluxDbAppender.java        | 104 +++++++++++++++++++++
 appender/pom.xml                                   |   1 +
 assembly/src/main/feature/feature.xml              |  11 +++
 manual/src/main/asciidoc/user-guide/appenders.adoc |  34 +++++++
 6 files changed, 287 insertions(+)

diff --git a/appender/influxdb/pom.xml b/appender/influxdb/pom.xml
new file mode 100644
index 0000000..451e444
--- /dev/null
+++ b/appender/influxdb/pom.xml
@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <!--
+
+        Licensed to the Apache Software Foundation (ASF) under one or more
+        contributor license agreements.  See the NOTICE file distributed with
+        this work for additional information regarding copyright ownership.
+        The ASF licenses this file to You under the Apache License, Version 2.0
+        (the "License"); you may not use this file except in compliance with
+        the License.  You may obtain a copy of the License at
+
+           http://www.apache.org/licenses/LICENSE-2.0
+
+        Unless required by applicable law or agreed to in writing, software
+        distributed under the License is distributed on an "AS IS" BASIS,
+        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+        See the License for the specific language governing permissions and
+        limitations under the License.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.karaf.decanter</groupId>
+        <artifactId>appender</artifactId>
+        <version>2.2.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <groupId>org.apache.karaf.decanter.appender</groupId>
+    <artifactId>org.apache.karaf.decanter.appender.influxdb</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Karaf :: Decanter :: Appender :: InfluxDB</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.karaf.decanter</groupId>
+            <artifactId>org.apache.karaf.decanter.api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.karaf.decanter.appender</groupId>
+            <artifactId>org.apache.karaf.decanter.appender.utils</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.influxdb</groupId>
+            <artifactId>influxdb-java</artifactId>
+            <version>2.13</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <inherited>true</inherited>
+                <extensions>true</extensions>
+                <configuration>
+                    <obrRepository>NONE</obrRepository>
+                    <instructions>
+                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+                        <Export-Package>!*</Export-Package>
+                        <Import-Package>
+                            *
+                        </Import-Package>
+                        <Private-Package>
+                            org.apache.karaf.decanter.appender.influxdb,
+                            org.apache.karaf.decanter.appender.utils
+                        </Private-Package>
+                        <_dsannotations>*</_dsannotations>
+                    </instructions>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>attach-artifact</goal>
+                        </goals>
+                        <configuration>
+                            <artifacts>
+                                <artifact>
+                                    <file>src/main/cfg/org.apache.karaf.decanter.appender.influxdb.cfg</file>
+                                    <type>cfg</type>
+                                </artifact>
+                            </artifacts>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
\ No newline at end of file
diff --git a/appender/influxdb/src/main/cfg/org.apache.karaf.decanter.appender.influxdb.cfg
b/appender/influxdb/src/main/cfg/org.apache.karaf.decanter.appender.influxdb.cfg
new file mode 100644
index 0000000..9dab7aa
--- /dev/null
+++ b/appender/influxdb/src/main/cfg/org.apache.karaf.decanter.appender.influxdb.cfg
@@ -0,0 +1,34 @@
+################################################################################
+#
+#    Licensed to the Apache Software Foundation (ASF) under one or more
+#    contributor license agreements.  See the NOTICE file distributed with
+#    this work for additional information regarding copyright ownership.
+#    The ASF licenses this file to You under the Apache License, Version 2.0
+#    (the "License"); you may not use this file except in compliance with
+#    the License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+#
+################################################################################
+
+##########################################
+# Decanter InfluxDB Appender Configuration
+##########################################
+
+# URL of the InfluxDB database
+url=
+
+# InfluxDB server username
+#username=
+
+# InfluxDB server password
+#password=
+
+# InfluxDB database name
+database=decanter
\ No newline at end of file
diff --git a/appender/influxdb/src/main/java/org/apache/karaf/decanter/appender/influxdb/InfluxDbAppender.java
b/appender/influxdb/src/main/java/org/apache/karaf/decanter/appender/influxdb/InfluxDbAppender.java
new file mode 100644
index 0000000..783f051
--- /dev/null
+++ b/appender/influxdb/src/main/java/org/apache/karaf/decanter/appender/influxdb/InfluxDbAppender.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.decanter.appender.influxdb;
+
+import org.apache.karaf.decanter.appender.utils.EventFilter;
+import org.influxdb.InfluxDB;
+import org.influxdb.InfluxDBFactory;
+import org.influxdb.dto.Point;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventConstants;
+import org.osgi.service.event.EventHandler;
+
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+@Component(
+        name = "org.apache.karaf.decanter.appender.influxdb",
+        immediate = true,
+        property = EventConstants.EVENT_TOPIC + "=decanter/collect/*"
+)
+public class InfluxDbAppender implements EventHandler {
+
+    private Dictionary<String, Object> config;
+
+    private InfluxDB influxDB;
+
+    @Activate
+    public void activate(ComponentContext componentContext) {
+        activate(componentContext.getProperties());
+    }
+
+    public void activate(Dictionary<String, Object> config) {
+        this.config = config;
+        if (config.get("url") == null) {
+            throw new IllegalArgumentException("url property is mandatory");
+        }
+        String url = (String) config.get("url");
+        String username = null;
+        if (config.get("username") != null) {
+            username = (String) config.get("username");
+        }
+        String password = null;
+        if (config.get("password") != null) {
+            password = (String) config.get("password");
+        }
+        if (username != null) {
+            this.influxDB = InfluxDBFactory.connect(url, username, password);
+        } else {
+            this.influxDB = InfluxDBFactory.connect(url);
+        }
+        String database = "decanter";
+        if (config.get("database") != null) {
+            database = (String) config.get("database");
+        }
+        this.influxDB.enableBatch(100, 200, TimeUnit.MILLISECONDS);
+        this.influxDB.setRetentionPolicy("defaultPolicy");
+        this.influxDB.setDatabase(database);
+    }
+
+    @Deactivate
+    public void deactivate() {
+        if (influxDB != null) {
+            influxDB.close();
+        }
+    }
+
+    @Override
+    public void handleEvent(Event event) {
+        if (EventFilter.match(event, config)) {
+            String type = "decanter";
+            if (event.getProperty("type") != null) {
+                type = (String) event.getProperty("type");
+            }
+            Map<String, Object> data = new HashMap<>();
+            for (String propertyName : event.getPropertyNames()) {
+                Object propertyValue = event.getProperty(propertyName);
+                data.put(propertyName, propertyValue);
+            }
+            Point point = Point.measurement(type).fields(data).build();
+            influxDB.write(point);
+        }
+    }
+
+}
diff --git a/appender/pom.xml b/appender/pom.xml
index d021ddd..77c8144 100644
--- a/appender/pom.xml
+++ b/appender/pom.xml
@@ -43,6 +43,7 @@
         <module>elasticsearch-jest</module>
         <module>elasticsearch-rest</module>
         <module>file</module>
+        <module>influxdb</module>
         <module>jdbc</module>
         <module>jms</module>
         <module>kafka</module>
diff --git a/assembly/src/main/feature/feature.xml b/assembly/src/main/feature/feature.xml
index 5a0cc65..a438464 100644
--- a/assembly/src/main/feature/feature.xml
+++ b/assembly/src/main/feature/feature.xml
@@ -320,6 +320,17 @@
         <configfile finalname="/etc/org.apache.karaf.decanter.appender.mqtt.cfg">mvn:org.apache.karaf.decanter.appender/org.apache.karaf.decanter.appender.mqtt/${project.version}/cfg</configfile>
     </feature>
 
+    <feature name="decanter-appender-influxdb-core" version="${project.version}" description="Karaf
Decanter InfluxDB Appender core">
+        <feature>decanter-common</feature>
+        <bundle dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.influxdb/2.15_1</bundle>
+        <bundle>mvn:org.apache.karaf.decanter.appender/org.apache.karaf.decanter.appender.influxdb/${project.version}</bundle>
+    </feature>
+
+    <feature name="decanter-appender-influxdb" version="${project.version}" description="Karaf
Decanter InfluxDB Appender">
+        <feature>decanter-appender-influxdb-core</feature>
+        <configfile finalname="/etc/org.apache.karaf.decanter.appender.influxdb.cfg">mvn:org.apache.karaf.decanter.appender/org.apache.karaf.decanter.appender.influxdb/${project.version}/cfg</configfile>
+    </feature>
+
     <feature name="decanter-appender-cassandra-core" version="${project.version}" description="Karaf
Decanter Cassandra Appender core">
         <feature>decanter-common</feature>
         <bundle dependency="true">mvn:com.google.guava/guava/16.0.1</bundle>
diff --git a/manual/src/main/asciidoc/user-guide/appenders.adoc b/manual/src/main/asciidoc/user-guide/appenders.adoc
index b2eb136..455289a 100644
--- a/manual/src/main/asciidoc/user-guide/appenders.adoc
+++ b/manual/src/main/asciidoc/user-guide/appenders.adoc
@@ -1192,6 +1192,40 @@ cassandra.port=9042
 * the `cassandra.host` property contains the hostname or IP address where the Cassandra instance
is running (default is localhost)
 * the `cassandra.port` property contains the port number of the Cassandra instance (default
is 9042)
 
+==== InfluxDB
+
+The Decanter InfluxDB appender allows you to store the data (coming from the collectors)
as a time series into a InfluxDB database.
+
+The `decanter-appender-influxdb` feature installs this appender:
+
+----
+karaf@root()> feature:install decanter-appender-influxdb
+----
+
+This feature installs the appender and a default `etc/org.apache.karaf.decanter.appender.influxdb.cfg`
configuration file containing:
+
+----
+##########################################
+# Decanter InfluxDB Appender Configuration
+##########################################
+
+# URL of the InfluxDB database
+url=
+
+# InfluxDB server username
+#username=
+
+# InfluxDB server password
+#password=
+
+# InfluxDB database name
+database=decanter
+----
+
+* `url` property is mandatory and define the location of the InfluxDB server
+* `database` property contains the name of the InfluxDB database. Default is `decanter`.
+* `username` and `password` are optional and define the authentication to the InfluxDB server.
+
 ==== MongoDB
 
 The Decanter MongoDB appender allows you to store the data (coming from the collectors) into
a MongoDB database.


Mime
View raw message