俗话说,简单的就是最好的,之前收藏的工具今天简单测试用下。
- 加入依赖,kotime本体没什么说的,freemarker和aop是kotime依赖的,项目没有的话也要加上。
<dependency>
<groupId>cn.langpy</groupId>
<artifactId>ko-time</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
- 配置下application.properties(或application.yml)
#如果项目中还有其他配置请用英文逗号分隔,如:koTime,dev
spring.profiles.active=koTime
#需要监测的切面范围,参考aop的@pointcut v1.4开始加入的功能
koTime.pointcut=execution(* com.huoyo..*(..))
#######下面为可选配置##########
#是否开启koTime,默认开启,当为false时,关闭koTime
koTime.enable=true
#是否开启控制输出,默认false
koTime.log.enable=false
#控制台输出语言(english/chinese)默认chinese
koTime.log.language=chinese
#时间阈值,用于前端展示,大于阈值显示红色,小于阈值显示绿色,默认800
koTime.time.threshold=800.0
#前端页面模板,默认为freemarker,可选thymeleaf 与引入的pom依赖对应
koTime.ui.template=freemarker
#是否开启异常检测,默认为false,开启后会对方法内部抛出的异常进行统计 v2.0.0开始支持
koTime.exception.enable=true
需要注意的是切面范围要匹配正确
- 启动项目访问切面下监控接口一次,访问统计地址:
http://localhost:8080/xxx服务/koTime
,没有服务名就省略xxx服务。
注意:会影响性能,建议在开发的时候引入测试,生产关闭。