SpringBoot SpringBoot 开发实用篇 6 监控 6.7 自定义端点

SpringBoot

【黑马程序员SpringBoot2全套视频教程,springboot零基础到项目实战(spring boot2完整版)】

SpringBoot 开发实用篇

6 监控

6.7 自定义端点
6.7.1 问题引入

之前我们已经完成了info、健康、性能指标的修改

在这里插入图片描述

现在问题来了,现在做的东西都是在之前人家有的端点上面进行修改,能不能我自己来个端点?

【答案是肯定的】

6.7.2 自定义端点

直接新建一个“端点类”

package com.dingjiaxiong.actuator;

import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.stereotype.Component;

/**
 * ClassName: PayEndpoint
 * date: 2022/10/24 10:01
 *
 * @author DingJiaxiong
 */

@Component
@Endpoint(id = "pay",enableByDefault = true)
public class PayEndpoint {

    @ReadOperation
    public void getPay(){
        System.out.println("=============");
        System.out.println("=====pay=====");
        System.out.println("=============");
    }

}

直接重启服务

在这里插入图片描述

在postman 中看看能否查到这个端点

在这里插入图片描述

OK,很明显, 我们自定义的端点已经进来了

直接调一下

在这里插入图片描述

可以看到已经执行了,说明添加成功了,但是前端没有信息返回,

在这里插入图片描述

给它加上

package com.dingjiaxiong.actuator;

import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.stereotype.Component;

/**
 * ClassName: PayEndpoint
 * date: 2022/10/24 10:01
 *
 * @author DingJiaxiong
 */

@Component
@Endpoint(id = "pay",enableByDefault = true)
public class PayEndpoint {

    @ReadOperation
    public Object getPay(){
        System.out.println("=============");
        System.out.println("=====pay=====");
        System.out.println("=============");
        
        return "你支付,我快乐";
    }

}

再次运行

在这里插入图片描述

查看面板

在这里插入图片描述

返回json 数据

package com.dingjiaxiong.actuator;

import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * ClassName: PayEndpoint
 * date: 2022/10/24 10:01
 *
 * @author DingJiaxiong
 */

@Component
@Endpoint(id = "pay",enableByDefault = true)
public class PayEndpoint {

    @ReadOperation
    public Object getPay(){
        Map map = new HashMap();
        map.put("level 1","300");
        map.put("level 2","200");
        map.put("level 3", "100");

        return map;
    }

}

内部会自动转换

OK。重启服务

在这里插入图片描述

OK, 自定义端点差不多就是这样了

回顾一下

  • 自定义端点

在这里插入图片描述

6.7.3 小结
  1. 自定义端点
6.7.4 总结
  1. 监控的意义
  2. 可视化监控平台————Spring Boot Admin
  3. 监控原理————Actuator
  4. 自定义监控指标
  • 系统端点添加监控指标
  • 自定义端点
6.7.5 开发实用篇小结

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ding Jiaxiong

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值