[ 
https://issues.apache.org/jira/browse/KARAF-5462?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16342582#comment-16342582
 ] 

ASF GitHub Bot commented on KARAF-5462:
---------------------------------------

jbonofre closed pull request #30: [KARAF-5462] Add dropwizard metric collector 
& appender
URL: https://github.com/apache/karaf-decanter/pull/30
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/README b/README
index deb850d..d41f5de 100644
--- a/README
+++ b/README
@@ -41,9 +41,8 @@ Apache Karaf Decanter is composed into:
 
 Getting Started
 ===============
-Apache Karaf Decanter is available as a Karaf features. The commands below 
start 
-the jmx collector, log collector and an appender to a local elasticsearch 
instance
-on the default port. Prerquisite is a running elasticsearch instance.
+Apache Karaf Decanter is available as a Karaf features. The following command 
registers
+the Karaf Decanter features repository.
 
 feature:repo-add decanter
 
@@ -57,43 +56,42 @@ See user guide for the details of Decanter features:
 
 Collectors
 -----------
-* decanter-collector-log
-* decanter-collector-log-socket
-* decanter-collector-file
+* decanter-collector-camel
+* decanter-collector-dropwizard
 * decanter-collector-eventadmin
+* decanter-collector-file
 * decanter-collector-jms
 * decanter-collector-jmx
 * decanter-collector-kafka
-* decanter-collector-rest
-* decanter-collector-jmx-activemq
-* decanter-collector-jmx-camel
-* decanter-collector-camel
+* decanter-collector-log
+* decanter-collector-log4j-socket
 * decanter-collector-mqtt
+* decanter-collector-process
 * decanter-collector-rest
 * decanter-collector-rest-servlet
 * decanter-collector-socket
 * decanter-collector-system
-* decanter-collector-process
 
 Appenders
 ---------
-* decanter-appender-log
+* decanter-appender-camel
+* decanter-appender-cassandra
+* decanter-appender-dropwizard
 * decanter-appender-elasticsearch-jest
-* decanter-appender-elasticsearch-rest
 * decanter-appender-elasticsearch-native-1.x
 * decanter-appender-elasticsearch-native-2.x
+* decanter-appender-elasticsearch-rest
 * decanter-appender-file
 * decanter-appender-jdbc
 * decanter-appender-jms
-* decanter-appender-camel
-* decanter-appender-mqtt
 * decanter-appender-kafka
-* decanter-appender-cassandra
+* decanter-appender-log
 * decanter-appender-mongodb
-* decanter-appender-socket
+* decanter-appender-mqtt
+* decanter-appender-orientdb
 * decanter-appender-redis
 * decanter-appender-rest
-* decanter-appender-orientdb
+* decanter-appender-socket
 
 Alerters
 ------------
diff --git a/appender/dropwizard/pom.xml b/appender/dropwizard/pom.xml
new file mode 100644
index 0000000..8f36e32
--- /dev/null
+++ b/appender/dropwizard/pom.xml
@@ -0,0 +1,26 @@
+<?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";>
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.karaf.decanter</groupId>
+        <artifactId>appender</artifactId>
+        <version>2.0.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <groupId>org.apache.karaf.decanter.appender</groupId>
+    <artifactId>org.apache.karaf.decanter.appender.dropwizard</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Karaf :: Decanter :: Appender :: Dropwizard Metrics</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>io.dropwizard.metrics</groupId>
+            <artifactId>metrics-core</artifactId>
+            <version>4.0.0</version>
+        </dependency>
+    </dependencies>
+
+</project>
\ No newline at end of file
diff --git 
a/appender/dropwizard/src/main/java/org/apache/karaf/decanter/appender/dropwizard/DropwizardMetricsAppender.java
 
b/appender/dropwizard/src/main/java/org/apache/karaf/decanter/appender/dropwizard/DropwizardMetricsAppender.java
new file mode 100644
index 0000000..3568dc1
--- /dev/null
+++ 
b/appender/dropwizard/src/main/java/org/apache/karaf/decanter/appender/dropwizard/DropwizardMetricsAppender.java
@@ -0,0 +1,51 @@
+/*
+ * 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.dropwizard;
+
+import com.codahale.metrics.Gauge;
+import com.codahale.metrics.MetricRegistry;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventConstants;
+import org.osgi.service.event.EventHandler;
+
+@Component(
+        name = "org.apache.karaf.decanter.appender.dropwizard",
+        immediate = true,
+        property = EventConstants.EVENT_TOPIC + "=decanter/collect/*"
+)
+public class DropwizardMetricsAppender implements EventHandler {
+
+    private final MetricRegistry registry = new MetricRegistry();
+
+    @Override
+    public void handleEvent(Event event) {
+        for (String propertyName : event.getPropertyNames()) {
+            final Object value = event.getProperty(propertyName);
+            if (value instanceof Number) {
+                registry.register(propertyName, new Gauge<Number>() {
+                    @Override
+                    public Number getValue() {
+                        return (Number) value;
+                    }
+                });
+            }
+        }
+    }
+
+
+}
diff --git a/appender/pom.xml b/appender/pom.xml
index ffa8a39..160b49e 100644
--- a/appender/pom.xml
+++ b/appender/pom.xml
@@ -36,6 +36,7 @@
     <modules>
         <module>camel</module>
         <module>cassandra</module>
+        <module>dropwizard</module>
         <module>elasticsearch-native-1.x</module>
         <module>elasticsearch-native-2.x</module>
         <module>elasticsearch-jest</module>
diff --git a/assembly/src/main/feature/feature.xml 
b/assembly/src/main/feature/feature.xml
index 4756418..591e4b3 100644
--- a/assembly/src/main/feature/feature.xml
+++ b/assembly/src/main/feature/feature.xml
@@ -35,6 +35,13 @@
         
<bundle>mvn:org.apache.karaf.decanter.marshaller/org.apache.karaf.decanter.marshaller.csv/${project.version}</bundle>
     </feature>
 
+    <feature name="decanter-collector-dropwizard" version="${project.version}" 
description="Karaf Decanter Dropwizard Metrics Collector">
+        <feature>decanter-common</feature>
+        <feature>scheduler</feature>
+        <bundle 
dependency="true">mvn:io.dropwizard.metrics/metrics-core/4.0.0</bundle>
+        
<bundle>mvn:org.apache.karaf.decanter.collector/org.apache.karaf.decanter.collector.dropwizard/${project.version}</bundle>
+    </feature>
+
     <feature name="decanter-collector-log" version="${project.version}" 
description="Karaf Decanter Log Messages Collector">
         <feature>decanter-common</feature>
         
<bundle>mvn:org.apache.karaf.decanter.collector/org.apache.karaf.decanter.collector.log/${project.version}</bundle>
@@ -373,6 +380,12 @@
         <configfile 
finalname="/etc/org.apache.karaf.decanter.appender.socket.cfg">mvn:org.apache.karaf.decanter.appender/org.apache.karaf.decanter.appender.socket/${project.version}/cfg</configfile>
     </feature>
 
+    <feature name="decanter-appender-dropwizard" version="${project.version}" 
description="Karaf Decanter Dropwizard Metrics Appender">
+        <feature>decanter-common</feature>
+        <bundle 
dependency="true">mvn:io.dropwizard.metrics/metrics-core/4.0.0</bundle>
+        
<bundle>mvn:org.apache.karaf.decanter.appender/org.apache.karaf.decanter.appender.dropwizard/${project.version}</bundle>
+    </feature>
+
     <feature name="decanter-alerting-core" version="${project.version}" 
description="Karaf Decanter Alerting core">
         <feature>decanter-common</feature>
         
<bundle>mvn:org.apache.karaf.decanter.alerting/org.apache.karaf.decanter.alerting.checker/${project.version}</bundle>
diff --git a/collector/dropwizard/pom.xml b/collector/dropwizard/pom.xml
new file mode 100644
index 0000000..96322e2
--- /dev/null
+++ b/collector/dropwizard/pom.xml
@@ -0,0 +1,26 @@
+<?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";>
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.karaf.decanter</groupId>
+        <artifactId>collector</artifactId>
+        <version>2.0.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <groupId>org.apache.karaf.decanter.collector</groupId>
+    <artifactId>org.apache.karaf.decanter.collector.dropwizard</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Karaf :: Decanter :: Collector :: DropWizard</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>io.dropwizard.metrics</groupId>
+            <artifactId>metrics-core</artifactId>
+            <version>4.0.0</version>
+        </dependency>
+    </dependencies>
+
+</project>
\ No newline at end of file
diff --git 
a/collector/dropwizard/src/main/java/org/apache/karaf/decanter/collector/dropwizard/DecanterReporterCollector.java
 
b/collector/dropwizard/src/main/java/org/apache/karaf/decanter/collector/dropwizard/DecanterReporterCollector.java
new file mode 100644
index 0000000..c3b175b
--- /dev/null
+++ 
b/collector/dropwizard/src/main/java/org/apache/karaf/decanter/collector/dropwizard/DecanterReporterCollector.java
@@ -0,0 +1,116 @@
+/**
+ * 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.collector.dropwizard;
+
+import com.codahale.metrics.*;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+@Component(
+        name = "org.apache.karaf.decanter.collector.dropwizard",
+        immediate = true,
+        property = { "decanter.collector.name=dropwizard",
+                "scheduler.period:Long=60",
+                "scheduler.concurrent:Boolean=false",
+                "scheduler.name=decanter-collector-dropwizard"}
+)
+public class DecanterReporterCollector implements Runnable {
+
+    @Reference
+    public EventAdmin dispatcher;
+
+    @Reference(cardinality = ReferenceCardinality.OPTIONAL)
+    public MetricSet metricRegistry;
+
+    @Override
+    public void run() {
+        Map<String, Metric> metrics = metricRegistry.getMetrics();
+        for (String metricName : metrics.keySet()) {
+            Metric metric = metrics.get(metricName);
+            Map<String, Object> data = new HashMap<>();
+            data.put("type", "dropwizard");
+            data.put("karafName", System.getProperty("karaf.name"));
+            try {
+                data.put("hostAddress", 
InetAddress.getLocalHost().getHostAddress());
+                data.put("hostName", InetAddress.getLocalHost().getHostName());
+            } catch (Exception e) {
+                // nothing to do
+            }
+            if (metric instanceof Gauge) {
+                Gauge gauge = (Gauge) metric;
+                Object value = gauge.getValue();
+                data.put("metric", "gauge");
+                data.put("value", value);
+            }
+            if (metric instanceof Counter) {
+                Counter counter = (Counter) metric;
+                data.put("metric", "counter");
+                data.put("count", counter.getCount());
+            }
+            if (metric instanceof Histogram) {
+                Histogram histogram = (Histogram) metric;
+                data.put("metric", "histogram");
+                data.put("count", histogram.getCount());
+                populateSnapshot(histogram.getSnapshot(), data);
+            }
+            if (metric instanceof Meter) {
+                Meter meter = (Meter) metric;
+                data.put("metric", "meter");
+                data.put("count", meter.getCount());
+                data.put("15 Minute Rate", meter.getFifteenMinuteRate());
+                data.put("5 Minute Rate", meter.getFiveMinuteRate());
+                data.put("1 Minute Rate", meter.getOneMinuteRate());
+                data.put("Mean Rate", meter.getMeanRate());
+            }
+            if (metric instanceof Timer) {
+                Timer timer = (Timer) metric;
+                data.put("metric", "timer");
+                data.put("count", timer.getCount());
+                data.put("15 Minute Rate", timer.getFifteenMinuteRate());
+                data.put("5 Minute Rate", timer.getFiveMinuteRate());
+                data.put("1 Minute Rate", timer.getOneMinuteRate());
+                data.put("Mean Rate", timer.getMeanRate());
+                populateSnapshot(timer.getSnapshot(), data);
+            }
+            Event event = new Event("decanter/collect/dropwizard", data);
+            dispatcher.postEvent(event);
+        }
+    }
+
+    private void populateSnapshot(Snapshot snapshot, Map<String, Object> data) 
{
+        data.put("75th Percentile", snapshot.get75thPercentile());
+        data.put("95th Percentile", snapshot.get95thPercentile());
+        data.put("98th Përcentile", snapshot.get98thPercentile());
+        data.put("99th Percentile", snapshot.get99thPercentile());
+        data.put("999th Percentile", snapshot.get999thPercentile());
+        data.put("max", snapshot.getMax());
+        data.put("mean", snapshot.getMean());
+        data.put("median", snapshot.getMedian());
+        data.put("min", snapshot.getMin());
+        data.put("stddev", snapshot.getStdDev());
+    }
+
+}
diff --git a/collector/pom.xml b/collector/pom.xml
index cde4783..204d343 100644
--- a/collector/pom.xml
+++ b/collector/pom.xml
@@ -35,6 +35,7 @@
 
     <modules>
         <module>camel</module>
+        <module>dropwizard</module>
         <module>eventadmin</module>
         <module>file</module>
         <module>jms</module>
diff --git a/manual/src/main/asciidoc/user-guide/appenders.adoc 
b/manual/src/main/asciidoc/user-guide/appenders.adoc
index 2b706c3..0e9f9a7 100644
--- a/manual/src/main/asciidoc/user-guide/appenders.adoc
+++ b/manual/src/main/asciidoc/user-guide/appenders.adoc
@@ -1357,4 +1357,17 @@ The `orientdb` feature starts an OrientDB embedded 
datase. It also installs the
 Most of the values can be let as they are, however, you can tweak some:
 
 * `<listener/>` allows you to configure the protocol and port numbers used by 
the OrientDB instance. You can define the IP address on which the instance is 
bound (`ip-address`), the port numbers range to use (`port-range`) for each 
protocol (`binary` or `http`).
-* the `db.pool.min` and `db.pool.max` can be increased if you have a large 
number of connections on the instance.
\ No newline at end of file
+* the `db.pool.min` and `db.pool.max` can be increased if you have a large 
number of connections on the instance.
+
+==== Dropwizard Metrics
+
+The Dropwizard Metrics appender receives the harvested data from the 
dispatcher and push in a Dropwizard Metrics
+`MetricRegistry`. You can register this `MetricRegistry` in your own 
application or use a Dropwizard Metrics Reporter
+to "push" these metrics to some backend.
+
+The `decanter-appender-dropwizard` feature provides the Decanter event handler 
registering the harvested data ino the
+`MetricRegistry`:
+
+----
+karaf@root()> feature:install decanter-appender-dropwizard
+----
\ No newline at end of file
diff --git a/manual/src/main/asciidoc/user-guide/collectors.adoc 
b/manual/src/main/asciidoc/user-guide/collectors.adoc
index ab8a2b1..f840e33 100644
--- a/manual/src/main/asciidoc/user-guide/collectors.adoc
+++ b/manual/src/main/asciidoc/user-guide/collectors.adoc
@@ -641,3 +641,16 @@ The `decanter-collector-rest-servlet` feature installs the 
collector:
 ----
 karaf@root()> feature:install decanter-collector-rest-servlet
 ----
+
+==== Dropwizard Metrics
+
+The Decanter Dropwizard Metrics collector get a `MetricSet` OSGi service and 
periodically get the metrics in the set.
+
+The `decanter-collector-dropwizard` feature installs the collector:
+
+----
+karaf@root()> feature:install decanter-collector-dropwizard
+----
+
+As soon as a `MetricSet` (like `MetricRegistry`) service will be available, 
the collector will get the metrics and
+send to the Decanter dispatcher.
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 5ffc19a..96897ff 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,16 +1,23 @@
 <?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. -->
+    <!--
+
+        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>
 
@@ -63,8 +70,8 @@
         <module>alerting</module>
         <module>backend</module>
         <module>spring-boot-starter-decanter</module>
-        <module>assembly</module>
         <module>tools-jar-wrapper</module>
+        <module>assembly</module>
     </modules>
 
     <scm>


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Provide Decanter DropWizard Metric integration
> ----------------------------------------------
>
>                 Key: KARAF-5462
>                 URL: https://issues.apache.org/jira/browse/KARAF-5462
>             Project: Karaf
>          Issue Type: New Feature
>          Components: decanter
>            Reporter: Jean-Baptiste Onofré
>            Assignee: Jean-Baptiste Onofré
>            Priority: Major
>             Fix For: decanter-2.0.0
>
>
> DropWizard (http://www.dropwizard.io) is a popular Java framework, especially 
> easily providing metrics (http://metrics.dropwizard.io).
> It would be great that Decanter can:
> - integration dropwizard (as appender)
> - easily interact with dropwizard to harvest metrics (collector)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to