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