spring boot admin监控spring cloud 详解使用spring boot admin监控spring cloud应用程序
Lovnx 人气:0最近在找一个spring cloud的监控组件,要求粒度要到每一个接口的,hystrix dashboard显然不适合,也不是这个应用场景。后来发现了spring boot admin这个神器,可以注册到Eureka和spring cloud无缝整合,页面AngularJS写的还算凑合,里面包含有许多功能:
- 显示 name/id 和版本号
- 显示在线状态
- Logging日志级别管理
- JMX beans管理
- Threads会话和线程管理
- Trace应用请求跟踪
- 应用运行参数信息,如:
- Java 系统属性
- Java 环境变量属性
- 内存信息
- Spring 环境属性
好了,不多说,直接上和eureka整合的代码,它可以通过eureka注册表里面的信息来对每一个服务进行监控。
1、构建service-admin工程,pom如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.lovnx</groupId> <artifactId>micro-service</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>service-admin</artifactId> <packaging>jar</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.7</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server</artifactId> <version>1.4.6</version> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server-ui</artifactId> <version>1.4.6</version> </dependency> <dependency> <groupId>org.jolokia</groupId> <artifactId>jolokia-core</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Camden.SR5</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
2、启动主类:
package com.lovnx; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.context.annotation.Configuration; import de.codecentric.boot.admin.config.EnableAdminServer; @Configuration @EnableAutoConfiguration @EnableDiscoveryClient @EnableAdminServer public class SpringBootAdminApplication { public static void main(String[] args) { SpringApplication.run(SpringBootAdminApplication.class, args); } }
3、配置文件application.properties:
server.port=7088 spring.application.name=service-admin eureka.client.serviceUrl.defaultZone=http://localhost:7070/eureka/ management.security.enabled=false info.version=@project.version@
4、logback.xml(实现日志级别修改功能):
<configuration> <include resource="org/springframework/boot/logging/logback/base.xml"/> <jmxConfigurator/> </configuration>
5、启动:
6、注意:
如果要监控注册到eureka的服务,必须要在这个服务里面引入:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
来开启一些管理功能,且须在配置文件加入一句:
management.security.enabled=false
关闭安全验证。
加载全部内容