Skip to content

Commit

Permalink
spring boot 集成 spring boot admin 进行可视化监控
Browse files Browse the repository at this point in the history
  • Loading branch information
xkcoding committed Nov 21, 2017
1 parent 408e0d8 commit c6d9899
Show file tree
Hide file tree
Showing 15 changed files with 224 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ spring boot demo 是一个用来学习 spring boot 的项目,已经集成 actu
<module>../spring-boot-demo-helloworld</module>
<module>../spring-boot-demo-properties</module>
<module>../spring-boot-demo-actuator</module>
<module>../spring-boot-demo-admin</module>
<module>../spring-boot-demo-logback</module>
<module>../spring-boot-demo-orm-jpa</module>
<module>../spring-boot-demo-orm-mybatis</module>
Expand Down Expand Up @@ -143,6 +144,7 @@ spring boot demo 是一个用来学习 spring boot 的项目,已经集成 actu
| [spring-boot-demo-helloworld](./spring-boot-demo-helloworld) | spring-boot 的一个 helloworld |
| [spring-boot-demo-properties](./spring-boot-demo-properties) | spring-boot 读取配置文件中的内容 |
| [spring-boot-demo-actuator](./spring-boot-demo-actuator) | spring-boot 集成 spring-boot-starter-actuator 用于监控 spring-boot 的启动和运行状态 |
| [spring-boot-demo-admin](./spring-boot-demo-admin) | spring-boot 集成 spring-boot-admin 来可视化的监控 spring-boot 程序的运行状态,可以与 actuator 互相搭配使用 |
| [spring-boot-demo-logback](./spring-boot-demo-logback) | spring-boot 集成 logback 日志 |
| [spring-boot-demo-orm-jpa](./spring-boot-demo-orm-jpa) | spring-boot 集成 spring-boot-starter-data-jpa 操作数据库 |
| [spring-boot-demo-orm-mybatis](./spring-boot-demo-orm-mybatis) | spring-boot 集成 [mybatis-spring-boot-starter](https://github.com/mybatis/spring-boot-starter)[mybatis-spring-boot-starter](https://github.com/alibaba/druid/tree/master/druid-spring-boot-starter) |
Expand Down
4 changes: 2 additions & 2 deletions spring-boot-demo-actuator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ management:

#### 方法一:(本 demo 中使用的是这种)

```yml
```yaml
management:
security:
enabled: false
Expand All @@ -94,7 +94,7 @@ pom.xml 中添加以下 `spring-boot-starter-security` 依赖:

并在 `application.yml` 文件中设置访问的密码

```yml
```yaml
security:
basic:
enabled: true
Expand Down
103 changes: 103 additions & 0 deletions spring-boot-demo-admin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# spring-boot-demo-admin

依赖[spring-boot-demo-parent](../spring-boot-demo-parent)、服务端依赖 `spring-boot-demo-admin``spring-boot-admin-server-ui`、客户端依赖 `spring-boot-admin-starter-client`

### pom.xml

```xml
<?xml version="1.0" encoding="UTF-8"?>
<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>

<artifactId>spring-boot-demo-admin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<name>spring-boot-demo-admin</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>com.xkcoding</groupId>
<artifactId>spring-boot-demo-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../spring-boot-demo-parent/pom.xml</relativePath>
</parent>

<properties>
<admin.server.version>1.5.2</admin.server.version>
<admin.server.ui.version>1.5.2</admin.server.ui.version>
<admin.client.version>1.5.2</admin.client.version>
</properties>

<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
<version>${admin.server.version}</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
<version>${admin.server.ui.version}</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>${admin.client.version}</version>
</dependency>
</dependencies>

<build>
<finalName>spring-boot-demo-admin</finalName>
</build>

</project>
```

### application.yml

```yaml
server:
port: 8080
context-path: /demo
spring:
application:
# 可视化管控台展示的监控项目名,不设置,会使用自动生成的名字
name: Spring Boot Admin
boot:
admin:
# 可视化管控台界面的 context-path
context-path: /spa
url: http://localhost:${server.port}/${server.context-path}
jackson:
serialization: true
# 去除权限校验
endpoints:
sensitive: false
```
### SpringBootDemoAdminApplication.java
```java
@SpringBootApplication
@EnableAdminServer // 开启管控台
@RestController
public class SpringBootDemoAdminApplication {

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

@GetMapping("/")
public Map<String, Object> index() {
ConcurrentMap<String, Object> ret = Maps.newConcurrentMap();
ret.put("msg", "Hello Spring Boot Admin");
return ret;
}
}
```

### 访问

http://localhost:8080/demo/spa 即可查看管控台主页,点击项目的 `Detail` 即可查看详细信息,但是比起 `actuator` 提供的端点监控,看起来确实美观不少,但是都各有优缺点。
48 changes: 48 additions & 0 deletions spring-boot-demo-admin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>

<artifactId>spring-boot-demo-admin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<name>spring-boot-demo-admin</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>com.xkcoding</groupId>
<artifactId>spring-boot-demo-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../spring-boot-demo-parent/pom.xml</relativePath>
</parent>

<properties>
<admin.server.version>1.5.2</admin.server.version>
<admin.server.ui.version>1.5.2</admin.server.ui.version>
<admin.client.version>1.5.2</admin.client.version>
</properties>

<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
<version>${admin.server.version}</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
<version>${admin.server.ui.version}</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>${admin.client.version}</version>
</dependency>
</dependencies>

<build>
<finalName>spring-boot-demo-admin</finalName>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.xkcoding.springbootdemoadmin;

import com.google.common.collect.Maps;
import de.codecentric.boot.admin.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.concurrent.ConcurrentMap;

@SpringBootApplication
@EnableAdminServer // 开启管控台
@RestController
public class SpringBootDemoAdminApplication {

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

@GetMapping("/")
public Map<String, Object> index() {
ConcurrentMap<String, Object> ret = Maps.newConcurrentMap();
ret.put("msg", "Hello Spring Boot Admin");
return ret;
}
}
17 changes: 17 additions & 0 deletions spring-boot-demo-admin/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
server:
port: 8080
context-path: /demo
spring:
application:
# 可视化管控台展示的监控项目名,不设置,会使用自动生成的名字
name: Spring Boot Admin
boot:
admin:
# 可视化管控台界面的 context-path
context-path: /spa
url: http://localhost:${server.port}/${server.context-path}
jackson:
serialization: true
# 去除权限校验
endpoints:
sensitive: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.xkcoding.springbootdemoadmin;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringBootDemoAdminApplicationTests {

@Test
public void contextLoads() {
}

}
2 changes: 1 addition & 1 deletion spring-boot-demo-cache-redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

### application.yml

```yml
```yaml
server:
port: 8080
context-path: /demo
Expand Down
2 changes: 1 addition & 1 deletion spring-boot-demo-helloworld/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class SpringBootDemoHelloworldApplication {

### application.yml

```yml
```yaml
server:
port: 8080
context-path: /demo
Expand Down
2 changes: 1 addition & 1 deletion spring-boot-demo-logback/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class SpringBootDemoLogbackApplication {

### application.yml

```yml
```yaml
server:
port: 8080
context-path: /demo
Expand Down
2 changes: 1 addition & 1 deletion spring-boot-demo-orm-jpa/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

### application.yml

```yml
```yaml
server:
port: 8080
context-path: /demo
Expand Down
2 changes: 1 addition & 1 deletion spring-boot-demo-orm-mybatis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

### application.yml

```yml
```yaml
server:
port: 8080
context-path: /demo
Expand Down
1 change: 1 addition & 0 deletions spring-boot-demo-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<module>../spring-boot-demo-helloworld</module>
<module>../spring-boot-demo-properties</module>
<module>../spring-boot-demo-actuator</module>
<module>../spring-boot-demo-admin</module>
<module>../spring-boot-demo-logback</module>
<module>../spring-boot-demo-orm-jpa</module>
<module>../spring-boot-demo-orm-mybatis</module>
Expand Down
2 changes: 1 addition & 1 deletion spring-boot-demo-properties/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### application.yml

```yml
```yaml
server:
port: 8080
context-path: /demo
Expand Down
2 changes: 1 addition & 1 deletion spring-boot-demo-swagger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

### application.yml

```yml
```yaml
server:
port: 8080
context-path: /demo
Expand Down

0 comments on commit c6d9899

Please sign in to comment.