springboot集成prometheus
1 Maven pom.xml引入依赖
<dependency><groupId>io.prometheus</groupId><artifactId>simpleclient_spring_boot</artifactId>
</dependency>
2 启动类引入注解
import io.prometheus.client.spring.boot.EnablePrometheusEndpoint;
import io.prometheus.client.spring.boot.EnableSpringBootMetricsCollector;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
@EnablePrometheusEndpoint
@EnableSpringBootMetricsCollector
public class Application {public static void main(String[] args) {SpringApplication.run(Application.class, args);}
3 Controller类写需要监控的指标,比如Counter
import io.prometheus.client.Counter;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.Random;@RestController
public class SampleController {private static Random random = new Random();private static final Counter requestTotal = Counter.build().name("my_sample_counter").labelNames("status").help("A simple Counter to illustrate custom Counters in Spring Boot and Prometheus").register();@RequestMapping("/endpoint")public void endpoint() {if (random.nextInt(2) > 0) {requestTotal.labels("success").inc();} else {requestTotal.labels("error").inc();}}
}
4 设置springboot应用的服务名和端口,在application.properties
spring.application.name=mydemo
server.port=8888
5 配置prometheus.yml
global:scrape_interval: 15s # By default, scrape targets every 15 seconds.evaluation_interval: 15s # By default, scrape targets every 15 seconds.# scrape_timeout is set to the global default (10s).# Attach these labels to any time series or alerts when communicating with# external systems (federation, remote storage, Alertmanager).external_labels:monitor: 'codelab-monitor'# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:# - "first.rules"# - "second.rules"# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.- job_name: 'prometheus'# Override the global default and scrape targets from this job every 5 seconds.scrape_interval: 5s# metrics_path defaults to '/metrics'# scheme defaults to 'http'.static_configs:- targets: ['localhost:9090']- job_name: 'mydemo'# Override the global default and scrape targets from this job every 5 seconds.scrape_interval: 5smetrics_path: '/prometheus'# scheme defaults to 'http'.static_configs:- targets: ['10.94.20.52:8888']
最关键的配置就是targets: [‘10.94.20.52:8888’],就是springboot应用的ip和端口
注:在application.xml里设置属性:spring.metrics.servo.enabled=false,去掉重复的metrics,不然在prometheus的控制台的targets页签里,会一直显示此endpoint为down状态。
6 多次访问 http://localhost:8888/mydemo/endpoint,然后在prometheus控制台查看相关metrics信息,my_sample_counter,2个页签:Graph,Console
springboot集成prometheus相关推荐
- 完整版SpringBoot集成Prometheus配置Grafana监控指标包括响应时间分位数TP90,TP80(图+文)
1 缘起 监控作为线上服务管理的最重要一环, 每当新服务上线后,都需要监控上线服务运行情况,包括QPS.时延.成功响应率.内存和CPU使用情况等, 通过监控信息,清晰且及时地掌握当前服务的健康程度,以 ...
- springboot 接口404_资深架构带你学习Springboot集成普罗米修斯
这篇文章主要介绍了springboot集成普罗米修斯(Prometheus)的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧 ...
- springboot集成普罗米修斯
Prometheus 是一套开源的系统监控报警框架.它由工作在 SoundCloud 的 员工创建,并在 2015 年正式发布的开源项目.2016 年,Prometheus 正式加入 Cloud Na ...
- SpringBoot集成Actuator端点配置
1.说明 Actuator端点可以监控应用程序并与之交互. Spring Boot包括许多内置的端点, 比如health端点提供基本的应用程序运行状况信息, 并允许添加自定义端点. 可以控制每个单独的 ...
- Windows下安装Mongodb SpringBoot集成MongoDB和Redis多数据源
全文内容: Mongodb安装 说明:Mongodb和redis是开发中常用的中间件,Redis的安装使用比较简单就不写了,只说本地也就是Windows安装Mongodb. SpringBoot集成M ...
- SpringBoot使用prometheus监控
本文介绍SpringBoot如何使用Prometheus配合Grafana监控. 1.关于Prometheus Prometheus是一个根据应用的metrics来进行监控的开源工具.相信很多工程都在 ...
- SpringBoot集成FreeMarker
给大家简单介绍一下springboot 集成FreeMarker 过程很简单,5分钟即可. 首先在项目中增添依赖spring-boot-starter-freemarker pom文件代码如下: &l ...
- springboot集成swagger2测试接口
springboot集成swagger2测试接口 1.需要的依赖 2.开始编写一个swagger2 3.演示效果图片 1.需要的依赖 <dependency><groupId> ...
- springboot 集成logback
springboot 集成logback 1.application.properties配置文件指定logback.xml logging.config=classpath:logback.xml ...
最新文章
- 扩展typeof来判断js变量的类型
- 死磕java_死磕JavaScript-垃圾收集机制
- 【数据结构】——归并排序
- 每次新增页面复制粘贴?100多行源码的 element-ui 的新增组件功能教你解愁
- apache jmeter_Apache Server和JMeter调试
- 【经典重温】所有数据无需共享同一个卷积核!谷歌提出条件参数化卷积CondConv(附Pytorch复现代码)...
- 嵌套组合图echarts
- webRTC之智能指针std::unique_ptr::reset()使用(十四)
- vue跨域使用websocket_在vue中使用SockJS实现webSocket通信的过程
- MyBatis概述与架构
- 微信小程序学习笔记-(11)-仿糗事百科
- BestCoder Round #67 (div.2) N*M bulbs
- MAPDF.NET 电子书合集
- namecheap域名如何绑定IP
- SRTF最短剩余时间优先调度C语言实现
- symfony配置文件之三:routing和路由配置
- 高翔视觉SLAM十四讲(第二版)各种软件、库安装的以及报错解决方法
- Meld——目录文件对比工具
- mysql explain type_MySQL explain type详解
- h5 微信公众号获取当前位置
热门文章
- 疯狂kotlin讲义连载之Kotlin的基础类型--null安全
- 腾讯,百度,网易游戏,华为笔面经验
- 互联网协议入门(一)
- 网站维护:Linux服务器查看外网访问IP指令汇总
- 语音信号的分帧加窗的matlab实现
- c++内存管理优化之ptmalloc,tcmalloc,jemalloc使用实例
- C++类型转换: static_cast const_cast reinterpret_cast dynamic_cast
- ubuntu12.04LTS安装已经共享的打印机
- python实现e2lsh高维数据集k近邻搜索——实现流程
- Kotlin 普及度增加,代码质量比 Java 更高?