Skip to content

Commit

Permalink
Merge pull request #27 from qunarcorp/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
xleiy authored Aug 29, 2019
2 parents 09090b2 + d649f54 commit 28bcfa2
Show file tree
Hide file tree
Showing 53 changed files with 421 additions and 114 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Bistoury提供可视化页面实时查看机器和应用的各种信息,包括

## java版本要求

jdk1.8+
ui、proxy使用Java1.8,agent使用java1.7或java1.8,由于agent会attach到应用中,所以应用也需要使用Java1.7或Java1.8。Java9及后续版本由于改动较大,会在以后陆续支持。

## 系统要求

Expand All @@ -57,10 +57,6 @@ jdk1.8+

## Q & A

- jdk版本要求为1.8,但是代码实现很多是1.7

公司内部使用1.7的jdk,开源版本并没有完全改过来,1.7的代码后续会逐渐修改为1.8的实现。

- 前端有的地方似乎有点不那么好看,实现的似乎也不太棒

所有的前端代码都是后端同学兼职完成,欢迎各位前端大牛贡献相关代码。
Expand Down
2 changes: 1 addition & 1 deletion bistoury-agent-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>bistoury</artifactId>
<groupId>qunar.tc.bistoury</groupId>
<version>2.0.2</version>
<version>2.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import qunar.tc.bistoury.agent.common.pid.impl.PidByPsHandler;
import qunar.tc.bistoury.agent.common.pid.impl.PidBySystemPropertyHandler;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.ServiceLoader;
Expand Down Expand Up @@ -54,8 +55,16 @@ private static List<PidHandler> initPidHandler() {
handlers.add(new PidByPsHandler());
}

ServiceLoader.load(PidHandlerFactory.class).forEach(factory -> handlers.add(factory.create()));
handlers.sort(Comparator.comparingInt(PidHandler::priority));
ServiceLoader<PidHandlerFactory> handlerFactories = ServiceLoader.load(PidHandlerFactory.class);
for (PidHandlerFactory factory : handlerFactories) {
handlers.add(factory.create());
}
Collections.sort(handlers, new Comparator<PidHandler>() {
@Override
public int compare(PidHandler o1, PidHandler o2) {
return o1.priority() - o2.priority();
}
});
return ImmutableList.copyOf(handlers);
}

Expand Down
2 changes: 1 addition & 1 deletion bistoury-agent-task/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>bistoury</artifactId>
<groupId>qunar.tc.bistoury</groupId>
<version>2.0.2</version>
<version>2.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion bistoury-agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>bistoury</artifactId>
<groupId>qunar.tc.bistoury</groupId>
<version>2.0.2</version>
<version>2.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
15 changes: 13 additions & 2 deletions bistoury-application/bistoury-application-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@
<parent>
<artifactId>bistoury-application</artifactId>
<groupId>qunar.tc.bistoury</groupId>
<version>2.0.2</version>
<version>2.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>bistoury-application-api</artifactId>


<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
91 changes: 51 additions & 40 deletions bistoury-application/bistoury-application-mysql/pom.xml
Original file line number Diff line number Diff line change
@@ -1,46 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>bistoury-application</artifactId>
<groupId>qunar.tc.bistoury</groupId>
<version>2.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>bistoury-application</artifactId>
<groupId>qunar.tc.bistoury</groupId>
<version>2.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>bistoury-application-mysql</artifactId>
<artifactId>bistoury-application-mysql</artifactId>

<dependencies>
<dependency>
<groupId>qunar.tc.bistoury</groupId>
<artifactId>bistoury-application-api</artifactId>
</dependency>
<dependency>
<groupId>qunar.tc.bistoury</groupId>
<artifactId>bistoury-common</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>qunar.tc.bistoury</groupId>
<artifactId>bistoury-application-api</artifactId>
</dependency>
<dependency>
<groupId>qunar.tc.bistoury</groupId>
<artifactId>bistoury-common</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
public class ApplicationUserDaoImpl implements ApplicationUserDao {
private static final String SELECT_APP_BY_USER_CODE = "select app_code from bistoury_user_app where user_code=?";

private static final String ADD_USER_FOR_APP = "insert ignore bistoury_user_app (app_code, user_code) values (?, ?)";
private static final String ADD_USER_FOR_APP = "insert ignore into bistoury_user_app (app_code, user_code) values (?, ?)";

private static final String REMOVE_USER_FROM_APP = "delete from bistoury_user_app where user_code = ? and app_code = ?";

Expand Down
15 changes: 13 additions & 2 deletions bistoury-application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>bistoury</artifactId>
<groupId>qunar.tc.bistoury</groupId>
<version>2.0.2</version>
<version>2.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -20,5 +20,16 @@
<module>bistoury-application-api</module>
<module>bistoury-application-mysql</module>
</modules>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
2 changes: 1 addition & 1 deletion bistoury-attach-arthas/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>bistoury</artifactId>
<groupId>qunar.tc.bistoury</groupId>
<version>2.0.2</version>
<version>2.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import com.taobao.middleware.logger.Logger;
import qunar.tc.bistoury.common.NamedThreadFactory;

import java.util.*;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -65,7 +68,13 @@ public Job createJob(InternalCommandManager commandManager, List<CliToken> token
/*
* 达到超时时间将会停止job
*/
ScheduledFuture<?> timoutTaskFuture = timeoutExecutor.schedule(job::terminate, getJobTimeoutInSecond(), TimeUnit.SECONDS);
ScheduledFuture<?> timoutTaskFuture = timeoutExecutor.schedule(new Runnable() {
@Override
public void run() {
job.terminate();
}
}, getJobTimeoutInSecond(), TimeUnit.SECONDS);

jobTimeoutTaskMap.put(job.id(), timoutTaskFuture);
Date timeoutDate = new Date(System.currentTimeMillis() + (getJobTimeoutInSecond() * 1000));
job.setTimeoutDate(timeoutDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ public class JarDebugClient implements InstrumentClient {

private static final String FILE_PROTOCOL = "file:";

private final Map<String, ClassInfo> class_classInfo;
private Map<String, ClassInfo> class_classInfo = Maps.newHashMap();

private InstrumentInfo instrumentInfo;

JarDebugClient(InstrumentInfo instrumentInfo) {
this.instrumentInfo = instrumentInfo;
logger.info("start init jar debugg client");
try {
class_classInfo = initAllClassInfo(instrumentInfo);
class_classInfo = initAllClassInfo(instrumentInfo, true);
logger.info("success init jar decompiler client");
} catch (Exception e) {
destroy();
Expand All @@ -65,9 +68,14 @@ public class JarDebugClient implements InstrumentClient {
}
}

private Map<String, ClassInfo> initAllClassInfo(InstrumentInfo instrumentInfo) {
private Map<String, ClassInfo> initAllClassInfo(InstrumentInfo instrumentInfo, boolean isLoadAll) {
Class[] loadedClasses = instrumentInfo.getInstrumentation().getAllLoadedClasses();
Map<String, ClassInfo> classInfoMap = Maps.newHashMap();
Map<String, ClassInfo> classInfoMap;
if (isLoadAll) {
classInfoMap = Maps.newHashMap();
} else {
classInfoMap = Maps.newHashMap(class_classInfo);
}
Map<String, JarFile> jarFileMap = new HashMap<>();
Map<String, Optional<Properties>> mavenInfoMap = new HashMap<>();
try {
Expand All @@ -76,6 +84,11 @@ private Map<String, ClassInfo> initAllClassInfo(InstrumentInfo instrumentInfo) {
if (Strings.isNullOrEmpty(clazzName) || clazzName.startsWith("[") || clazzName.indexOf("$") >= 0) {
continue;
}

if (!isLoadAll && classInfoMap.containsKey(clazzName)) {
continue;
}

final ClassLoader classLoader = clazz.getClassLoader();
if (classLoader == null || InstrumentInfo.IGNORE_CLASS.contains(classLoader.getClass().getName())) {
continue;
Expand All @@ -101,6 +114,33 @@ public Set<String> getAllClass() {
return ImmutableSet.copyOf(class_classInfo.keySet());
}

/**
* 所有类全部重新加载
*
* @return
*/
public boolean reloadAllClass() {
logger.info("begin reload all class");
Map<String, ClassInfo> tmpClassInfo = initAllClassInfo(instrumentInfo, true);
class_classInfo = tmpClassInfo;
logger.info("end reload all class");
return true;
}

/**
* 只加载没有加载的类
*
* @return
*/
public boolean reLoadNewClass() {
logger.info("begin reload new class");
Map<String, ClassInfo> tmpClassInfo = initAllClassInfo(instrumentInfo, false);
class_classInfo = tmpClassInfo;
logger.info("end reload new class");
return true;
}


public ClassInfo getClassPath(final String className) {
return class_classInfo.get(className);
}
Expand Down
Loading

0 comments on commit 28bcfa2

Please sign in to comment.