spring-boot-actuator-monitor
基于spring boot的 监控平台
#spring-boot-admin 监控后台
新建一个maven工程 boot-admin , 继承 spring-boot-starter-parent
1
2
3
4
5
6
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.4.RELEASE</version>
</parent>加入依赖
1 | <dependency> |
加入plugin 以 exec jar包运行
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<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>新建执行执行类 com.izerui.boot.admin.Application.java
1 | @SpringBootApplication |
- 声明监控后台的应用名称、端口、上下文、基本授权验证用户名、密码等信息 application.properties
1 | # application |
mvn install 后 执行 java -jar boot-admin-exec.jar
访问 http://主机ID:端口/boot-admin
注册应用到监控后台
确保应用继承 spring-boot-starter-parent
1
2
3
4
5
6
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.4.RELEASE</version>
</parent>引入依赖
1 | <dependency> |
配置被监控的应用的名称和监控后台地址 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注意上下文。
配置logback的jmx接口调用
1
2
3
4
5
6
7
8
9
10"1.0" encoding="UTF-8" xml version=
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<jmxConfigurator/>
<logger name="com.izerui" level="DEBUG"/>
<root level="INFO">
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>
</configuration>发布自定义jmx接口
在spring bean 类的头信息上增加注解 @ManagedResource(currencyTimeLimit = 20) 和 @Lazy
声明属性: @ManagedAttribute(description = "当前TCP连接数")
声明方法: @ManagedOperation(description = "关闭对应IP的所有连接")
@ManagedOperationParameters(
@ManagedOperationParameter(name = "ip", description = "终端IP")
)
参考资料: