SpringBoot:Actuator监控中心+AdminUI界面管理

一,Actuator + AdminUI服务监控中心介绍

    1,什么是SpringBoot监控中心

       针对微服务器监控、服务器内存变化(堆内存,线程,日志管理等)、检测服务配置连接池是否可用(模拟访问、懒加载)、统计现有Bean(通过Spring容器)、Http接口(@RequestMapping)的一系列数据管理。Actuator监控应用只通过JSON形式返回数据统计结果,没有UI界面处理;AdminUI则内置Actuator服务监控,并对返回JSON数据进行图形化处理展示。

    2,为什么要用SpringBoot监控中心

        Actuator是SpringBoot的一个附加功能,可以帮助应用程序在生产环境运行时的监控和管理。可以使用HTTP的各个请求路径来监管、审计、收集引用的运行情况,特别对于微服务管理十分有意义;

        AdminUI内置了Actuator服务,是对监控服务的图形化界面补充;

二,SpringBoot整合Actuator服务监控

    1,maven依赖引入



	org.springframework.boot
	spring-boot-starter-actuator

    2,application.properties:配置可进行监控的接口,此处配置为全部启动,默认只启用三个接口

### 监控中心配置, 允许监控所欲接口
management.endpoints.web.exposure.include=*

    3,启动服务,从打印日志中查看启用结果;如下图,说明启用成功,此处应该为15个endPoints,因为我已经引入了AdminUI依赖,默认添加了该部分一个配置点;如果不配置第二步启用全部,则此处显示为2个endPoints

SpringBoot:Actuator监控中心+AdminUI界面管理_第1张图片

    4,页面访问服务监控,返回结果均为JSON;如下,每一个链接均表示一个功能统计。比如mappings表示全部HTTP接口统计,beans表示Spring容器中的所有注册Bean,threadDump表示系统中的所有线程,health对所有懒加载的服务连接进行虚拟连接测试等等;

SpringBoot:Actuator监控中心+AdminUI界面管理_第2张图片

SpringBoot:Actuator监控中心+AdminUI界面管理_第3张图片

SpringBoot:Actuator监控中心+AdminUI界面管理_第4张图片

SpringBoot:Actuator监控中心+AdminUI界面管理_第5张图片

三,SpringBoot整合AdminUI界面管理

    1,启动AdminUI界面,需要单独定义AdminUI-Server服务,独立于功能服务之外。所有功能服务作为AdminUI-Client服务连接到Server服务,Server服务检测到连接后对进行监控处理

    2,AdminUI-Server服务

        * 创建一个Maven服务,引入maven依赖




  4.0.0

  springboot_actuator_server
  springboot.actuator.server
  1.0-SNAPSHOT

  
    org.springframework.boot
    spring-boot-starter-parent
    2.1.1.RELEASE
     
  

  springboot.actuator.server
  
  http://www.example.com

  
    UTF-8
    1.7
    1.7
  

  
    
    
      de.codecentric
      spring-boot-admin-starter-server
      2.1.1
    
    
      org.springframework.boot
      spring-boot-starter-webflux
    
    
    
      org.jolokia
      jolokia-core
    
    
    
      org.springframework.boot
      spring-boot-starter-actuator
    
    
    
      com.googlecode.json-simple
      json-simple
      1.1
    
  

  
    
      
        
        
          maven-clean-plugin
          3.1.0
        
        
        
          maven-resources-plugin
          3.0.2
        
        
          maven-compiler-plugin
          3.8.0
        
        
          maven-surefire-plugin
          2.22.1
        
        
          maven-jar-plugin
          3.0.2
        
        
          maven-install-plugin
          2.5.2
        
        
          maven-deploy-plugin
          2.8.2
        
        
        
          maven-site-plugin
          3.7.1
        
        
          maven-project-info-reports-plugin
          3.0.0
        
      
    
    
      
        org.springframework.boot
        spring-boot-maven-plugin
      
    
  

        * application.properties配置文件添加配置信息,此处主要对端口号进行修改,不与其他进程冲突

server.port=8081

        * 启动类:此处启动类不同于标准的SpringBoot启动类

package com.actuator.server;

import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Configuration;

/**
 * @author pj_zhang
 * @create 2018-12-30 16:24
 **/
@Configuration
@EnableAutoConfiguration
@EnableAdminServer
public class AppApplication {
    public static void main(String[] args) {
        SpringApplication.run(AppApplication.class, args);
    }
}

        * 启动服务后进行页面访问,出现UI界面说明配置成功

SpringBoot:Actuator监控中心+AdminUI界面管理_第6张图片

    3,AdminUI-Client

        * maven依赖,注意已经引入的依赖不要二次引入



	de.codecentric
	spring-boot-admin-starter-client
	2.1.1



	org.jolokia
	jolokia-core



	org.springframework.boot
	spring-boot-starter-actuator



	com.googlecode.json-simple
	json-simple
	1.1

        * application.properties配置服务监控信息指向AdminUI-Server

### 注册当前服务到AdminUI-Server服务中
spring.boot.admin.client.url=http://127.0.0.1:8081

         * 启动服务后,查看UI界面已经已经监控到注册服务,注意此处当前服务的注册ID

SpringBoot:Actuator监控中心+AdminUI界面管理_第7张图片

        * 通过点击上面服务连接,默认classpath:index.html文件,static目录为静态资源存放目录,访问会自动解析

SpringBoot:Actuator监控中心+AdminUI界面管理_第8张图片

SpringBoot:Actuator监控中心+AdminUI界面管理_第9张图片

    4,AdminUI界面演示

        * 进入界面入口,点击中心实例进入主控制界面

SpringBoot:Actuator监控中心+AdminUI界面管理_第10张图片

    * 主控制界面。包括刚才通过Actuator演示的所有功能,此处功能已经全部通过UI界面勾画,方便服务监控信息查看;左侧为Actuator功能列表,右侧为具体服务信息

SpringBoot:Actuator监控中心+AdminUI界面管理_第11张图片

        * 以Beans功能为例,展示所有Spring容器中的Bean,大致跟踪服务展示流程;点击Beans按钮后,服务会通过实例注册ID路由到目标服务进行调用,具体信息获取方式依旧是依靠Actuator提供的服务监控接口进行服务统计

SpringBoot:Actuator监控中心+AdminUI界面管理_第12张图片

你可能感兴趣的:(SpringBoot)