springboot应用中Prometheus 获取百分位指标 histogram_quantile,需要实现 DistributionStatisticConfig配置类,
详细介绍可以参考 “springboot如何集成Prometheus如何暴露Histogram来获取P99等监控指标” 一文,地址:https://blog.youkuaiyun.com/lp19861126/article/details/106309546
这里介绍如何通过自定义 starter通过pom 引用的方式达到代码无侵入方式,主要达到两个需求:
1、配置类的过滤参数不能写在代码里,要实现通过参数配置方式注入,实际项目有近20个业务板块服务,用apollo作为配置中心
2、不能有代码侵入,不用在每个应用中手动加入配置类代码,近500人的研发团队,子应用多,需要通过集成后按照服务化集合后的应用通过pom 方式引用maven依赖,达到即插即用
具体实现如下:
1、创建maven工程 Spring-Boot-Starter-PrometheusHistograms
2、加入依赖,pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.one</groupId>
<artifactId>Spring-Boot-Starter-PrometheusHistograms</artifactId>
<version>0.0.1-RELEASE</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-