com.dalaoyang
springboot2_prometheus
0.0.1-SNAPSHOT
springboot2_prometheus
springboot2_prometheus
<java.version>1.8</java.version>
org.springframework.boot
spring-boot-starter-actuator
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
test
io.micrometer
micrometer-registry-prometheus
1.1.3
org.springframework.boot
spring-boot-maven-plugin
2.修改application.yml
management:
endpoints:
web:
exposure:
include: ‘*’
metrics:
tags:
application: ${spring.application.name}
health:
redis:
enabled: false
3.设置application
在启动问价中加入以下代码。
@Bean
MeterRegistryCustomizer configurer(@Value(“${spring.application.name}”) String applicationName) {
return (registry) -> registry.config().commonTags(“application”, applicationName);
}
SpringBoot项目到这里就配置完成了,启动项目,访问http://ip:8080/actuator/prometheus即可看到返回值,这些值就是spring boot返回在前台页面的信息。
3.Prometheus配置
在prometheus配置监控我们的SpringBoot应用,完整配置如下所示。找到配置文件替换即可。
my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
scrape_timeout is set to the global default (10s).
Alertmanager configuration
alerting:
alertmanagers:
-
static_configs:
-
targets:
- alertmanager:9093
Load rules once and periodically evaluate them according to the global ‘evaluation_interval’.
rule_files:
- “first_rules.yml”
- “second_rules.yml”
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’
static_configs:
-
targets: [‘localhost:9090’]
-
job_name: ‘springboot_system’ #监控任务名称
scrape_interval: 5s
metrics_path: ‘/actuator/prometheus’
static_configs:
- targets: [‘localhost:8088’] #springboot端口号
最后
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,不论你是刚入门Java开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,不论你是刚入门Java开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!**
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!