Skip to content

Commit 8278398

Browse files
authored
在线debug和动态监控支持Spring boot项目
Dev
2 parents b8229b1 + 8fa5773 commit 8278398

File tree

10 files changed

+83
-27
lines changed

10 files changed

+83
-27
lines changed

bistoury-attach-arthas/src/main/java/qunar/tc/bistoury/attach/arthas/instrument/InstrumentClientStore.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,34 +70,36 @@ public static synchronized void init(Instrumentation instrumentation) {
7070

7171
ImmutableList.Builder<InstrumentClient> builder = new ImmutableList.Builder<>();
7272

73+
//jar debug放在最前面,因为在里面会对jar包启动的项目进行解压
7374
try {
74-
builder.add(QDebugClients.create(instrumentInfo));
75+
builder.add(JarDebugClients.create(instrumentInfo));
7576
} catch (Exception e) {
76-
logger.error("", "qdebug client init error", e);
77+
logger.error("", "jar decompiler init error", e);
7778
}
79+
7880
try {
79-
builder.add(QMonitorClients.create(instrumentInfo));
81+
builder.add(AppConfigClients.create(instrumentInfo));
8082
} catch (Exception e) {
81-
logger.error("", "qmonitor client init error", e);
83+
logger.error("", "app config client init error", e);
8284
}
8385

8486
try {
85-
builder.add(JarInfoClients.create(instrumentInfo));
87+
builder.add(QDebugClients.create(instrumentInfo));
8688
} catch (Exception e) {
87-
logger.error("", "jar info client init error", e);
89+
logger.error("", "qdebug client init error", e);
8890
}
89-
9091
try {
91-
builder.add(AppConfigClients.create(instrumentInfo));
92+
builder.add(QMonitorClients.create(instrumentInfo));
9293
} catch (Exception e) {
93-
logger.error("", "app config client init error", e);
94+
logger.error("", "qmonitor client init error", e);
9495
}
9596

9697
try {
97-
builder.add(JarDebugClients.create(instrumentInfo));
98+
builder.add(JarInfoClients.create(instrumentInfo));
9899
} catch (Exception e) {
99-
logger.error("", "jar decompiler init error", e);
100+
logger.error("", "jar info client init error", e);
100101
}
102+
101103
clients = builder.build();
102104
}
103105

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (C) 2019 Qunar, Inc.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package qunar.tc.bistoury.attach.file;
19+
20+
import qunar.tc.bistoury.clientside.common.store.BistouryStore;
21+
22+
import java.io.File;
23+
24+
/**
25+
* @author leix.xie
26+
* @date 2019/8/24 01:27
27+
* @describe
28+
*/
29+
public class JarStorePathUtil {
30+
31+
private static final String STORE_PATH = BistouryStore.getStorePath("tomcat_webapp");
32+
33+
static {
34+
File file = new File(STORE_PATH);
35+
if (!file.exists() || !file.isDirectory()) {
36+
file.mkdirs();
37+
}
38+
}
39+
40+
public static String getJarStorePath() {
41+
return new File(STORE_PATH).getPath();
42+
}
43+
44+
public static String getJarLibPath() {
45+
return System.getProperty("bistoury.jar.lib.path", new File(getJarStorePath(), "BOOT-INF/lib/").getPath());
46+
}
47+
48+
public static String getJarSourcePath() {
49+
return System.getProperty("bistoury.jar.source.path", new File(getJarStorePath(), "BOOT-INF/classes/").getPath());
50+
}
51+
}

bistoury-attach-common/src/main/java/qunar/tc/bistoury/attach/file/impl/JarFileServiceWrapper.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import com.google.common.io.Files;
2222
import com.taobao.middleware.logger.Logger;
2323
import qunar.tc.bistoury.attach.common.BistouryLoggger;
24+
import qunar.tc.bistoury.attach.file.JarStorePathUtil;
2425
import qunar.tc.bistoury.attach.file.URLUtil;
25-
import qunar.tc.bistoury.clientside.common.store.BistouryStore;
2626

2727
import java.io.File;
2828
import java.io.InputStream;
@@ -40,15 +40,10 @@ public class JarFileServiceWrapper {
4040

4141
private static final Logger logger = BistouryLoggger.getLogger();
4242

43-
private static final String STORE_PATH = BistouryStore.getStorePath("tomcat_webapp");
44-
4543
private static final AtomicBoolean STARTED = new AtomicBoolean(false);
4644

4745
public JarFileServiceWrapper() {
48-
File file = new File(STORE_PATH);
49-
if (!file.exists() || !file.isDirectory()) {
50-
file.mkdirs();
51-
}
46+
5247
}
5348

5449
/**
@@ -58,8 +53,7 @@ public JarFileServiceWrapper() {
5853
* @return
5954
*/
6055
public String getJarPath(final String jarFile) {
61-
final String jarFilePath = jarFile.substring(jarFile.lastIndexOf(File.separatorChar) + 1).replace(".jar", "");
62-
File file = new File(STORE_PATH, jarFilePath);
56+
File file = new File(JarStorePathUtil.getJarStorePath());
6357
if (!file.exists() || !file.isDirectory() || !STARTED.get()) {
6458
deleteDirectory(file);
6559
unPackJar(jarFile, file);

bistoury-dist/bin/bistoury-agent.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ if [[ -n $APP_PID ]]; then
4141
fi
4242

4343
CLASSPATH="$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/sa-jdi.jar"
44-
JAVA_OPTS="$JAVA_OPTS -Dbistoury.app.lib.class=$BISTOURY_APP_LIB_CLASS -Xmx80m -Xmn50m -XX:+UseParallelGC -XX:+UseParallelOldGC -XX:+UseCodeCacheFlushing -Xloggc:${BISTOURY_LOG_DIR}/bistoury-gc-${TIMESTAMP}.log -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${BISTOURY_LOG_DIR}"
44+
JAVA_OPTS="$JAVA_OPTS -Dbistoury.app.lib.class=$BISTOURY_APP_LIB_CLASS -Xmx80m -Xmn50m -XX:+UseParallelGC -XX:+UseParallelOldGC -XX:+UseCodeCacheFlushing -Xloggc:${BISTOURY_LOG_DIR}/bistoury-gc-${TIMESTAMP}.log -XX:+PrintGC -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${BISTOURY_LOG_DIR}"
4545
BISTOURY_PID_FILE="$BISTOURY_PID_DIR/bistoury-agent.pid"
4646
BISTOURY_DAEMON_OUT="$BISTOURY_LOG_DIR/bistoury-agent.out"
4747

bistoury-instrument-client/src/main/java/qunar/tc/bistoury/instrument/client/classpath/DefaultAppClassPathSupplier.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.google.common.base.Strings;
2121
import com.google.common.collect.ImmutableList;
22+
import qunar.tc.bistoury.attach.file.JarStorePathUtil;
2223

2324
import java.io.File;
2425
import java.util.Iterator;
@@ -43,7 +44,11 @@ public DefaultAppClassPathSupplier(AppLibClassSupplier appLibClassSupplier) {
4344

4445
String appSourcePath = System.getProperty("bistoury.app.classes.path");
4546
if (!Strings.isNullOrEmpty(appSourcePath)) {
46-
supplier = new SettableAppClassPathSupplier(ImmutableList.of(appLibPath, appSourcePath));
47+
//这两个路径用于spring boot,springboot会先将文件解压后放在缓存文件夹下,读取时可以从里面读取
48+
String jarLibPath = JarStorePathUtil.getJarLibPath();
49+
String jarSourcePath = JarStorePathUtil.getJarSourcePath();
50+
ImmutableList<String> list = ImmutableList.of(appLibPath, appSourcePath, jarLibPath, jarSourcePath);
51+
supplier = new SettableAppClassPathSupplier(list);
4752
} else {
4853
Iterator<AppClassPathSupplierFactory> factoryIterator = ServiceLoader.load(AppClassPathSupplierFactory.class).iterator();
4954
if (factoryIterator.hasNext()) {

bistoury-instrument-client/src/main/java/qunar/tc/bistoury/instrument/client/classpath/WebAppClassPathSupplier.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package qunar.tc.bistoury.instrument.client.classpath;
1919

2020
import com.google.common.collect.ImmutableList;
21+
import qunar.tc.bistoury.attach.file.JarStorePathUtil;
2122

2223
import java.io.File;
2324
import java.util.List;
@@ -43,6 +44,11 @@ private List<String> findClassPath(String appLibPath) {
4344
final File webRoot = libFile.getParentFile();
4445
String sourcePath = new File(webRoot, "classes").getAbsolutePath();
4546
String libPath = libFile.getAbsolutePath();
46-
return ImmutableList.of(sourcePath, libPath);
47+
48+
//这两个路径用于spring boot,springboot会先将文件解压后放在缓存文件夹下,读取时可以从里面读取
49+
String jarLibPath = JarStorePathUtil.getJarLibPath();
50+
String jarSourcePath = JarStorePathUtil.getJarSourcePath();
51+
52+
return ImmutableList.of(sourcePath, libPath, jarLibPath, jarSourcePath);
4753
}
4854
}

bistoury-proxy/src/bin/bistoury-proxy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ else
2525
JAVA=java;
2626
fi
2727
CLASSPATH="$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/sa-jdi.jar"
28-
JAVA_OPTS="$JAVA_OPTS -Xloggc:${BISTOURY_LOG_DIR}/bistoury-gc-${TIMESTAMP}.log -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${BISTOURY_LOG_DIR}"
28+
JAVA_OPTS="$JAVA_OPTS -Xloggc:${BISTOURY_LOG_DIR}/bistoury-gc-${TIMESTAMP}.log -XX:+PrintGC -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${BISTOURY_LOG_DIR}"
2929
BISTOURY_PID_FILE="$BISTOURY_PID_DIR/bistoury-proxy.pid"
3030
BISTOURY_DAEMON_OUT="$BISTOURY_LOG_DIR/bistoury-proxy.out"
3131

bistoury-proxy/src/main/java/qunar/tc/bistoury/proxy/container/Bootstrap.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public static void main(String[] args) throws Exception {
7676

7777
logger.info("Server配置加载完成,正在启动中...");
7878
tomcat.start();
79-
logger.info("Server启动成功");
8079
tomcat.getServer().await();
8180
} catch (Exception e) {
8281
logger.error("Server启动失败...", e);

bistoury-ui/src/bin/bistoury-ui.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ else
2525
JAVA=java;
2626
fi
2727
CLASSPATH="$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/sa-jdi.jar"
28-
JAVA_OPTS="$JAVA_OPTS -Xloggc:${BISTOURY_LOG_DIR}/bistoury-gc-${TIMESTAMP}.log -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${BISTOURY_LOG_DIR}"
28+
JAVA_OPTS="$JAVA_OPTS -Xloggc:${BISTOURY_LOG_DIR}/bistoury-gc-${TIMESTAMP}.log -XX:+PrintGC -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${BISTOURY_LOG_DIR}"
2929
BISTOURY_PID_FILE="$BISTOURY_PID_DIR/bistoury-ui.pid"
3030
BISTOURY_DAEMON_OUT="$BISTOURY_LOG_DIR/bistoury-ui.out"
3131

bistoury-ui/src/main/java/qunar/tc/bistoury/ui/container/Bootstrap.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public static void main(String[] args) {
7373

7474
logger.info("Server配置加载完成,正在启动中...");
7575
tomcat.start();
76-
logger.info("Server启动成功");
7776
tomcat.getServer().await();
7877
} catch (Exception e) {
7978
logger.error("Server启动失败...", e);

0 commit comments

Comments
 (0)