最近在找一个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如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
<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、启动主类:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
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:
1
2
3
4
5
|
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(实现日志级别修改功能):
1
2
3
4
|
<configuration> <include resource= "org/springframework/boot/logging/logback/base.xml" /> <jmxconfigurator/> </configuration> |
5、启动:
6、注意:
如果要监控注册到eureka的服务,必须要在这个服务里面引入:
1
2
3
4
|
<dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-actuator</artifactid> </dependency> |
来开启一些管理功能,且须在配置文件加入一句:
1
|
management.security.enabled= false |
关闭安全验证。
代码托管:https://github.com/lovnx/micro-service
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:http://blog.csdn.net/rickiyeat/article/details/73109328