Spring Boot Admin Server 2.x 融合 Javamelody

Spring Boot Admin Server 2.x 融合 Javamelody_第1张图片

先看定义

1. What is Spring Boot Admin?

codecentric’s Spring Boot Admin is a community project to manage and monitor your Spring Boot ® applications. The applications register with our Spring Boot Admin Client (via HTTP) or are discovered using Spring Cloud ® (e.g. Eureka, Consul)本文基于此种应用场景. The UI is just a Vue.js application on top of the Spring Boot Actuator endpoints.

2.What is Javamelody?

The goal of JavaMelody is to monitor Java or Java EE applications in QA and production environments. It is not a tool to simulate requests from users, it is a tool to measure and calculate statistics on real operation of an application depending on the usage of the application by users.

SBA主要作用是监控微服务状态(如CPU、内存、硬盘、redis、db等指标),也包含httptrace维度跟踪记录被监控服务的http请求时长等,但其意义不在于过程监控,过程监控还是交给专业的工具来做,如Pinpoint等APM,但如果你手头恰好没有好用的APM且不存在微服务之间复杂调用链路的话,可以尝试直接通过SBA观察服务过程指标,本文的意义即在此,通过将Javamelody内嵌到SBA 2.x中,支持通过一个终端监控服务状态&过程指标

针对SBA 1.x,Javamelody官方提供了融合工程(https://github.com/javamelody/spring-boot-admin-server-ui-javamelody),但SBA 2.x做了很大改造,老的融合工程不再适用,而SBA 1.x不适配新的Spring Boot版本(至少我使用的2.0.2.RELEASE是不适用的)

本文源码工程地址:https://github.com/number68/microservice-admin-server,可以基于此融合更多第三方工具

效果图:


Spring Boot Admin Server 2.x 融合 Javamelody_第2张图片

改造方式:

  • 增加JavaMelodyListener监听SBA InstanceEvent,根据Application的启停/上下线等Event决定是否collect该Application Remote Javamelody数据,调用的是Javamelody CollectorServlet中的add/removeApplication method,存储到key/value为application id(此处用的是instance id)与service url的map
  • 服务端融合Javamelody Servlet
  • 增加SBA Javamelody ui工程,通过SBA的viewRegistry.addView function增加菜单栏和对应的路由Component,在Component