io.micronaut.configuration.metrics.micrometer.prometheus.PrometheusMeterRegistryFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of micronaut-micrometer-registry-prometheus Show documentation
Show all versions of micronaut-micrometer-registry-prometheus Show documentation
Provides integration between Micronaut and Micrometer
/*
* Copyright 2017-2019 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.configuration.metrics.micrometer.prometheus;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.micronaut.configuration.metrics.micrometer.ExportConfigurationProperties;
import io.micronaut.context.annotation.Factory;
import jakarta.inject.Singleton;
import java.util.Properties;
import static io.micronaut.configuration.metrics.micrometer.MeterRegistryFactory.MICRONAUT_METRICS_EXPORT;
/**
* Creates a Prometheus meter registry.
*/
@Factory
public class PrometheusMeterRegistryFactory {
public static final String PROMETHEUS_CONFIG = MICRONAUT_METRICS_EXPORT + ".prometheus";
public static final String PROMETHEUS_ENABLED = PROMETHEUS_CONFIG + ".enabled";
/**
* Create a PrometheusMeterRegistry bean if global metrics are enabled
* and Prometheus is enabled. Will be true by default when this
* configuration is included in project.
*
* @param exportConfigurationProperties The export configuration
* @return PrometheusMeterRegistry
*/
@Singleton
PrometheusMeterRegistry prometheusConfig(ExportConfigurationProperties exportConfigurationProperties) {
Properties exportConfig = exportConfigurationProperties.getExport();
return new PrometheusMeterRegistry(exportConfig::getProperty);
}
}