Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/monitoring/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ Parameters:

- `host` - the Graphite server host
- `port` - the Graphite server port
- `protocol` - protocol to use (TCP/UDP)

### StatsD (org.apache.flink.metrics.statsd.StatsDReporter)
Dependency:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.codahale.metrics.ScheduledReporter;
import com.codahale.metrics.graphite.Graphite;

import com.codahale.metrics.graphite.GraphiteUDP;
import org.apache.flink.annotation.PublicEvolving;
import org.apache.flink.dropwizard.ScheduledDropwizardReporter;
import org.apache.flink.metrics.MetricConfig;
Expand All @@ -30,6 +31,13 @@
@PublicEvolving
public class GraphiteReporter extends ScheduledDropwizardReporter {

public static final String ARG_PROTOCOL = "protocol";

private enum Protocol {
TCP,
UDP
}

@Override
public ScheduledReporter getReporter(MetricConfig config) {
String host = config.getString(ARG_HOST, null);
Expand All @@ -42,6 +50,7 @@ public ScheduledReporter getReporter(MetricConfig config) {
String prefix = config.getString(ARG_PREFIX, null);
String conversionRate = config.getString(ARG_CONVERSION_RATE, null);
String conversionDuration = config.getString(ARG_CONVERSION_DURATION, null);
String protocol = config.getString(ARG_PROTOCOL, "TCP");

com.codahale.metrics.graphite.GraphiteReporter.Builder builder =
com.codahale.metrics.graphite.GraphiteReporter.forRegistry(registry);
Expand All @@ -58,6 +67,20 @@ public ScheduledReporter getReporter(MetricConfig config) {
builder.convertDurationsTo(TimeUnit.valueOf(conversionDuration));
}

return builder.build(new Graphite(host, port));
Protocol prot;
try {
prot = Protocol.valueOf(protocol);
} catch (IllegalArgumentException iae) {
log.warn("Invalid protocol configuration: " + protocol + " Expected: TCP or UDP, defaulting to TCP.");
prot = Protocol.TCP;
}

switch(prot) {
case UDP:
return builder.build(new GraphiteUDP(host, port));
case TCP:
default:
return builder.build(new Graphite(host, port));
}
}
}