001package io.prometheus.metrics.config;
002
003import java.util.Map;
004import javax.annotation.Nullable;
005
006/** Properties starting with io.prometheus.exporter.httpServer */
007public class ExporterHttpServerProperties {
008
009  private static final String PORT = "port";
010  private static final String PREFIX = "io.prometheus.exporter.httpServer";
011  @Nullable private final Integer port;
012
013  private ExporterHttpServerProperties(@Nullable Integer port) {
014    this.port = port;
015  }
016
017  @Nullable
018  public Integer getPort() {
019    return port;
020  }
021
022  /**
023   * Note that this will remove entries from {@code properties}. This is because we want to know if
024   * there are unused properties remaining after all properties have been loaded.
025   */
026  static ExporterHttpServerProperties load(Map<Object, Object> properties)
027      throws PrometheusPropertiesException {
028    Integer port = Util.loadInteger(PREFIX + "." + PORT, properties);
029    Util.assertValue(port, t -> t > 0, "Expecting value > 0.", PREFIX, PORT);
030    return new ExporterHttpServerProperties(port);
031  }
032
033  public static Builder builder() {
034    return new Builder();
035  }
036
037  public static class Builder {
038
039    @Nullable private Integer port;
040
041    private Builder() {}
042
043    public Builder port(int port) {
044      this.port = port;
045      return this;
046    }
047
048    public ExporterHttpServerProperties build() {
049      return new ExporterHttpServerProperties(port);
050    }
051  }
052}