spring-boot-actuator-monitor

基于spring boot的 监控平台

#spring-boot-admin 监控后台

  1. 新建一个maven工程 boot-admin , 继承 spring-boot-starter-parent

    org.springframework.boot spring-boot-starter-parent 1.2.4.RELEASE
  2. 加入依赖

    org.springframework.boot spring-boot-starter-web de.codecentric spring-boot-admin-server 1.2.1 de.codecentric spring-boot-admin-server-ui 1.2.1 org.springframework.boot spring-boot-starter-security com.googlecode.json-simple json-simple false
  3. 加入plugin 以 exec jar包运行

       <plugin>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-maven-plugin</artifactId>
           <executions>
               <execution>
                   <goals>
                       <goal>repackage</goal>
                   </goals>
                   <configuration>
                       <classifier>exec</classifier>
                   </configuration>
               </execution>
           </executions>
       </plugin>
    
  4. 新建执行执行类 com.izerui.boot.admin.Application.java

    @SpringBootApplication @EnableAdminServer @EnableDiscoveryClient public class Application {

       public static void main(String[] args) {
           SpringApplication.run(Application.class,args);
       }
    

    }

  5. 声明监控后台的应用名称、端口、上下文、基本授权验证用户名、密码等信息 application.properties

    application

    server.port = 8888

    basic security

    security.ignored=/api/** security.user.name=boot security.user.password=boot1234

  6. mvn install 后 执行 java -jar boot-admin-exec.jar

  7. 访问 http://主机ID:端口/boot-admin


注册应用到监控后台

  1. 确保应用继承 spring-boot-starter-parent

    org.springframework.boot spring-boot-starter-parent 1.2.4.RELEASE
  2. 引入依赖

    de.codecentric spring-boot-admin-starter-client 1.2.1 com.googlecode.json-simple json-simple false
  3. 配置被监控的应用的名称和监控后台地址 application.properties

    jar 方式运行

    web application

    server.port=28584 info.version=@pom.version@ info.info=微信代理服务 management.context-path=/management server.context-path=/@pom.artifactId@ endpoints.jmx.domain=@pom.artifactId@ spring.application.name=@pom.artifactId@

    boot admin

    spring.boot.admin.url=http://192.168.1.128:8888/boot-admin


    war 方式运行

    web application

    info.version=@pom.version@ info.info=阿里支付服务 management.context-path=/management endpoints.jmx.domain=@pom.artifactId@ spring.application.name=@pom.artifactId@

    boot admin

    spring.boot.admin.url=http://192.168.1.128:8888 spring.boot.admin.client.service-url=http://192.168.1.106:8098/qq-pay-web

    注意: 别忘了添加logging配置

    LOGGING

    logging.file=/tmp/logs/offline-proxy-tcp.log

    注意: 有些应用被权限框架拦截了。故需要加入 management.context-path=/management 并在权限框架内 将 /management/** = anon 权限放开,声明url注意上下文。

  4. 配置logback的jmx接口调用

  5. 发布自定义jmx接口

    在spring bean 类的头信息上增加注解 @ManagedResource(currencyTimeLimit = 20) 和 @Lazy

    声明属性: @ManagedAttribute(description = "当前TCP连接数")

    声明方法: @ManagedOperation(description = "关闭对应IP的所有连接") @ManagedOperationParameters( @ManagedOperationParameter(name = "ip", description = "终端IP") )

参考资料: