prometheus监控SpringBoot项目

书接上回,我们已经介绍了:
1.grafana与prometheus安装
2.prometheus监控服务器状态
3.prometheus监控RabbitMQ
此回将prometheus监控SpringBoot项目

一、SpringBoot集成Prometheus

依赖
 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
        </dependency>
配置
management:
  endpoints:
    web:
      exposure:
        include: 'prometheus' #[*]
  metrics:
    tags:
      application: ${spring.application.name}

二、导入模板

https://grafana.com/grafana/dashboards/6756
在这里插入图片描述

二、导入模板

https://grafana.com/grafana/dashboards/6756
在这里插入图片描述

三、修改prometheus文件

 - job_name: webhook
    scrape_interval: 15s
    scrape_timeout: 10s
    metrics_path: '/actuator/prometheus'
    static_configs:
     - targets: [ip:8999','ip','1p:20028']

重启prometheus
效果
在这里插入图片描述

关注 Java有货领取更多资料

联系小编。微信:372787553,带您进群互相学习
左侧小编微信,右侧获取免费资料
在这里插入图片描述

技术博客:https://blog.csdn.net/weixin_38937840

SpringCloud学习代码: https://github.com/Dylan-haiji/javayh-cloud

Redis、Mongo、Rabbitmq、Kafka学习代码: https://github.com/Dylan-haiji/javayh-middleware

AlibabaCloud学习代码:https://github.com/Dylan-haiji/javayh-cloud-nacos

SpringBoot+SpringSecurity实现自定义登录学习代码:https://github.com/Dylan-haiji/javayh-distribution

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要解决 Prometheus 监控 Spring Boot 项目无法访问 /actuator/prometheus 的权限问题,可以按照以下步骤进行操作: 1. 确认 Prometheus 已正确配置和运行。确保 Prometheus 的配置文件中已添加正确的目标 URL,即 Spring Boot 应用程序的 /actuator/prometheus 端点。 2. 在 Spring Boot 项目中,确保已添加合适的依赖。在项目的 pom.xml 文件中,添加以下依赖项: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> </dependency> ``` 3. 确认 Spring Boot 项目的配置文件中已启用 Prometheus 监控。在 application.properties 文件中,添加以下配置: ``` # 启用 Prometheus endpoint management.endpoints.web.exposure.include=prometheus ``` 4. 如果项目中使用了安全框架(如 Spring Security),则需要为 Prometheus 端点添加访问权限。在项目的安全配置文件中,添加以下配置: ```java @Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/actuator/prometheus").permitAll() // 允许所有用户访问 Prometheus 端点 .anyRequest().authenticated(); // 其他端点需要身份验证 } } ``` 执行以上步骤后,重新启动 Spring Boot 项目Prometheus,然后可以尝试访问 /actuator/prometheus 端点。现在,应该能够成功访问该端点,并获取到 Prometheus 所需的监控数据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小杨同学~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值