james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [03/14] james-project git commit: JAMES-1950 Introduce metrics logger implementation
Date Fri, 03 Mar 2017 17:26:11 GMT
JAMES-1950 Introduce metrics logger implementation


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/1e2d9f3b
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/1e2d9f3b
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/1e2d9f3b

Branch: refs/heads/master
Commit: 1e2d9f3b9c2be0a4e379ccddea8154053306a166
Parents: f7ed849
Author: Antoine Duprat <aduprat@linagora.com>
Authored: Thu Feb 23 16:02:44 2017 +0100
Committer: Antoine Duprat <aduprat@linagora.com>
Committed: Fri Mar 3 18:17:20 2017 +0100

----------------------------------------------------------------------
 metrics/metrics-logger/pom.xml                  | 49 ++++++++++++++++++++
 .../james/metrics/logger/DefaultMetric.java     | 43 +++++++++++++++++
 .../metrics/logger/DefaultMetricFactory.java    | 41 ++++++++++++++++
 .../james/metrics/logger/DefaultTimeMetric.java | 49 ++++++++++++++++++++
 metrics/pom.xml                                 |  1 +
 5 files changed, 183 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/1e2d9f3b/metrics/metrics-logger/pom.xml
----------------------------------------------------------------------
diff --git a/metrics/metrics-logger/pom.xml b/metrics/metrics-logger/pom.xml
new file mode 100644
index 0000000..0fef3a7
--- /dev/null
+++ b/metrics/metrics-logger/pom.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<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">
+    <parent>
+        <artifactId>metrics</artifactId>
+        <groupId>org.apache.james</groupId>
+        <version>3.0.0-beta6-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>metrics-logger</artifactId>
+
+    <name>Apache James :: Metrics :: Logger</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.james</groupId>
+            <artifactId>metrics-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>1.7.2</version>
+        </dependency>
+    </dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/james-project/blob/1e2d9f3b/metrics/metrics-logger/src/main/java/org/apache/james/metrics/logger/DefaultMetric.java
----------------------------------------------------------------------
diff --git a/metrics/metrics-logger/src/main/java/org/apache/james/metrics/logger/DefaultMetric.java
b/metrics/metrics-logger/src/main/java/org/apache/james/metrics/logger/DefaultMetric.java
new file mode 100644
index 0000000..3c80e4d
--- /dev/null
+++ b/metrics/metrics-logger/src/main/java/org/apache/james/metrics/logger/DefaultMetric.java
@@ -0,0 +1,43 @@
+/****************************************************************
+ * 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.james.metrics.logger;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.james.metrics.api.Metric;
+
+public class DefaultMetric implements Metric {
+
+    private AtomicInteger value;
+
+    public DefaultMetric() {
+        value = new AtomicInteger();
+    }
+
+    @Override
+    public void increment() {
+        value.incrementAndGet();
+    }
+
+    @Override
+    public void decrement() {
+        value.decrementAndGet();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/1e2d9f3b/metrics/metrics-logger/src/main/java/org/apache/james/metrics/logger/DefaultMetricFactory.java
----------------------------------------------------------------------
diff --git a/metrics/metrics-logger/src/main/java/org/apache/james/metrics/logger/DefaultMetricFactory.java
b/metrics/metrics-logger/src/main/java/org/apache/james/metrics/logger/DefaultMetricFactory.java
new file mode 100644
index 0000000..b00e3f3
--- /dev/null
+++ b/metrics/metrics-logger/src/main/java/org/apache/james/metrics/logger/DefaultMetricFactory.java
@@ -0,0 +1,41 @@
+/****************************************************************
+ * 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.james.metrics.logger;
+
+import org.apache.james.metrics.api.Metric;
+import org.apache.james.metrics.api.MetricFactory;
+import org.apache.james.metrics.api.TimeMetric;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DefaultMetricFactory implements MetricFactory {
+
+    public static final Logger LOGGER = LoggerFactory.getLogger(DefaultMetricFactory.class);
+
+    @Override
+    public Metric generate(String name) {
+        return new DefaultMetric();
+    }
+
+    @Override
+    public TimeMetric timer(String name) {
+        return new DefaultTimeMetric(name);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/1e2d9f3b/metrics/metrics-logger/src/main/java/org/apache/james/metrics/logger/DefaultTimeMetric.java
----------------------------------------------------------------------
diff --git a/metrics/metrics-logger/src/main/java/org/apache/james/metrics/logger/DefaultTimeMetric.java
b/metrics/metrics-logger/src/main/java/org/apache/james/metrics/logger/DefaultTimeMetric.java
new file mode 100644
index 0000000..24da728
--- /dev/null
+++ b/metrics/metrics-logger/src/main/java/org/apache/james/metrics/logger/DefaultTimeMetric.java
@@ -0,0 +1,49 @@
+/****************************************************************
+ * 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.james.metrics.logger;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.james.metrics.api.TimeMetric;
+
+import com.google.common.base.Stopwatch;
+
+public class DefaultTimeMetric implements TimeMetric {
+
+    private final String name;
+    private final Stopwatch stopwatch;
+
+    public DefaultTimeMetric(String name) {
+        this.name = name;
+        this.stopwatch = Stopwatch.createStarted();
+    }
+
+    @Override
+    public String name() {
+        return name;
+    }
+
+    @Override
+    public long stopAndPublish() {
+        long elapsed = stopwatch.elapsed(TimeUnit.MILLISECONDS);
+        DefaultMetricFactory.LOGGER.info("Time spent in " + name + ": " + elapsed + " ms.");
+        return elapsed;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/1e2d9f3b/metrics/pom.xml
----------------------------------------------------------------------
diff --git a/metrics/pom.xml b/metrics/pom.xml
index f6b854e..1fad2ef 100644
--- a/metrics/pom.xml
+++ b/metrics/pom.xml
@@ -35,6 +35,7 @@
     <modules>
         <module>metrics-api</module>
         <module>metrics-dropwizard</module>
+        <module>metrics-logger</module>
     </modules>
 
     <properties>


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message