2021-04-20 22:15:14 +08:00
2020-12-10 18:54:29 +08:00
2021-01-27 22:58:48 +08:00
2021-04-20 22:15:14 +08:00
2020-12-10 18:54:29 +08:00
2020-12-10 18:57:39 +08:00
2021-04-20 22:15:14 +08:00
2021-04-20 22:15:14 +08:00

koTime

介绍

koTime是一个springboot项目性能分析工具通过追踪方法调用链路以及对应的运行时长快速定位性能瓶颈

预览

http://huoyo.gitee.io/ko-time/

优点:

  • 实时监听方法,统计运行时长
  • web展示方法调用链路瓶颈可视化追踪

缺点:

  • 对项目中每个方法进行监控,在性能层面会有一定的影响,建议在开发阶段使用

使用教程

  1. 引入依赖 或者 下载发行版本
 <dependency>
    <groupId>cn.langpy</groupId>
    <artifactId>ko-time</artifactId>
    <version>1.7</version>
  </dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-${freemarker或者thymeleaf任选一个}</artifactId>
</dependency>
  1. 配置信息

在application.yml中配置

spring.profiles.active=koTime
koTime.log.enable=false  # 是否开启控制输出非必填默认false
koTime.log.language=chinese # 控制台输出语言english/chinese非必填默认chinese
koTime.time.threshold=800.0 # 时间阈值用于前端展示大于阈值显示红色小于阈值显示绿色非必填默认800
koTime.pointcut=execution(* com.huoyo.demo.controller.*(..)) || execution(* com.huoyo.demo.service.*(..)) 需要监测的切面范围比如监测controller层和service层参考aop的@pointcut  v1.4开始加入的功能用来替代下面的步骤3
koTime.ui.template=thymeleaf  前端页面模板默认为freemarker可选thymeleaf 与引入的pom依赖对应

注意暂不支持mybatis的mapper监测

  1. 新建一个类实现ComputeTimeHandlerInterface并在 @Pointcut 写入 需要监测的范围

注意v1.3之前需要该步骤v1.4及以上使用koTime.pointcut配置即可无需此步骤

@Component
@Aspect
public class RunTimeHandler implements ComputeTimeHandlerInterface {
    @Override
    @Pointcut("execution(* com.huoyo..*.*(..))")
    public void prog() {

    }
}

  1. 启动项目访问 /koTime 路径即可

比如:http://localhost:8080/koTime 如果项目自定义的contextpath访问如http://localhost:8080/xxx服务/koTime

  1. 其他使用

对于单个方法的监测,可以使用@ComputeTime注解

    @ComputeTime
    public void test() {

    }

可视化展示

1.接口调用统计

根据颜色判断需要优化的接口数,红色为待优化,绿色为正常

输入图片说明

2.接口列表总览

在列表中会显示该接口的运行耗时,如果为绿色则无需优化,如果为红色,需要详细查看问题所在

输入图片说明

3.调用详情

点开接口时,会显示该接口的调用链路以及运行时长

输入图片说明

版本说明

V1.0:基本功能

V1.1:接口统计

V1.2:不可用,错误版本

V1.3:添加日志、时间阈值可配置

V1.4添加koTime.pointcut配置

V1.5剔除lombok

V1.6兼容thymeleaf

V1.7修复未调用接口时No value present异常

特别说明

1.本项目使用java8开发其他版本未曾试验如有什么bug还请告知

2.v1.5及以下版本默认使用了freemarker模板其余版本可选用thymeleaf需要自行引入

  <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-freemarker</artifactId>
        <version>xxxx</version>
  </dependency>

3.项目使用@Aspect注解未引入 aop相关包的自行引入如aspectj或者spring-boot-starter-aop

Description
koTime是一个轻量级的springboot项目性能分析工具,通过方法调用链路追踪以及运行时长监控快速定位性能瓶颈,并进行可视化展示,还支持代码热更新与邮件预警! a springboot tool for tracing call graph,which can help you find method's performances easily.
Readme LGPL-2.1 11 MiB
Languages
Java 58.6%
HTML 23.8%
CSS 12.5%
JavaScript 5.1%