prometheus+grafana替代Zabbix监控springboot

《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!

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端口号

最后

无论是哪家公司,都很重视基础,大厂更加重视技术的深度和广度,面试是一个双向选择的过程,不要抱着畏惧的心态去面试,不利于自己的发挥。同时看中的应该不止薪资,还要看你是不是真的喜欢这家公司,是不是能真的得到锻炼。

针对以上面试技术点,我在这里也做一些分享,希望能更好的帮助到大家。

《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!
到大家。

[外链图片转存中…(img-6TJxLTHw-1714646009338)]

[外链图片转存中…(img-bStvR76I-1714646009338)]

[外链图片转存中…(img-A9LmOBC8-1714646009339)]

《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值