
com.taotao.boot.prometheus.configuration.PrometheusInterceptorConfiguration Maven / Gradle / Ivy
/*
* Copyright (c) 2020-2030, Shuigedeng ([email protected] & https://blog.taotaocloud.top/).
*
* 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 com.taotao.boot.prometheus.configuration;
import com.taotao.boot.prometheus.collector.PrometheusCollector;
import com.taotao.boot.prometheus.interceptor.PrometheusMetricsInterceptor;
import com.taotao.boot.prometheus.properties.PrometheusProperties;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@EnableConfigurationProperties({PrometheusProperties.class})
@ConditionalOnProperty(prefix = PrometheusProperties.PREFIX, name = "enabled", havingValue = "true")
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@AutoConfiguration(after = PrometheusAutoConfiguration.class)
public class PrometheusInterceptorConfiguration implements WebMvcConfigurer {
private final PrometheusCollector prometheusCollector;
public PrometheusInterceptorConfiguration(PrometheusCollector prometheusCollector) {
this.prometheusCollector = prometheusCollector;
}
// 拦截器
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new PrometheusMetricsInterceptor(prometheusCollector))
.addPathPatterns("/**")
.excludePathPatterns("/actuator/**");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy