Skip to content

Commit

Permalink
[FLINK-6013][metrics] Add Datadog HTTP metrics reporter
Browse files Browse the repository at this point in the history
This closes apache#3736.
  • Loading branch information
bowenli86 authored and zentol committed May 9, 2017
1 parent 50baec6 commit 54ceec1
Show file tree
Hide file tree
Showing 15 changed files with 970 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/monitoring/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,30 @@ metrics.reporter.stsd.port: 8125

{% endhighlight %}

### Datadog (org.apache.flink.metrics.datadog.DatadogHttpReporter)

In order to use this reporter you must copy `/opt/flink-metrics-datadog-{{site.version}}.jar` into the `/lib` folder
of your Flink distribution.

Note any variables in Flink metrics, such as `<host>`, `<job_name>`, `<tm_id>`, `<subtask_index>`, `<task_name>`, and `<operator_name>`,
will be sent to Datadog as tags. Tags will look like `host:localhost` and `job_name:myjobname`.

Parameters:

- `apikey` - the Datadog API key
- `tags` - (optional) the global tags that will be applied to metrics when sending to Datadog. Tags should be separated by comma only

Example configuration:

{% highlight yaml %}

metrics.reporters: dghttp
metrics.reporter.dghttp.class: org.apache.flink.metrics.datadog.DatadogHttpReporter
metrics.reporter.dghttp.apikey: xxx
metrics.reporter.dghttp.tags: myflinkapp,prod

{% endhighlight %}

## System metrics

By default Flink gathers several metrics that provide deep insights on the current state.
Expand Down
7 changes: 7 additions & 0 deletions flink-dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ under the License.
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-metrics-datadog</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<!-- end optional Flink metrics reporters -->

<!-- start optional Flink libraries -->
Expand Down
7 changes: 7 additions & 0 deletions flink-dist/src/main/assemblies/opt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@
<fileMode>0644</fileMode>
</file>

<file>
<source>../flink-metrics/flink-metrics-datadog/target/flink-metrics-datadog-${project.version}-shaded.jar</source>
<outputDirectory>opt/</outputDirectory>
<destName>flink-metrics-datadog-${project.version}.jar</destName>
<fileMode>0644</fileMode>
</file>

<file>
<source>../flink-shaded-hadoop/flink-shaded-hadoop2/target/flink-shaded-hadoop2-${project.version}.jar</source>
<outputDirectory>opt/</outputDirectory>
Expand Down
108 changes: 108 additions & 0 deletions flink-metrics/flink-metrics-datadog/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?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:https://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:https://maven.apache.org/POM/4.0.0"
xmlns:xsi="http:https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http:https://maven.apache.org/POM/4.0.0 http:https://maven.apache.org/xsd/maven-4.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-datadog</artifactId>
<name>flink-metrics-datadog</name>

<dependencies>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-metrics-core</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.7.0</version>
</dependency>

<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
<version>1.12.0</version>
</dependency>


<!-- test dependencies -->

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-runtime_2.10</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils-junit</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<relocations combine.children="append">
<relocation>
<pattern>okhttp3</pattern>
<shadedPattern>org.apache.flink.shaded.okhttp3</shadedPattern>
</relocation>
<relocation>
<pattern>okio</pattern>
<shadedPattern>org.apache.flink.shaded.okio</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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:https://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.datadog;

import org.apache.flink.metrics.Counter;

import java.util.List;

/**
* Mapping of counter between Flink and Datadog
* */
public class DCounter extends DMetric {
private final Counter counter;

public DCounter(Counter c, String metricName, String host, List<String> tags) {
super(MetricType.counter, metricName, host, tags);
counter = c;
}

/**
* Visibility of this method must not be changed
* since we deliberately not map it to json object in a Datadog-defined format
* */
@Override
public Number getMetricValue() {
return counter.getCount();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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:https://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.datadog;


import org.apache.flink.metrics.Gauge;

import java.util.List;

/**
* Mapping of gauge between Flink and Datadog
* */
public class DGauge extends DMetric {
private final Gauge<Number> gauge;

public DGauge(Gauge<Number> g, String metricName, String host, List<String> tags) {
super(MetricType.gauge, metricName, host, tags);
gauge = g;
}

/**
* Visibility of this method must not be changed
* since we deliberately not map it to json object in a Datadog-defined format
* */
@Override
public Number getMetricValue() {
return gauge.getValue();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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:https://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.datadog;

import org.apache.flink.metrics.Meter;

import java.util.List;

/**
* Mapping of meter between Flink and Datadog
*
* Only consider rate of the meter, due to Datadog HTTP API's limited support of meter
* */
public class DMeter extends DMetric {
private final Meter meter;

public DMeter(Meter m, String metricName, String host, List<String> tags) {
super(MetricType.gauge, metricName, host, tags);
meter = m;
}

@Override
public Number getMetricValue() {
return meter.getRate();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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:https://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.datadog;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.util.ArrayList;
import java.util.List;

/**
* Abstract metric of Datadog for serialization
* */
@JsonInclude(JsonInclude.Include.NON_NULL)
public abstract class DMetric {
private static final long MILLIS_TO_SEC = 1000L;

/**
* Names of metric/type/tags field and their getters must not be changed
* since they are mapped to json objects in a Datadog-defined format
* */
private final String metric; // Metric name
private final MetricType type;
private final String host;
private final List<String> tags;

public DMetric(MetricType metricType, String metric, String host, List<String> tags) {
this.type = metricType;
this.metric = metric;
this.host = host;
this.tags = tags;
}

public MetricType getType() {
return type;
}

public String getMetric() {
return metric;
}

public String getHost() {
return host;
}

public List<String> getTags() {
return tags;
}

public List<List<Number>> getPoints() {
// One single data point
List<Number> point = new ArrayList<>();
point.add(getUnixEpochTimestamp());
point.add(getMetricValue());

List<List<Number>> points = new ArrayList<>();
points.add(point);

return points;
}

@JsonIgnore
public abstract Number getMetricValue();

public static long getUnixEpochTimestamp() {
return (System.currentTimeMillis() / MILLIS_TO_SEC);
}
}
Loading

0 comments on commit 54ceec1

Please sign in to comment.