更新pom依赖

更新jdk基础依赖为jdk17
更新spring-boot依赖为3
重新整理配置文件DefaultConfig, KoTimeConfig, KoTimeRunner, LoadConfig
更新界面容量显示为易读, 调整显示样式
This commit is contained in:
ccz 2024-07-05 11:39:56 +08:00
parent 5965c682b4
commit 00ada5121b
10 changed files with 725 additions and 370 deletions

1
.gitignore vendored
View File

@ -4,4 +4,3 @@ rebel.xml
target/
.txlcn
*.log
/.idea/

29
pom.xml
View File

@ -6,35 +6,41 @@
<groupId>cn.langpy</groupId>
<artifactId>ko-time</artifactId>
<version>2.4.4</version>
<version>3.0.0</version>
<name>KoTime</name>
<description>A springboot tool for tracking the paths of the methods,which can help you find method's performances easily.</description>
<licenses>
<license>
<name>GNU Lesser General Public License v2.1</name>
<url>https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt</url>
</license>
</licenses>
<url>https://gitee.com/huoyo/ko-time</url>
<scm>
<tag>master</tag>
<url>https://gitee.com/huoyo/ko-time.git</url>
<connection>scm:git:https://gitee.com/huoyo/ko-time.git</connection>
<developerConnection>scm:git:https://gitee.com/huoyo/ko-time.git</developerConnection>
</scm>
<properties>
<aspecttj.version>1.9.9.1</aspecttj.version>
<tomcat.version>9.0.43</tomcat.version>
<spring-context.version>5.3.24</spring-context.version>
<spring-web.version>5.3.24</spring-web.version>
<spring-webmvc.version>5.3.24</spring-webmvc.version>
<spring-boot.version>2.7.4</spring-boot.version>
<spring-redis.version>2.6.2</spring-redis.version>
<spring-mail.version>2.7.3</spring-mail.version>
<tomcat.version>10.1.12</tomcat.version>
<spring-context.version>6.0.11</spring-context.version>
<spring-web.version>6.0.11</spring-web.version>
<spring-webmvc.version>6.0.11</spring-webmvc.version>
<spring-boot.version>3.1.3</spring-boot.version>
<spring-redis.version>3.1.3</spring-redis.version>
<spring-mail.version>3.1.3</spring-mail.version>
<fastjson.version>2.0.9</fastjson.version>
<oshi-core.version>6.2.2</oshi-core.version>
<byte-agent.version>1.12.13</byte-agent.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
@ -100,12 +106,14 @@
<version>${oshi-core.version}</version>
</dependency>
</dependencies>
<developers>
<developer>
<name>ZhangChang</name>
<email>1729913829@qq.com</email>
</developer>
</developers>
<build>
<plugins>
<plugin>
@ -113,8 +121,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
@ -175,6 +183,7 @@
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>snapshots</id>

View File

@ -2,6 +2,7 @@ package cn.langpy.kotime.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
/**
@ -9,43 +10,177 @@ import org.springframework.stereotype.Component;
*/
@Component
@ConfigurationProperties(prefix = "ko-time")
@Lazy(value = false)
public class DefaultConfig {
private Boolean enable;
private String language;
/**
* to enable kotime
*/
private Boolean enable = true;
/**
* to select language for viewer, chinese
*/
private String language = "chinese";
@Deprecated
private String logLanguage;
private Boolean logEnable;
private Boolean versionNotice;
private Double threshold;
private Double discardRate;
private String pointcut;
private Boolean exceptionEnable;
private Boolean paramAnalyse;
private String saver;
/**
* false
* to print log in console
*/
private Boolean logEnable = false;
/**
* "defaultValue": true,
* "description": "to enable version-notice",
*/
private Boolean versionNotice = true;
/**
* red will appear if avgRunTime>threshold
*/
private Double threshold = 800.0;
/**
* data will be discard if Math.random()<discard-rate
*/
private Double discardRate = 0.3;
/**
* pointcut for aop
* execution(* com.example..*.*(..))
*/
private String pointcut = "execution(* com.example..*.*(..))";
/**
* to enable exception listener
* "defaultValue": false,
*/
private Boolean exceptionEnable = false;
/**
* the charger of analysing params
*/
private Boolean paramAnalyse = true;
/**
* a place to store data
* memory
*/
private String saver = "memory";
/**
* datasource
*/
private String dataSource;
/**
* StringRedisTemplates bean
*/
private String redisTemplate;
private Integer threadNum;
private String contextPath;
/**
* number of thread to store data
*/
private Integer threadNum = 2;
/**
* server url for static resources
* http://localhost:8080
*/
private String contextPath = "";
/**
* dataPrefix
*/
private String dataPrefix;
private Boolean dataReset;
private Boolean authEnable;
/**
* to delete all data
*/
private Boolean dataReset = false;
/**
* to enable authentication
*/
private Boolean authEnable = false;
/**
* userName for authentication
*/
private String userName;
/**
* password for authentication
*/
private String password;
/**
* static token of html
*/
private String staticToken;
private Long authExpire;
/**
* expire within 43200 s
*/
private Long authExpire = 43200L;
private Boolean mailEnable;
private String mailHost;
private Integer mailPort;
private String mailProtocol;
private String mailEncoding;
/**
* to enable email
*/
private Boolean mailEnable = false;
/**
* host of email
*/
private String mailHost = "smtp.qq.com";
/**
* port of email
*/
private Integer mailPort = 587;
/**
* protocol of email
*/
private String mailProtocol = "smtp";
/**
* encoding of email
*/
private String mailEncoding = "UTF-8";
/**
* sender of email
*/
private String mailUser;
/**
* code of email
*/
private String mailCode;
/**
* receivers of email
*/
private String mailReceivers;
private Integer mailThreshold;
private String mailScope;
private String propertyFile;
/**
* trigger thresold of email
*/
private Integer mailThreshold = 4;
/**
* trigger scope of email
*/
private String mailScope = "Controller";
/**
* dynamic.properties
*/
private String propertyFile = "dynamic.properties";
public String getPropertyFile() {
return propertyFile;

View File

@ -0,0 +1,36 @@
package cn.langpy.kotime.config;
import cn.langpy.kotime.handler.RunTimeHandler;
import jakarta.annotation.Resource;
import org.springframework.aop.aspectj.AspectJExpressionPointcutAdvisor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.logging.Logger;
/**
* @author ccz
* @date 2024-7-5 03:16:56
*/
@Configuration
public class KoTimeConfig {
private static Logger log = Logger.getLogger(KoTimeConfig.class.toString());
@Value("${koTime.pointcut:execution(* cn.langpy.kotime.controller.KoTimeController.*(..))}")
private String pointcut;
@Resource
private DefaultConfig defaultConfig;
@Bean
public AspectJExpressionPointcutAdvisor configurabledvisor() {
log.info("kotime=>loading method listener");
AspectJExpressionPointcutAdvisor advisor = new AspectJExpressionPointcutAdvisor();
String cutRange = defaultConfig.getPointcut() == null ? pointcut : defaultConfig.getPointcut();
cutRange = cutRange + " && !@annotation(cn.langpy.kotime.annotation.KoListener)";
advisor.setExpression(cutRange);
advisor.setAdvice(new RunTimeHandler());
return advisor;
}
}

View File

@ -0,0 +1,23 @@
package cn.langpy.kotime.config;
import jakarta.annotation.Resource;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
/**
* @author ccz
* @date 2024-7-5 03:17:13
*/
@ComponentScan("cn.langpy.kotime")
@AutoConfiguration
public class KoTimeRunner implements ApplicationRunner {
@Resource
private LoadConfig loadConfig;
@Override
public void run(ApplicationArguments args) throws Exception {
loadConfig.initConfig();
}
}

View File

@ -1,30 +1,27 @@
package cn.langpy.kotime.config;
import cn.langpy.kotime.annotation.KoListener;
import cn.langpy.kotime.handler.RunTimeHandler;
import cn.langpy.kotime.handler.InvokedHandler;
import cn.langpy.kotime.service.GraphService;
import cn.langpy.kotime.service.InvokedQueue;
import cn.langpy.kotime.util.Common;
import cn.langpy.kotime.util.Context;
import cn.langpy.kotime.util.DataBaseException;
import org.springframework.aop.aspectj.AspectJExpressionPointcutAdvisor;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.sql.DataSource;
import java.io.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Map;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@ -32,8 +29,7 @@ import java.util.stream.Collectors;
/**
* zhangchang
*/
@ComponentScan("cn.langpy.kotime")
@Configuration
@Component
public class LoadConfig {
private static Logger log = Logger.getLogger(LoadConfig.class.toString());
@ -56,7 +52,6 @@ public class LoadConfig {
@Value("${server.servlet.context-path:}")
private String serverContext;
@Value("${ko-time.mail-enable:false}")
private Boolean mailEnable;
@ -65,8 +60,6 @@ public class LoadConfig {
@Resource
private ApplicationContext applicationContext;
@PostConstruct
public void initConfig() {
DefaultConfig config = improveConfig();
@ -215,15 +208,4 @@ public class LoadConfig {
}
}
@Bean
public AspectJExpressionPointcutAdvisor configurabledvisor() {
log.info("kotime=>loading method listener");
AspectJExpressionPointcutAdvisor advisor = new AspectJExpressionPointcutAdvisor();
String cutRange = defaultConfig.getPointcut() == null ? pointcut : defaultConfig.getPointcut();
cutRange = cutRange + " && !@annotation(cn.langpy.kotime.annotation.KoListener)";
advisor.setExpression(cutRange);
advisor.setAdvice(new RunTimeHandler());
return advisor;
}
}

View File

@ -11,6 +11,8 @@ import cn.langpy.kotime.service.ThreadUsageService;
import cn.langpy.kotime.util.Context;
import cn.langpy.kotime.util.InvalidAuthInfoException;
import cn.langpy.kotime.util.KoUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Controller;
@ -18,8 +20,6 @@ import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.*;
import java.util.logging.Logger;
@ -44,6 +44,7 @@ public class KoTimeController {
private final String metricFlowJsText = getResourceText("kostatic/Metricflow.js");
private final String jQueryJsText = getResourceText("kostatic/JQuery.min.js");
private final String uiKitIconsJs = getResourceText("kostatic/uikit-icons.js");
private final String KoTimeUtil = getResourceText("kostatic/util.js");
@PostMapping("/login")
@ResponseBody
@ -81,7 +82,7 @@ public class KoTimeController {
@GetMapping
public void index(String kotoken, String test,String charset, String language,HttpServletResponse response, HttpServletRequest request) {
public void index(String kotoken, String test, String charset, String language, HttpServletResponse response, HttpServletRequest request) {
if (!Context.getConfig().getEnable()) {
return;
}
@ -95,7 +96,7 @@ public class KoTimeController {
if (!StringUtils.hasText(charset)) {
charset = "utf-8";
}
response.setContentType("text/html;charset="+charset);
response.setContentType("text/html;charset=" + charset);
ClassPathResource classPathResource = new ClassPathResource(KoConstant.getViewName(language));
try (
InputStream inputStream = classPathResource.getInputStream();
@ -132,6 +133,8 @@ public class KoTimeController {
line = line.replace("staticTokenVisitValue", staticTokenVisit + "");
} else if (line.indexOf("staticTokenValue") > -1) {
line = line.replace("staticTokenValue", "'" + kotoken + "'");
} else if (line.indexOf("KoTimeUtil") > -1) {
line = line.replace("KoTimeUtil", KoTimeUtil);
}
stringBuilder.append(line + "\n");
}
@ -377,7 +380,7 @@ public class KoTimeController {
threads = threads.stream().sorted(COMPARATOR).collect(Collectors.toList());
Map<String, Long> stateCounting = threads.stream().collect(Collectors.groupingBy(ThreadInfo::getState, Collectors.counting()));
stateCounting.put("all",(long)threads.size());
stateCounting.put("all", (long) threads.size());
Map map = new HashMap();
map.put("statistics", stateCounting);
@ -399,17 +402,17 @@ public class KoTimeController {
Properties dynamicProperties = Context.getDynamicProperties();
for (String line : textSplit) {
line = line.trim();
if (line.length()==0 || line.startsWith("#") || line.startsWith("//")) {
if (line.length() == 0 || line.startsWith("#") || line.startsWith("//")) {
continue;
}
int i = line.indexOf("=");
if (i<1) {
if (i < 1) {
continue;
}
String propertyStr = line.substring(0, i).trim();
String valueStr = line.substring(i+1).trim();
log.info("updated property: "+propertyStr+"=("+dynamicProperties.get(propertyStr)+"->"+valueStr+")");
dynamicProperties.setProperty(propertyStr,valueStr);
String valueStr = line.substring(i + 1).trim();
log.info("updated property: " + propertyStr + "=(" + dynamicProperties.get(propertyStr) + "->" + valueStr + ")");
dynamicProperties.setProperty(propertyStr, valueStr);
}
return true;
@ -426,8 +429,8 @@ public class KoTimeController {
StringBuilder stringBuilder = new StringBuilder();
for (String key : dynamicProperties.stringPropertyNames()) {
String value = dynamicProperties.getProperty(key);
if (value!=null) {
stringBuilder.append(key+"="+value+"\n");
if (value != null) {
stringBuilder.append(key + "=" + value + "\n");
}
}
map.put("data", stringBuilder.toString());

View File

@ -0,0 +1 @@
cn.langpy.kotime.config.KoTimeRunner

View File

@ -0,0 +1,10 @@
function getSize(size) {
let sizes = [' Bytes', ' KB', ' MB', ' GB',
' TB', ' PB', ' EB', ' ZB', ' YB'];
for (let i = 1; i < sizes.length; i++) {
if (size < Math.pow(1024, i))
return (Math.round((size / Math.pow(1024, i - 1)) * 100) / 100) + sizes[i - 1];
}
return size;
}

File diff suppressed because it is too large Load Diff