Spring boot监控Actuator

网友投稿 276 2022-11-21


Spring boot监控Actuator

Actuator是监控管理http://,不过没有可视化,这里就引入了admin-ui来解决Spring Boot Admin 分为Client端和Server端Client端是客户端Server端是spring-boot-admin来监控client的.先来一个Client客户端代码;

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

spring-boot-demo-admin-client

1.0.0-SNAPSHOT

jar

spring-boot-demo-admin-client

Demo project for Spring Boot

com.xkcoding

spring-boot-demo-admin

1.0.0-SNAPSHOT

UTF-8

UTF-8

1.8

org.springframework.boot

spring-boot-starter-web

de.codecentric

spring-boot-admin-starter-client

org.springframework.boot

spring-boot-starter-security

org.springframework.boot

spring-boot-starter-test

test

spring-boot-demo-admin-client

org.springframework.boot

spring-boot-maven-plugin

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

spring-boot-demo-admin-client

1.0.0-SNAPSHOT

jar

spring-boot-demo-admin-client

Demo project for Spring Boot

com.xkcoding

spring-boot-demo-admin

1.0.0-SNAPSHOT

UTF-8

UTF-8

1.8

org.springframework.boot

spring-boot-starter-web

de.codecentric

spring-boot-admin-starter-client

org.springframework.boot

spring-boot-starter-security

org.springframework.boot

spring-boot-starter-test

test

spring-boot-demo-admin-client

org.springframework.boot

spring-boot-maven-plugin

application.yml文件,注意这里的url一定跑配置到Server的路径,不然找不到,有点类型erkura的注册中心地址.

server:

port: 8081

servlet:

context-path: /demo

spring:

application:

# Spring Boot Admin展示的客户端项目名,不设置,会使用自动生成的随机id

name: spring-boot-demo-admin-client

boot:

admin:

client:

# Spring Boot Admin 服务端地址

url: "http://localhost:8080/"

instance:

metadata:

# 客户端端点信息的安全认证信息

user.name: ${spring.security.user.name}

user.password: ${spring.security.user.password}

security:

user:

name: xkcoding

password: 123456

management:

endpoint:

health:

# 端点健康情况,默认值"never",设置为"always"可以显示硬盘使用情况和线程情况

show-details: always

endpoints:

web:

exposure:

# 设置端点暴露的哪些内容,默认["health","info"],设置"*"代表暴露所有可访问的端点

include: "*"

Java文件就随便暴露个接口就行

package com.xkcoding.admin.client.controller;

import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.RestController;

/**

*

* 首页

*

*

* @package: com.xkcoding.admin.client.controller

* @description: 首页

* @author: yangkai.shen

* @date: Created in 2018/10/8 2:15 PM

* @copyright: Copyright (c) 2018

* @version: V1.0

* @modified: yangkai.shen

*/

@RestController

public class IndexController {

@GetMapping(value = {"", "/"})

public String index() {

return "This is a Spring Boot Admin Client.";

}

}

接下来是Server服务端,作为监控平台使用pom.xml

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

spring-boot-demo-admin-server

1.0.0-SNAPSHOT

jar

spring-boot-demo-admin-server

Demo project for Spring Boot

com.xkcoding

spring-boot-demo-admin

1.0.0-SNAPSHOT

UTF-8

UTF-8

1.8

org.springframework.boot

spring-boot-starter-web

de.codecentric

spring-boot-admin-starter-server

org.springframework.boot

spring-boot-starter-test

test

spring-boot-demo-admin-server

org.springframework.boot

spring-boot-maven-plugin

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

spring-boot-demo-admin-server

1.0.0-SNAPSHOT

jar

spring-boot-demo-admin-server

Demo project for Spring Boot

com.xkcoding

spring-boot-demo-admin

1.0.0-SNAPSHOT

UTF-8

UTF-8

1.8

org.springframework.boot

spring-boot-starter-web

de.codecentric

spring-boot-admin-starter-server

org.springframework.boot

spring-boot-starter-test

test

spring-boot-demo-admin-server

org.springframework.boot

spring-boot-maven-plugin

application.yml

server:

port: 8080

运行服务端地址,发现已经检测到了注册过的客户端

可以看到客户端的信息

http追踪可以看到请求


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:JAVA 8 '::' 关键字详解
下一篇:Maven插件的安装及使用
相关文章

 发表评论

暂时没有评论,来抢沙发吧~