背景

springboot如何集成Prometheus我这里不做详细描述,要想了解集成过程,可以参考一下博客:
Spring Boot 使用 Micrometer 集成 Prometheus 监控 Java 应用性能
这里我讲一下如果我们j需要获取到某些监控指标的p99、p90等度量数据,比如说http请求的响应时长p99等,

Micrometer

根据指标监控的对象个数、监视目的和含义的不同,Micrometer指标类型大体可以分为Gauge、Counter、DistributionSummary、Timer四种。
这里我重点说一下DistributionSummary。

DistributionSummary

DistributionSummary是用于跟踪事件的分布情况,有多个指标组成:

  • count,事件的个数,聚合指标,如响应的个数
  • sum,综合,聚合指标,如响应大小的综合
  • histogram,分布,聚合指标,包含le标签用于区分bucket,例如web.response.size.historgram{le=512} = 99,表示响应大小不超过512(Byte)的响应个数是99个。一般有多个bucket,如le=128,le=256,le=512,le=1024,le=+Inf等。
    每个bucket展示为一条时间序列,会得到类似下面的图。


percentile(quantile),百分位数,聚合指标,包含percentile标签用于区分不同的百分位,例如web.response.size.percentile{p=90) = 512,表示90%的响应大小都小于512。一般有多个percentile,如p50,p75,p90,p99。
每个百分位展示为一条时间序列,会得到类似下面的图。


Timer
Timer是DistributionSummary的特化,专门用于计时类的指标,可以对记录的时间值(duration)进行单位换算。

暴露histogram

 <dependency>
<groupid>io.micrometer</groupid>
<artifactid>micrometer-registry-prometheus</artifactid>
</dependency>

其中prometheus的类库中为我们提供了很多的监控指标,可以访问下
http://localhost:8080/actuator/prometheus就可以看到已有监控看信息


但是默认这些监控指标并不是DistributionSummary,所以需要我们在初始化时替换配置并打开计数开关,如下:

import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.config.MeterFilter;
import io.micrometer.core.instrument.distribution.DistributionStatisticConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import java.time.Duration; @Configuration
@Slf4j
public class MicrometerConfig { @Bean
MeterRegistryCustomizer<meterregistry> metricsCommonTags() {
return registry -&gt; {
registry.config().meterFilter(
new MeterFilter() {
@Override
public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) {
if (id.getType() == Meter.Type.TIMER&amp;&amp;id.getName().matches("^(http|hystrix){1}.*")) {
return DistributionStatisticConfig.builder()
.percentilesHistogram(true)
.percentiles(0.5, 0.90,0.95, 0.99)
.sla(Duration.ofMillis(50).toNanos(),
Duration.ofMillis(100).toNanos(),
Duration.ofMillis(200).toNanos(),
Duration.ofSeconds(1).toNanos(),
Duration.ofSeconds(5).toNanos(),
.minimumExpectedValue(Duration.ofMillis(1).toNanos())
.maximumExpectedValue(Duration.ofSeconds(5).toNanos())
.build()
.merge(config);
} else {
return config;
}
}
});
};
}
}

以上代码根据需要来暴露histogram信息,这里是选择http响应时长以及hystrix响应监控暴露histogram,如果有需要可以不增加过滤条件。
打开后可以看到多了很多监控信息:

配置到grafana

avg(http_server_requests_seconds{service=~"$service" ,quantile =~ "0.9|0.5|0.99", uri !~ "/actuator.*|/health|/prometheus|root"}*1000 &gt; 0) by (uri,quantile)

</meterregistry>

springboot如何集成Prometheus如何暴露Histogram来获取P99等监控指标的更多相关文章

  1. asp.net core 集成 Prometheus

    asp.net core 集成 prometheus Intro Prometheus 是一个开源的现代化,云原生的系统监控框架,并且可以轻松的集成 PushGateway, AlertManager ...

  2. SpringBoot应用集成微服务组件Nacos

    目录 springboot与微服务组件nacos Nacos服务快速启动 STS4 开发工具 Maven 环境配置 STS4开发工具引入Maven配置 Maven Repo配置阿里云镜像源 Sprin ...

  3. Spring Boot 微服务应用集成Prometheus + Grafana 实现监控告警

    Spring Boot 微服务应用集成Prometheus + Grafana 实现监控告警 一.添加依赖 1.1 Actuator 的 /prometheus端点 二.Prometheus 配置 部 ...

  4. springboot elasticsearch 集成注意事项

    文章来源: http://www.cnblogs.com/guozp/p/8686904.html 一 elasticsearch基础 这里假设各位已经简单了解过elasticsearch,并不对es ...

  5. Springboot Application 集成 OSGI 框架开发

    内容来源:https://www.ibm.com/developerworks/cn/java/j-springboot-application-integrated-osgi-framework-d ...

  6. SpringBoot项目集成Hystrix

    Hystrix Hystrix是由Netflix开源的一个服务隔离组件,通过服务隔离来避免由于依赖延迟.异常,引起资源耗尽导致系统不可用的解决方案. 1.什么是服务熔断   服务熔断就是对该服务的调用 ...

  7. 钉钉通知机器人与SpringBoot的集成

    Spring Boot Admin 集成自定义监控告警(2.0.1版本)------钉钉机器人 - yuancao24的博客 - CSDN博客https://blog.csdn.net/yuancao ...

  8. SpringBoot项目集成PageHelper使用

    SpringBoot项目集成PageHelper使用 一.开始 ​ 地址:https://github.com/pagehelper/Mybatis-PageHelper ​ 在spring boot ...

  9. Springboot简单集成ActiveMQ

    Springboot简单集成ActiveMQ 消息发送者的实现 pom.xml添加依赖 <dependency> <groupId>org.springframework.bo ...

  10. 在springboot中集成mybatis开发

    在springboot中利用mybatis框架进行开发需要集成mybatis才能进行开发,那么如何在springboot中集成mybatis呢?按照以下几个步骤就可以实现springboot集成myb ...

随机推荐

  1. Web运作原理探析

    Web运作原理探析 1.1 web的 概念 Web是一种分布式的应用架构,旨在共享分布在网络上的各个Web服务器中的所有互相链接的信息. 1.2 HTML是指超文本标记语言. 1.3 URL简介 UR ...

  2. android系统中log机制

    android系统中log机制 背景 习惯了Linux开发的我,转到安卓以后,对于安卓开发的很多问题没有经验.看到同事解决问题都会看logcat,因此有必要了解一下这些东西. 介绍 Android提供 ...

  3. 「转」Android编译选项中的eng、user、user-debug

    Android编译选项中eng.user.user-debug主要区别 reference: https://blog.csdn.net/dearsq/article/details/52589376 ...

  4. Ubuntu 22.04单机部署K3s

    安装docker 从docker官网获取最新的一键安装脚本,安装docker运行环境 curl -fsSL https://get.docker.com -o get-docker.sh sudo s ...

  5. 【论文阅读】Trajectory-guided Control Prediction for End-to-end Autonomous Driving: A Simple yet Strong Baseline

    参考与前言 Summary: leaderboard 现存第一名 TCP,非常simple的设置 取得了很好的效果 论文链接:Trajectory-guided Control Prediction ...

  6. HTTP事务理解

    借图: 首先三次握手理解: TCP三次握手好比两个对话, 第一次握手:甲给乙一直发送信息,乙没有回应,甲不知道乙有没有收到信息 第二次握手:乙收到信息,然后再给甲回信息,此时甲知道乙收到信息,但乙不知 ...

  7. 《Programming from the Ground Up》阅读笔记:p19-p48

    <Programming from the Ground Up>学习第2天,p19-p48总结,总计30页. 一.技术总结 1.object file p20, An object fil ...

  8. Pandas中的常用函数

    1. map.apply.applymap 参考:Pandas教程 | 数据处理三板斧--map.apply.applymap详解 在日常的数据处理中,经常会对一个DataFrame进行逐行.逐列和逐 ...

  9. Mybatis下划线自动映射驼峰字段

    mybatis-config.xml <!--下划线自动映射驼峰字段--> <settings> <setting name="mapUnderscoreToC ...

  10. Mac 设置多个版本JDK

    控制台: p.p1 { margin: 0; font: 11px Menlo; color: rgba(0, 0, 0, 1) } span.s1 { font-variant-ligatures: ...