001package io.prometheus.metrics.config;
002
003import java.util.Map;
004
005public class ExporterPushgatewayProperties {
006
007  private static final String ADDRESS = "address";
008  private static final String JOB = "job";
009  private static final String SCHEME = "scheme";
010  private static final String PREFIX = "io.prometheus.exporter.pushgateway";
011  private final String scheme;
012  private final String address;
013  private final String job;
014
015  private ExporterPushgatewayProperties(String address, String job, String scheme) {
016    this.address = address;
017    this.job = job;
018    this.scheme = scheme;
019  }
020
021  /** Address of the Pushgateway in the form {@code host:port}. Default is {@code localhost:9091} */
022  public String getAddress() {
023    return address;
024  }
025
026  /**
027   * {@code job} label for metrics being pushed. Default is the name of the JAR file that is
028   * running.
029   */
030  public String getJob() {
031    return job;
032  }
033
034  /**
035   * Scheme to be used when pushing metrics to the pushgateway. Must be "http" or "https". Default
036   * is "http".
037   */
038  public String getScheme() {
039    return scheme;
040  }
041
042  /**
043   * Note that this will remove entries from {@code properties}. This is because we want to know if
044   * there are unused properties remaining after all properties have been loaded.
045   */
046  static ExporterPushgatewayProperties load(Map<Object, Object> properties)
047      throws PrometheusPropertiesException {
048    String address = Util.loadString(PREFIX + "." + ADDRESS, properties);
049    String job = Util.loadString(PREFIX + "." + JOB, properties);
050    String scheme = Util.loadString(PREFIX + "." + SCHEME, properties);
051    if (scheme != null) {
052      if (!scheme.equals("http") && !scheme.equals("https")) {
053        throw new PrometheusPropertiesException(
054            String.format(
055                "%s.%s: Illegal value. Expecting 'http' or 'https'. Found: %s",
056                PREFIX, SCHEME, scheme));
057      }
058    }
059    return new ExporterPushgatewayProperties(address, job, scheme);
060  }
061}