001package io.prometheus.metrics.config; 002 003import java.util.HashMap; 004import java.util.Map; 005 006/** 007 * The Prometheus Java client library can be configured at runtime (e.g. using a properties file). 008 * <p> 009 * This class represents the runtime configuration. 010 */ 011public class PrometheusProperties { 012 013 private static final PrometheusProperties instance = PrometheusPropertiesLoader.load(); 014 015 private final MetricsProperties defaultMetricsProperties; 016 private final Map<String, MetricsProperties> metricProperties = new HashMap<>(); 017 private final ExemplarsProperties exemplarProperties; 018 private final ExporterProperties exporterProperties; 019 private final ExporterFilterProperties exporterFilterProperties; 020 private final ExporterHttpServerProperties exporterHttpServerProperties; 021 private final ExporterOpenTelemetryProperties exporterOpenTelemetryProperties; 022 private final ExporterPushgatewayProperties exporterPushgatewayProperties; 023 024 /** 025 * Get the properties instance. When called for the first time, {@code get()} loads the properties from the following locations: 026 * <ul> 027 * <li>{@code prometheus.properties} file found in the classpath.</li> 028 * <li>Properties file specified in the {@code PROMETHEUS_CONFIG} environment variable or the {@code prometheus.config} system property.</li> 029 * <li>Individual properties from system properties.</li> 030 * </ul> 031 */ 032 public static PrometheusProperties get() throws PrometheusPropertiesException { 033 return instance; 034 } 035 036 public PrometheusProperties( 037 MetricsProperties defaultMetricsProperties, 038 Map<String, MetricsProperties> metricProperties, 039 ExemplarsProperties exemplarProperties, 040 ExporterProperties exporterProperties, 041 ExporterFilterProperties exporterFilterProperties, 042 ExporterHttpServerProperties httpServerConfig, 043 ExporterPushgatewayProperties pushgatewayProperties, 044 ExporterOpenTelemetryProperties otelConfig) { 045 this.defaultMetricsProperties = defaultMetricsProperties; 046 this.metricProperties.putAll(metricProperties); 047 this.exemplarProperties = exemplarProperties; 048 this.exporterProperties = exporterProperties; 049 this.exporterFilterProperties = exporterFilterProperties; 050 this.exporterHttpServerProperties = httpServerConfig; 051 this.exporterPushgatewayProperties = pushgatewayProperties; 052 this.exporterOpenTelemetryProperties = otelConfig; 053 } 054 055 /** 056 * The default metric properties apply for metrics where {@link #getMetricProperties(String)} is {@code null}. 057 */ 058 public MetricsProperties getDefaultMetricProperties() { 059 return defaultMetricsProperties; 060 } 061 062 /** 063 * Properties specific for one metric. Should be merged with {@link #getDefaultMetricProperties()}. 064 * May return {@code null} if no metric-specific properties are configured for a metric name. 065 */ 066 public MetricsProperties getMetricProperties(String metricName) { 067 return metricProperties.get(metricName.replace(".", "_")); 068 } 069 070 public ExemplarsProperties getExemplarProperties() { 071 return exemplarProperties; 072 } 073 074 public ExporterProperties getExporterProperties() { 075 return exporterProperties; 076 } 077 078 public ExporterFilterProperties getExporterFilterProperties() { 079 return exporterFilterProperties; 080 } 081 082 public ExporterHttpServerProperties getExporterHttpServerProperties() { 083 return exporterHttpServerProperties; 084 } 085 086 public ExporterPushgatewayProperties getExporterPushgatewayProperties() { 087 return exporterPushgatewayProperties; 088 } 089 090 public ExporterOpenTelemetryProperties getExporterOpenTelemetryProperties() { 091 return exporterOpenTelemetryProperties; 092 } 093}