001/* 002 * Copyright 2012-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.boot.actuate.autoconfigure.metrics; 018 019import io.micrometer.core.annotation.Timed; 020import io.micrometer.core.instrument.Clock; 021import io.micrometer.core.instrument.binder.MeterBinder; 022import io.micrometer.core.instrument.config.MeterFilter; 023 024import org.springframework.beans.factory.ObjectProvider; 025import org.springframework.boot.autoconfigure.AutoConfigureBefore; 026import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 027import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 028import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 029import org.springframework.boot.context.properties.EnableConfigurationProperties; 030import org.springframework.context.annotation.Bean; 031import org.springframework.context.annotation.Configuration; 032import org.springframework.core.annotation.Order; 033 034/** 035 * {@link EnableAutoConfiguration Auto-configuration} for Micrometer-based metrics. 036 * 037 * @author Jon Schneider 038 * @author Stephane Nicoll 039 * @since 2.0.0 040 */ 041@Configuration 042@ConditionalOnClass(Timed.class) 043@EnableConfigurationProperties(MetricsProperties.class) 044@AutoConfigureBefore(CompositeMeterRegistryAutoConfiguration.class) 045public class MetricsAutoConfiguration { 046 047 @Bean 048 @ConditionalOnMissingBean 049 public Clock micrometerClock() { 050 return Clock.SYSTEM; 051 } 052 053 @Bean 054 public static MeterRegistryPostProcessor meterRegistryPostProcessor( 055 ObjectProvider<MeterBinder> meterBinders, 056 ObjectProvider<MeterFilter> meterFilters, 057 ObjectProvider<MeterRegistryCustomizer<?>> meterRegistryCustomizers, 058 ObjectProvider<MetricsProperties> metricsProperties) { 059 return new MeterRegistryPostProcessor(meterBinders, meterFilters, 060 meterRegistryCustomizers, metricsProperties); 061 } 062 063 @Bean 064 @Order(0) 065 public PropertiesMeterFilter propertiesMeterFilter(MetricsProperties properties) { 066 return new PropertiesMeterFilter(properties); 067 } 068 069}