实现springboot的admin管理监控案例

实现springboot的admin管理监控案例

package com.itheima.controller;

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

@RestController
public class HelloController {
    @RequestMapping("/user/findAll")
    public void sayHello() {
        System.out.println("hello");
    }
}

application中的配置

# 暴露所有的监控点
management.endpoints.web.exposure.include=*
# 开启endpoint 关闭服务功能
management.endpoint.shutdown.enabled=true

# springboot admin 服务端的地址,http://localhost:9000
# 连接到springboot的admin
spring.boot.admin.client.url=http://localhost:9000

admin-server中的配置

server.port=9000

启动引导类

package com.itheima;

import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableAdminServer //开启springboot的admin的服务端的支持
public class Springboot06AdminServerApplication {

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

}

pom文件中的配置

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.9.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.itheima</groupId>
    <artifactId>springboot06-admin-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>springboot06-admin-server</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-boot-admin.version>2.1.5</spring-boot-admin.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
        </dependency>


    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-dependencies</artifactId>
                <version>${spring-boot-admin.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>


</project>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Spring Boot Admin 提供了默认的监控界面和监控指标,但是有时候我们需要根据项目需求进行自定义监控。下面介绍一下如何自定义 Spring Boot Admin 监控。 1. 自定义监控指标 Spring Boot Admin 默认提供了一些监控指标,比如内存使用情况、线程池信息等。但是如果我们需要监控其他的指标,可以通过自定义 Endpoint 的方式来实现。 自定义 Endpoint 需要实现 `org.springframework.boot.actuate.endpoint.Endpoint` 接口,示例代码如下: ```java @Component public class CustomEndpoint implements Endpoint<Map<String, Object>> { @Override public String getId() { return "my-endpoint"; } @Override public boolean isEnabled() { return true; } @Override public boolean isSensitive() { return true; } @Override public Map<String, Object> invoke() { // 获取自定义指标信息 Map<String, Object> customMetrics = new HashMap<>(); customMetrics.put("customMetric1", "value1"); customMetrics.put("customMetric2", "value2"); return customMetrics; } } ``` 在 `invoke()` 方法中返回自定义的指标信息即可。同时需要注意的是,`isEnabled()` 和 `isSensitive()` 方法需要根据实际情况返回是否启用和是否敏感信息。 2. 自定义监控页面 Spring Boot Admin监控页面是基于 [AdminLTE](https://adminlte.io/) 构建的,可以通过自定义 AdminLTE 主题来自定义监控页面。 首先需要创建一个自定义的 AdminLTE 主题,可以在 [AdminLTE ThemeRoller](https://adminlte.io/themes/AdminLTE/index.html#!/custom) 上进行配置和下载。下载后将主题文件放到 Spring Boot Admin 的静态资源目录下即可。 然后在 Spring Boot Admin 的配置文件中添加如下配置: ```yaml spring: boot: admin: ui: custom: brand: primary: "#3c8dbc" title: "Custom Title" ``` 其中 `brand` 和 `title` 分别代表自定义的品牌颜色和标题,根据实际情况进行调整即可。 以上就是自定义 Spring Boot Admin 监控的方法,可以根据实际项目需求进行自定义。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值