Skip to content

Commit f413bd8

Browse files
authored
Merge pull request #12 from fanzhongwei/master
feat:添加方法执行时间百分比统计,与JMeter性能报告统计方式一致
2 parents aa1cea6 + 0a81b6a commit f413bd8

File tree

380 files changed

+4332
-80
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

380 files changed

+4332
-80
lines changed

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@
77
*.jar
88
*.war
99
*.ear
10-
javaagent.iml
10+
*.iml
1111

1212
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
1313
hs_err_pid*
1414
target/maven-archiver/pom.properties
1515
*.prefs
1616
*.project
1717
.classpath
18-
/target
18+
target
1919
/.settings
20-
/.idea
20+
.idea
2121
*.log
22+
dependency-reduced-pom.xml
2223

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ agent.exclude.class.regex=
2121
agent.log.avg.execute.time=false
2222
# 记录方法的耗时时是采用nanoTime,还是currentTimeMillis,nanoTime更准确,但是会耗时一些
2323
agent.log.nano=true
24+
# 是否统计方法执行时间百分比,同JMeter性能测试百分比计算方式,如果开启默认会统计最大值、最小值
25+
agent.log.stat.execute.time=false
26+
# 方法执行时间统计百分比(agent.log.stat.execute.time=true时有效),多选范围[0, 1],例如:0.5,0.9,0.95,0.99
27+
agent.log.stat.execute.time.pct=0.5,0.9,0.95,0.99
2428
```
2529

2630
## agent日志分析器使用

agent-analyer/bin/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# agent-analyzer启动教程
2+
3+
## 启动服务
4+
5+
启动 agent-analyzer 有以下两种方式,请使用提供的脚本(`run.sh`)启动程序
6+
7+
### 使用 `run.sh` 启动程序
8+
9+
请使用如下命令启动服务:`sh run.sh [port] [jmx-port]`
10+
11+
+ `port` 为访问 UIM API 的端口,如果不指定的话,默认为 **80**
12+
+ `jmx-port` 为 JMX 远程监控端口。如果不指定的话,不会开启
13+
14+
15+
## 验证启动是否成功
16+
17+
在运行 shell 脚本后,静候一小段时间,在浏览器中键入以下地址,即可查看是否启动成功:
18+
19+
`http://ip:port/`
20+
21+
22+
## 停止服务
23+
24+
使用如下脚本停止服务,这样会停止所有的 `agent-analyzer` 服务。
25+
26+
```bash
27+
sh stop.sh
28+
```

agent-analyer/bin/run.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
DIR1="`dirname $BASH_SOURCE`"
3+
CURRENT_PATH=`readlink -f "$DIR1"`
4+
5+
APP_NAME="agent-analyzer.jar"
6+
7+
APP_PORT=8080
8+
if [ -z "$1" ]
9+
then
10+
echo "没有指定程序端口,将使用默认端口 ${APP_PORT}"
11+
else
12+
APP_PORT=$1
13+
fi
14+
15+
16+
echo "尝试获取本机 ip 地址"
17+
IP_ADDR='127.0.0.1'
18+
IP_ADDR=$(ip addr | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/, "\\1", "g", $2)}')
19+
echo "成功获取本机 ip 地址: $IP_ADDR"
20+
21+
JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx2g -Xmn256m"
22+
JAVA_OPT="${JAVA_OPT} -XX:+UseG1GC"
23+
JAVA_OPT="${JAVA_OPT} -XX:+HeapDumpOnOutOfMemoryError"
24+
if [ -z "$2" ]
25+
then
26+
echo "没有指定 JMX 远程端口,将无法进行远程监控"
27+
else
28+
JAVA_OPT="${JAVA_OPT} -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=${2} -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostn
29+
ame=${IP_ADDR}"
30+
fi
31+
32+
echo "程序运行参数为:${JAVA_OPT}"
33+
echo "程序运行端口为:${APP_PORT}"
34+
35+
nohup java ${JAVA_OPT} -jar ${CURRENT_PATH}/${APP_NAME} --server.port=$APP_PORT > nohup_${APP_PORT}.out 2>&1 &
36+

agent-analyer/bin/stop.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
# add comment
3+
if [ -z "$1" ]
4+
then
5+
pid=`ps ax |grep -i 'agent-analyzer.jar' |grep java | grep -v grep | awk '{print $1}'`
6+
else
7+
pid=`ps ax |grep -i 'agent-analyzer.jar' |grep java | grep -i 'server.port='''${1}''''| grep -v grep | awk '{print $1}'`
8+
fi
9+
10+
if [ -z "$pid" ] ; then
11+
echo "agent-analyzer is not running."
12+
exit 0;
13+
fi
14+
echo "agent-analyzer(${pid}) is running."
15+
echo "Send shutdown request to agent-analyzer(${pid})....."
16+
kill -9 ${pid}
17+
echo "Shutdown agent-analyzer(${pid}) success."
18+

agent-analyer/pom.xml

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.wenshuo</groupId>
6+
<artifactId>agent-analyzer</artifactId>
7+
<version>1.0.0</version>
8+
<packaging>jar</packaging>
9+
10+
<name>agent日志分析器</name>
11+
12+
<properties>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
<java.version>1.8</java.version>
15+
<springboot.version>2.6.7</springboot.version>
16+
<fastjson.version>1.2.83</fastjson.version>
17+
<commons-io.version>2.15.1</commons-io.version>
18+
</properties>
19+
20+
<dependencyManagement>
21+
<dependencies>
22+
<dependency>
23+
<!-- Import dependency management from Spring Boot -->
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-dependencies</artifactId>
26+
<version>${springboot.version}</version>
27+
<type>pom</type>
28+
<scope>import</scope>
29+
</dependency>
30+
</dependencies>
31+
</dependencyManagement>
32+
33+
<dependencies>
34+
<dependency>
35+
<groupId>org.projectlombok</groupId>
36+
<artifactId>lombok</artifactId>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.springframework.boot</groupId>
40+
<artifactId>spring-boot-starter-web</artifactId>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.apache.commons</groupId>
44+
<artifactId>commons-lang3</artifactId>
45+
</dependency>
46+
47+
<!-- <dependency>-->
48+
<!-- <groupId>net.sourceforge.cglib</groupId>-->
49+
<!-- <artifactId>com.springsource.net.sf.cglib</artifactId>-->
50+
<!-- <version>2.2.0</version>-->
51+
<!-- </dependency>-->
52+
<!-- 格式化对象,方便输出日志 -->
53+
<dependency>
54+
<groupId>com.alibaba</groupId>
55+
<artifactId>fastjson</artifactId>
56+
<version>${fastjson.version}</version>
57+
</dependency>
58+
<!-- spring data jpa -->
59+
<dependency>
60+
<groupId>org.springframework.boot</groupId>
61+
<artifactId>spring-boot-starter-data-jpa</artifactId>
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>com.h2database</groupId>
66+
<artifactId>h2</artifactId>
67+
<scope>runtime</scope>
68+
</dependency>
69+
70+
<dependency>
71+
<groupId>commons-io</groupId>
72+
<artifactId>commons-io</artifactId>
73+
<version>${commons-io.version}</version>
74+
</dependency>
75+
<dependency>
76+
<groupId>commons-logging</groupId>
77+
<artifactId>commons-logging</artifactId>
78+
<version>1.2</version>
79+
<scope>compile</scope>
80+
</dependency>
81+
</dependencies>
82+
83+
<build>
84+
<finalName>agent-analyzer</finalName>
85+
<resources>
86+
<resource>
87+
<directory>src/main/java</directory>
88+
<includes>
89+
<include>**/*.xml</include>
90+
</includes>
91+
</resource>
92+
<resource>
93+
<directory>${basedir}/src/main/webapp</directory>
94+
<targetPath>META-INF/resources</targetPath>
95+
<includes>
96+
<include>**/**</include>
97+
</includes>
98+
</resource>
99+
<resource>
100+
<directory>src/main/resources</directory>
101+
<filtering>false</filtering>
102+
<excludes>
103+
<exclude>.gitkeep</exclude>
104+
</excludes>
105+
<includes>
106+
<include>**</include>
107+
</includes>
108+
</resource>
109+
</resources>
110+
<plugins>
111+
<plugin>
112+
<groupId>org.apache.maven.plugins</groupId>
113+
<artifactId>maven-compiler-plugin</artifactId>
114+
<version>3.8.1</version>
115+
<configuration>
116+
<source>${java.version}</source>
117+
<target>${java.version}</target>
118+
</configuration>
119+
</plugin>
120+
<plugin>
121+
<groupId>org.springframework.boot</groupId>
122+
<artifactId>spring-boot-maven-plugin</artifactId>
123+
<version>${springboot.version}</version>
124+
<executions>
125+
<execution>
126+
<goals>
127+
<goal>repackage</goal>
128+
</goals>
129+
</execution>
130+
</executions>
131+
<configuration>
132+
<mainClass>com.wenshuo.agent.analyzer.AgentAnalyzer</mainClass>
133+
<fork>true</fork>
134+
</configuration>
135+
</plugin>
136+
</plugins>
137+
</build>
138+
</project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.wenshuo.agent.analyzer;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
/**
7+
* agent日志分析
8+
*
9+
* @date 2024/09/06 13:52
10+
**/
11+
@SpringBootApplication
12+
13+
public class AgentAnalyzer {
14+
public static void main(String[] args) {
15+
SpringApplication.run(AgentAnalyzer.class, args);
16+
}
17+
18+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.wenshuo.agent.analyzer.bean;
2+
3+
import com.alibaba.fastjson.annotation.JSONField;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
import java.util.Date;
9+
import java.util.UUID;
10+
import javax.persistence.Entity;
11+
import javax.persistence.GeneratedValue;
12+
import javax.persistence.Id;
13+
import javax.persistence.Table;
14+
15+
/**
16+
* @date 2024/09/06 14:05
17+
**/
18+
@Entity
19+
@Table(name = "T_AGENT_LOG")
20+
@Data
21+
@NoArgsConstructor
22+
@AllArgsConstructor
23+
public class AgentLogDO {
24+
25+
@Id
26+
@GeneratedValue
27+
private UUID id;
28+
29+
private Date startTime;
30+
31+
private Date endTime;
32+
33+
@JSONField(name = "class")
34+
private String className;
35+
36+
private String methodName;
37+
38+
private Long counter;
39+
40+
private Long time;
41+
42+
private Long avg;
43+
44+
private Long min;
45+
46+
private Long max;
47+
48+
private Long median;
49+
50+
private Long th90Pct;
51+
52+
private Long th95Pct;
53+
54+
private Long th99Pct;
55+
56+
private String version;
57+
58+
private String day;
59+
60+
private String startAndEnd;
61+
62+
private String fileName;
63+
64+
private String timeCut;
65+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.wenshuo.agent.analyzer.bean;
2+
3+
import com.alibaba.fastjson.annotation.JSONField;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
import java.util.Date;
9+
10+
/**
11+
* @date 2024/09/06 14:09
12+
**/
13+
@Data
14+
@NoArgsConstructor
15+
@AllArgsConstructor
16+
public class ClassBean {
17+
18+
private String bh;
19+
20+
private Date startTime;
21+
22+
private String start;
23+
24+
private Date endTime;
25+
26+
private String end;
27+
28+
@JSONField(name = "class")
29+
private String className;
30+
31+
@JSONField(name = "methods")
32+
private String methods;
33+
34+
private String version;
35+
36+
private String day;
37+
38+
private String startAndEnd;
39+
}

0 commit comments

Comments
 (0)