You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2018/10/31 14:58:26 UTC

[GitHub] patricklucas closed pull request #4299: [FLINK-7155] [metrics] Add Influxdb reporter

patricklucas closed pull request #4299: [FLINK-7155] [metrics] Add Influxdb reporter
URL: https://github.com/apache/flink/pull/4299
 
 
   

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/flink-metrics/flink-metrics-influxdb/pom.xml b/flink-metrics/flink-metrics-influxdb/pom.xml
new file mode 100644
index 00000000000..57ac07ccc57
--- /dev/null
+++ b/flink-metrics/flink-metrics-influxdb/pom.xml
@@ -0,0 +1,91 @@
+<?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/maven-v4_0_0.xsd">
+
+	<modelVersion>4.0.0</modelVersion>
+
+	<parent>
+		<groupId>org.apache.flink</groupId>
+		<artifactId>flink-metrics</artifactId>
+		<version>1.4-SNAPSHOT</version>
+		<relativePath>..</relativePath>
+	</parent>
+
+	<artifactId>flink-metrics-influxdb</artifactId>
+	<name>flink-metrics-influxdb</name>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.flink</groupId>
+			<artifactId>flink-annotations</artifactId>
+			<version>${project.version}</version>
+			<scope>provided</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>org.apache.flink</groupId>
+			<artifactId>flink-metrics-core</artifactId>
+			<version>${project.version}</version>
+			<scope>provided</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>org.apache.flink</groupId>
+			<artifactId>flink-metrics-dropwizard</artifactId>
+			<version>${project.version}</version>
+		</dependency>
+
+		<dependency>
+			<groupId>io.dropwizard.metrics</groupId>
+			<artifactId>metrics-core</artifactId>
+			<version>${metrics.version}</version>
+		</dependency>
+
+		<dependency>
+			<groupId>com.github.davidb</groupId>
+			<artifactId>metrics-influxdb</artifactId>
+			<version>0.9.3</version>
+		</dependency>
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<artifactId>maven-assembly-plugin</artifactId>
+				<version>2.4</version>
+				<configuration>
+					<descriptorRefs>
+						<descriptorRef>jar-with-dependencies</descriptorRef>
+					</descriptorRefs>
+				</configuration>
+				<executions>
+					<execution>
+						<id>make-assembly</id>
+						<phase>package</phase>
+						<goals>
+							<goal>single</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
+	</build>
+</project>
diff --git a/flink-metrics/flink-metrics-influxdb/src/main/java/org/apache/flink/metrics/influxdb/InfluxdbReporter.java b/flink-metrics/flink-metrics-influxdb/src/main/java/org/apache/flink/metrics/influxdb/InfluxdbReporter.java
new file mode 100644
index 00000000000..19575539175
--- /dev/null
+++ b/flink-metrics/flink-metrics-influxdb/src/main/java/org/apache/flink/metrics/influxdb/InfluxdbReporter.java
@@ -0,0 +1,76 @@
+/*
+ * 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.flink.metrics.influxdb;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.dropwizard.ScheduledDropwizardReporter;
+import org.apache.flink.metrics.MetricConfig;
+
+import com.codahale.metrics.MetricFilter;
+import com.codahale.metrics.ScheduledReporter;
+import metrics_influxdb.HttpInfluxdbProtocol;
+import metrics_influxdb.api.measurements.CategoriesMetricMeasurementTransformer;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * This class acts as a factory for the {@link metrics_influxdb.InfluxdbReporter} and allows using it as a Flink
+ * reporter.
+ */
+@PublicEvolving
+public class InfluxdbReporter extends ScheduledDropwizardReporter {
+
+	public static final String ARG_USER = "user";
+	public static final String ARG_PASSWORD = "password";
+	public static final String ARG_DB = "db";
+
+	@Override
+	public ScheduledReporter getReporter(final MetricConfig config) {
+		final String host = config.getString(ARG_HOST, "localhost");
+		final Integer port = config.getInteger(ARG_PORT, HttpInfluxdbProtocol.DEFAULT_PORT);
+		final String user = config.getString(ARG_USER, null);
+		final String password = config.getString(ARG_PASSWORD, null);
+		final String db = config.getString(ARG_DB, "flink");
+		final String conversionRate = config.getString(ARG_CONVERSION_RATE, null);
+		final String conversionDuration = config.getString(ARG_CONVERSION_DURATION, null);
+
+		final metrics_influxdb.InfluxdbReporter.Builder builder =
+			metrics_influxdb.InfluxdbReporter.forRegistry(registry);
+
+		builder.protocol(new HttpInfluxdbProtocol(host, port, user, password, db));
+
+		if (conversionRate != null) {
+			builder.convertRatesTo(TimeUnit.valueOf(conversionRate));
+		}
+
+		if (conversionDuration != null) {
+			builder.convertDurationsTo(TimeUnit.valueOf(conversionDuration));
+		}
+
+		builder
+			.filter(MetricFilter.ALL)
+			.skipIdleMetrics(false)
+			.transformer(new CategoriesMetricMeasurementTransformer(
+				"host", "process_type", "tm_id", "job_name", "task_name", "subtask_index"
+			));
+
+		return builder.build();
+	}
+
+}
diff --git a/flink-metrics/pom.xml b/flink-metrics/pom.xml
index 3b655c404c0..7472e27db24 100644
--- a/flink-metrics/pom.xml
+++ b/flink-metrics/pom.xml
@@ -38,6 +38,7 @@ under the License.
 		<module>flink-metrics-dropwizard</module>
 		<module>flink-metrics-ganglia</module>
 		<module>flink-metrics-graphite</module>
+		<module>flink-metrics-influxdb</module>
 		<module>flink-metrics-jmx</module>
 		<module>flink-metrics-prometheus</module>
 		<module>flink-metrics-statsd</module>


 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services