通过mybatis拦截器给sql执行加一个耗时监控

news/2025/2/11 18:30:16/

代码没什么内容,直接贴上来吧,其中costTimeUtil可以看我的另一篇博文:java实现一个不带次数变量的加权平均值算法-CSDN博客

@Slf4j
@Intercepts({@Signature(type = StatementHandler.class,method = "query",args = {Statement.class, ResultHandler.class}
), @Signature(type = StatementHandler.class,method = "queryCursor",args = {Statement.class}
), @Signature(type = StatementHandler.class,method = "update",args = {Statement.class}
), @Signature(type = StatementHandler.class,method = "batch",args = {Statement.class}
)})
public class MetricOnDbQueryInterceptor implements Interceptor {private static final String MAPPER_SLOW_SQL_METRIC = "MetricOnDbQueryInterceptor_cost";@Resourceprivate AlertOnTimesOfAverageCostTimeUtil costTimeUtil;@Overridepublic Object intercept(Invocation invocation) throws Throwable {long start = System.currentTimeMillis();try {return invocation.proceed();} finally {String sql = ((StatementHandler) invocation.getTarget()).getBoundSql().getSql();long costTime = System.currentTimeMillis() - start;if (costTimeUtil.shouldDoTheMetricWork(sql, costTime)) {//这里可以做一些监控打点的功能log.warn("it is a slow sql query:{}, costTime:{}", sql, costTime);}}}
}


http://www.ppmy.cn/news/1336580.html

相关文章

ES6 模块化、CommonJS 模块化的区别经典面试题

语法差异: ES6 模块化 使用 import 和 export 关键字来导入和导出模块。 javascriptCopy code// 导入模块 import { someFunction } from someModule; ​ // 导出模块 export function myFunction() {// code } CommonJS 模块化 使用 require 和 module.exports 或 exports 来导…

ETCD高可用架构涉及常用功能整理

ETCD高可用架构涉及常用功能整理 1. etcd的高可用系统架构和相关组件1.1 Quorum机制1.2 Raft协议 2. etcd的核心参数2.1 常规配置2.2 特殊优化配置2.2.1 强行拉起新集群 --force-new-cluster2.2.2 兼容磁盘io性能差2.2.3 etcd存储quota 3. etcd常用命令3.1 常用基础命令3.1.1 列…

综合案例 - 商品列表

文章目录 需求说明1.my-tag组件封装(完成初始化)2.may-tag封装(控制显示隐藏)3.my-tag组件封装(v-model处理:信息修改)4.my-table组件封装(整个表格)①数据不能写死&…

docker swarm转移K8s 实践(-)

相关资料 Kubernetes初识_kubernetes怎么读-CSDN博客

电商新时代:小红书笔记详情API引领购物体验变革

一、引言 随着互联网的普及和电子商务的飞速发展,消费者的购物方式和习惯也在发生深刻变化。传统的商品详情页面已经不能满足现代消费者的需求,他们更希望在购物前了解更多关于产品的真实评价和详细信息。在这样的背景下,小红书笔记详情API应…

漏洞原理MySQL注入布尔盲注入

1 判断MySql注入点是否存在 利用盲注入的方式 http://127.0.0.1/news/show.php?id46 and 11 # 正常显示 http://127.0.0.1/news/show.php?id46 and 12 # 不显示 2 获取数据库的长度 http://127.0.0.1/news/show.php?id46 and length(database())n n的范围是从 1 开始 h…

【使用opencv、python、dlib实现人脸关键点检测、眨眼检测和嘴巴开闭检测,可简单用于疲劳检测】

使用opencv、python、dlib实现人脸关键点检测、眨眼检测和嘴巴开闭检测,可简单用于疲劳检测 环境准备opencvdlib 原理眨眼检测张嘴检测原理 代码示例人脸关键点检测眨眼检测张嘴检测 写在最后 环境准备 opencv 一、简单介绍 OpenCV (Open Source Computer Vision…

FastBee开源物联网平台2.0开源版发布啦!!!

一、项目介绍 物美智能(wumei-smart)更名为蜂信物联(FastBee)。 FastBee开源物联网平台,简单易用,更适合中小企业和个人学习使用。适用于智能家居、智慧办公、智慧社区、农业监测、水利监测、工业控制等。 系统后端采用Spring boot;前端采用…