Skip to content

Commit

Permalink
Add support for custom listen address (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
denis256 committed Dec 31, 2023
1 parent 8019a64 commit 051b190
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.prometheus.client.hotspot.DefaultExports;

import java.io.IOException;
import java.net.InetAddress;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -34,17 +35,22 @@ public class MetricService {
private final ConcurrentMap<String, Histogram> histograms = new ConcurrentHashMap<>();

public MetricService(int prometheusPort) throws IOException {
this("", prometheusPort, emptyMap());
this("", "0.0.0.0", prometheusPort, emptyMap());
}

public MetricService(String prefix, int prometheusPort) throws IOException {
this(prefix, prometheusPort, emptyMap());
this(prefix, "0.0.0.0", prometheusPort, emptyMap());
}

public MetricService(String prefix, int prometheusPort, Map<String, String> defaultLabels) throws IOException {
public MetricService(String prefix, String listenAddress, int prometheusPort) throws IOException {
this(prefix, listenAddress, prometheusPort, emptyMap());
}

public MetricService(String prefix, String listenAddress, int prometheusPort, Map<String, String> defaultLabels) throws IOException {
this.prefix = prefix;
DefaultExports.initialize();
this.server = new HTTPServer.Builder()
.withInetAddress(InetAddress.getByName(listenAddress))
.withPort(prometheusPort)
.build();
this.defaultLabels = defaultLabels;
Expand Down

0 comments on commit 051b190

Please sign in to comment.