forked from xkcoding/spring-boot-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spring boot 集成 spring boot admin 进行可视化监控
- Loading branch information
Showing
15 changed files
with
224 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` 提供的端点监控,看起来确实美观不少,但是都各有优缺点。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
28 changes: 28 additions & 0 deletions
28
...-admin/src/main/java/com/xkcoding/springbootdemoadmin/SpringBootDemoAdminApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
16 changes: 16 additions & 0 deletions
16
...n/src/test/java/com/xkcoding/springbootdemoadmin/SpringBootDemoAdminApplicationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ | |
|
||
### application.yml | ||
|
||
```yml | ||
```yaml | ||
server: | ||
port: 8080 | ||
context-path: /demo | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,7 @@ | |
|
||
### application.yml | ||
|
||
```yml | ||
```yaml | ||
server: | ||
port: 8080 | ||
context-path: /demo | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,7 @@ | |
|
||
### application.yml | ||
|
||
```yml | ||
```yaml | ||
server: | ||
port: 8080 | ||
context-path: /demo | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
### application.yml | ||
|
||
```yml | ||
```yaml | ||
server: | ||
port: 8080 | ||
context-path: /demo | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ | |
|
||
### application.yml | ||
|
||
```yml | ||
```yaml | ||
server: | ||
port: 8080 | ||
context-path: /demo | ||
|