Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
# Javaagent
## 概述
javaagent是一个简单优雅的java agent,利用java自带的instrument特性+javassist字节码编辑技术,实现了无侵入的方法级性能监控。相比于NewRelic或者开源的[pinpoint](https://github.com/naver/pinpoint),本工具主打的是简单,我们只记录每个方法的执行次数和时间,并输出到日志。基于javaagent的日志,你可以使用[JQL](https://github.com/dingjs/javaagent/tree/master/resources/JQL)工具进行分析查询,也可以自己去写分析器,这样可以让你快速定位生产环境的性能瓶颈。
javaagent是一个简单优雅的java agent,利用java自带的instrument特性+javassist字节码编辑技术,实现了无侵入的方法级性能监控。相比于NewRelic或者开源的[pinpoint](https://github.com/naver/pinpoint),以及阿里的[arthas](https://github.com/alibaba/arthas),本工具主打的是简单,我们只记录每个方法的执行次数和时间,并输出到json格式的日志文件中。基于javaagent的日志,你可以使用严丽同学开发的[agent日志分析工具](https://pan.baidu.com/s/1Ma4iEWRmBonGO1TapeEF-g)进行分析查询,也可以自己去写分析器,这样可以让你快速定位生产环境的性能瓶颈。

## 集成
java启动参数中就有jaaagent,你只需要在JAVA_OPTS中加入`-javaagent:/opt/javaagent/javaagent.jar=/opt/javaagent/agent.properties`就实现了方法级监控。其中`=`前指定的是jar包的路径,`=`后指定的是对agent的一些配置参数。

### agent.properties说明
```
# 你想监控哪些包,多个包用分号分隔,凡是不在该配置里的包中类都不会监控,所以不会去默认监控各种第三方包以及jre自带的类
agent.include.package=com.thunisoft
# 你不想监控的包,多个包用分号分隔,include.package减去exclude.package就是你监控的包
# 需要监控的包,多个包用分号分隔
agent.include.package=com.XXX
# 不需要监控的包,多个包用分号分隔。 需要监控的包-不需要监控的包就是真正要监控的包
agent.exclude.package=
# 你不想监控的包的正则
agent.exclude.class.regex=
# 日志文件路径,会自动带上日期
agent.log.file=/opt/logs/agent.log
# 你希望多长时间输出一次日志,以秒为单位,建议生产环境配置600或者1200
# 日志文件,会自动增加日期后缀
agent.log.file=d\:\\agent.log
# 日志输出周期
agent.log.interval.seconds=600
# 你是否需要计算平均时间,对于生产环境,建议配成false,通过JQL查询时会进行计算
# 不需要监控的类的正则表达式
agent.exclude.class.regex=
# 是否记录平均时间
agent.log.avg.execute.time=false
# 是否监控pojo的get set方法,如果不开启的话,则不监控,避免出现大量pojo相关的日志。
agent.pojo.monitor.open=false
# 默认不需要监控的类的正则表达式
agent.exclude.class.regex.default=.*EnhancerByCGLIB.*;.*FastClassByCGLIB.*
# 记录方法的耗时时是采用nanoTime,还是currentTimeMillis,nanoTime更准确,但是会耗时一些
agent.log.nano=true
```
### JQL
JQL是用金雷同学用python写的一个agent日志分析工具,你可以用这个工具做查询、排序、limit等。详细用法,请参考[JQL完全指南](https://github.com/dingjs/javaagent/tree/master/resources/JQL)。

![JQL截图](https://github.com/dingjs/javaagent/blob/master/resources/images/JQL.png?raw=true)


30 changes: 0 additions & 30 deletions README_en_US.md

This file was deleted.

20 changes: 3 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.dingjsh</groupId>
<groupId>com.wenshuo</groupId>
<artifactId>javaagent</artifactId>
<version>1.2.0</version>
<version>2.1.0</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.target>1.6</project.build.target>
</properties>
<organization>
<name>BeiJing Thunisoft Corporation Limited</name>
<url>http://www.thunisoft.com</url>
</organization>
<developers>
<developer>
<id>dingjsh</id>
Expand All @@ -29,16 +25,6 @@
<distribution>repo</distribution>
</license>
</licenses>
<distributionManagement>
<repository>
<id>public-repo</id>
<url>http://repo.thunisoft.com/maven2/content/repositories/cmptreleases/</url>
</repository>
<snapshotRepository>
<id>public-snapshots</id>
<url>http://repo.thunisoft.com/maven2/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>

<build>
<sourceDirectory>src</sourceDirectory>
Expand Down Expand Up @@ -74,7 +60,7 @@
<configuration>
<archive>
<manifestEntries>
<premain-class>com.thunisoft.agent.Agent</premain-class>
<premain-class>com.wenshuo.agent.Agent</premain-class>
</manifestEntries>
</archive>
</configuration>
Expand Down
Loading