Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -69,14 +67,10 @@ private Builder(MetricRegistry registry) {
this.durationUnit = TimeUnit.MILLISECONDS;
this.filter = MetricFilter.ALL;
this.ttl = null;
this.tags = new ArrayList<String>();
this.tags = new ArrayList<>();
this.prefix = null;
this.separator = " ";
try {
this.localHost = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
this.localHost = null;
}
this.localHost = null;
}

/**
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/codahale/metrics/riemann/HostnameResolution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.codahale.metrics.riemann;

import java.net.InetAddress;

public enum HostnameResolution {
LOCAL {
@Override
public String getHostname() {
try {
return InetAddress.getLocalHost().getHostName();
} catch (Exception e) {
return null;
}
}
},
DOCKER {
@Override
public String getHostname() {
return System.getenv("HOST");
}
};

public abstract String getHostname();
}
1 change: 1 addition & 0 deletions src/main/java/io/dropwizard/riemann/RiemannBundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void start() throws Exception {
.tags(riemannConfig.getTags())
.prefixedWith(riemannConfig.getPrefix())
.useSeparator(".")
.localHost(riemannConfig.getHostnameResolution().getHostname())
.convertDurationsTo(TimeUnit.MILLISECONDS).convertRatesTo(TimeUnit.SECONDS);
riemannReporter = builder.build(riemann);
riemannReporter.start(riemannConfig.getPollingInterval(), TimeUnit.SECONDS);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/io/dropwizard/riemann/RiemannConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

package io.dropwizard.riemann;

import com.codahale.metrics.riemann.HostnameResolution;
import lombok.*;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.Collections;
import java.util.List;

Expand All @@ -47,4 +49,7 @@ public class RiemannConfig {

@Singular
private List<String> tags = Collections.emptyList();

@NotNull
private HostnameResolution hostnameResolution = HostnameResolution.LOCAL;
}