SpringBoot整合Prometheus实现业务指标上报
SpringBoot整合Prometheus实现业务指标上报
本文基于SpringBoot2.5.7 整合Prometheus,完成一个简单的业务指标上报。应用上报监控数据到pushgateway,然后prometheus定时拉取应用上报的数据。关于Prometheus和pushgateway 不是本文重点,可以参考官网介绍。
实现请求次数上报
添加依赖
implementation 'io.micrometer:micrometer-registry-prometheus'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.prometheus:simpleclient_pushgateway'
代码如下:
每请求/index 计数+1
@RestController
public class HelloIndexController {@AutowiredMycustomerMetricsBean mycustomerMetricsBean;@RequestMapping("/index")public String index() {mycustomerMetricsBean.getCounter().increment();return "ok";}
}
定义hello-Index.size metric 信息
@Component
@Getter
@Setter
public class MycustomerMetricsBean {private Counter counter;public MycustomerMetricsBean(MeterRegistry registry) {PrometheusMeterRegistry prometheusMeterRegistry = (PrometheusMeterRegistry) registry;this.counter = registry.counter("hello-Index.size", Tags.empty());}}
启动类
@SpringBootApplication
public class PrometheusApplicationDemo {public static void main(String[] args) {SpringApplication.run(PrometheusApplicationDemo.class,args);}
}
management:metrics:tags:application: ${spring.application.name}## 定义export 到prometheusexport:prometheus:enabled: truepushgateway: ## 配置pushgateway 信息enabled: truebase-url: http://192.168.100.101:9091/job: ${spring.application.name}grouping-key:instance: 192.168.100.168
spring:application:name: spring-boot-prometheus
关于整合Prometheus关键类如下:
SpringBoot整合Prometheus实现业务指标上报相关推荐
- 【SpringBoot】12.SpringBoot整合Dubbo+Zookeeper
1. 准 备 1.1 Dubbo 简介 Apache Dubbo 是一款高性能.轻量级的开源 Java RPC 框架,它提供了三大核心能力:面向接口的远程方法调用.智能容错和 负载均衡.以及服务自动注 ...
- SpringBoot整合AlertManager,实现自定义的告警收敛以及邮件处理,告警风暴,解决重复告警问题
SpringBoot整合AlertManager,实现自定义的告警收敛以及邮件处理,告警风暴,解决重复告警问题 需求 将传感器通过Http发送到微服务(SpringBoot项目)的警报消息,通知给对应 ...
- 很详细的SpringBoot整合UEditor教程
很详细的SpringBoot整合UEditor教程 2017年04月10日 20:27:21 小宝2333 阅读数:21529 版权声明:本文为博主原创文章,未经博主允许不得转载. https://b ...
- springboot整合Actuator监控
springboot整合Actuator监控. 1.简要说明: Actuator提供了对springboot应用程序监视和管理的能力,可以选择通过使用HTTP Endpoint或者使用JMX来管理和监 ...
- [资源分享] 【Springboot】实例讲解Springboot整合OpenTracing分布式链路追踪系统(Jaeger和Zipkin)
1 分布式追踪系统 随着大量公司把单体应用重构为微服务,对于运维人员的责任就更加重大了.架构更复杂.应用更多,要从中快速诊断出问题.找到性能瓶颈,并不是一件容易的事.因此,也随着诞生了一系列面向Dev ...
- SpringBoot第九篇: springboot整合Redis
这篇文章主要介绍springboot整合redis,至于没有接触过redis的同学可以看下这篇文章:5分钟带你入门Redis. 引入依赖: 在pom文件中添加redis依赖: <dependen ...
- es springboot 不设置id_原创 | 一篇解决Springboot 整合 Elasticsearch
ElasticSearch 结合业务的场景,在目前的商品体系需要构建搜索服务,主要是为了提供用户更丰富的检索场景以及高速,实时及性能稳定的搜索服务. ElasticSearch是一个基于Lucene的 ...
- SpringBoot使用prometheus监控
本文介绍SpringBoot如何使用Prometheus配合Grafana监控. 1.关于Prometheus Prometheus是一个根据应用的metrics来进行监控的开源工具.相信很多工程都在 ...
- springboot整合shiro使用shiro-spring-boot-web-starter
此文章仅仅说明在springboot整合shiro时的一些坑,并不是教程 增加依赖 <!-- 集成shiro依赖 --> <dependency><groupId> ...
最新文章
- 深入浅出 Redis client/server交互流程
- 人机语言(MML: Man-Machine Language)
- 001帝国Cms二次开发之helloworld
- PHP中绘制图像的一些函数总结
- Win10下使用Debug
- [Cracking the Coding Interview] 4.1 Route Between Nodes 节点间的路径
- druid 多数据源_Spring Boot2 系列教程(二十二)整合 MyBatis 多数据源
- 面试稳了!BATJ 等大厂 400+ 道面试题全汇总!
- 手机号段对应地区编码_什么是编码器?了解两种类型的编码器
- pl/mysql安装_MySQL安装
- 计算机需要那些高中数学知识点,高中数学复习知识点有哪些
- html css 实现文字竖排模拟古籍排版
- Tkinter实例:家庭账本(Python)
- 别在直接背3500个英语单词了,支你一招,看过来
- Unity 给物体加贴图
- 视觉感知在数据可视化中的作用
- Alibaba SWE 实习岗 笔试题 JAVA
- 用键盘控制鼠标移动!!
- ffmpeg webm 提取_使用 FFmpeg 对 webp转png , webm转mp4或者gif等进行操作
- 博彦科技:区块链建立优质农产品“信任链”|FISCO BCOS 2021 Meetup上海站