栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java > SpringBoot

springboot2.x中的服务监控

SpringBoot 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

springboot2.x中的服务监控

想给服务添加一个监控,看看网上各位前辈的,基本都是基于springboot1.x的,springboot升级到2.0以后和1.x还是有很多不一样的,那么2.0以后怎么使用admin监控呢?

先看下图的managment.security.enable,现在已经是过时API了,那么我们必须要更新知识库了。

security.png

总体思路

和之前的思路一样,分为服务端和客户端。
服务端配置pom
客户端添加监控url配置

server端1、创建项目,引入依赖,我的完整pom如下
 
        
        
            org.springframework.boot
            spring-boot-starter-web
        

        
        
            org.springframework.boot
            spring-boot-starter-actuator
        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-server
        
        
            de.codecentric
            spring-boot-admin-server
        
        
            de.codecentric
            spring-boot-admin-server-ui
        
        
            org.springframework.boot
            spring-boot-starter-webflux
        
        
            org.jolokia
            jolokia-core
        
        
            org.springframework.boot
            spring-boot-starter-actuator
        
        
            junit
            junit
            4.11
            test
        
    
2、配置yml
server:
  port: 8888eureka:
  instance:
    hostname: localhost
    prefer-ip-address: true
    lease-renewal-interval-in-seconds: 10
  client:
    registry-fetch-interval-seconds: 5
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: always
spring:
  application:
    name: spring-boot-admin-server
3、启用服务监控
@Configuration@EnableAutoConfiguration@EnableAdminServerpublic class ActuatorApplication {    public static void main(String[] args) {
        SpringApplication.run(ActuatorApplication.class, args);
    }
}
client端

在需要监控的项目中添加以下配置

1、添加pom依赖
        
            de.codecentric
            spring-boot-admin-starter-client
        
        
            org.springframework.boot
            spring-boot-starter-actuator
        
        
            org.jolokia
            jolokia-core
        
2、添加yml配置
spring:
  application:
      name: boot-service
  boot:
    admin:
      client:
        url: http://localhost:8888
查看监控

先启动刚才创建的服务监控项目,然后再分别启动需要监控的项目,然后访问http://localhost:8888(根据你的实际情况),访问结果如下

飘红.png


一眼就看到一个不正常的服务,我们点进去看一下出了什么问题,因为我的服务确实在正常运行,可以正常访问

5.png


结果就很明显了,一看network error,明显是网络不通,可是服务在正常运行,那么基本就是权限的问题了,因为我的eboot-admin添加了shiro的权限拦截,因此上面的/actuator/**都被拦截了,我们在shiro中将该路径放行


filterChainDefinitionMap.put("/actuator/**", "anon");

再次访问,结果如下


不再红.png


applications.png


journal.png

服务出现问题,applications会有如下提示,一看offline就······


挂掉挂掉.png

至此,springboot2.0的服务监控已经搞定。同时actuator也可以配合security做权限控制,但是我们监控的这些服务大部分可能都是在内网环境使用,后期我会加上带权限的监控,所有源码已上传到gitee,【戳我获取源码】,后期新增功能和代码会随时上传,需要的小伙伴随时获取哦
当然,如果能帮我点个star就更好了^_^


作者:小尘哥
链接:https://www.jianshu.com/p/d6ad46336a4f


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/235532.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号