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