Skip to content

Commit

Permalink
在线debug和动态监控支持Spring boot项目
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
xleiy authored Aug 25, 2019
2 parents b8229b1 + 8fa5773 commit 8278398
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,34 +70,36 @@ public static synchronized void init(Instrumentation instrumentation) {

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

//jar debug放在最前面,因为在里面会对jar包启动的项目进行解压
try {
builder.add(QDebugClients.create(instrumentInfo));
builder.add(JarDebugClients.create(instrumentInfo));
} catch (Exception e) {
logger.error("", "qdebug client init error", e);
logger.error("", "jar decompiler init error", e);
}

try {
builder.add(QMonitorClients.create(instrumentInfo));
builder.add(AppConfigClients.create(instrumentInfo));
} catch (Exception e) {
logger.error("", "qmonitor client init error", e);
logger.error("", "app config client init error", e);
}

try {
builder.add(JarInfoClients.create(instrumentInfo));
builder.add(QDebugClients.create(instrumentInfo));
} catch (Exception e) {
logger.error("", "jar info client init error", e);
logger.error("", "qdebug client init error", e);
}

try {
builder.add(AppConfigClients.create(instrumentInfo));
builder.add(QMonitorClients.create(instrumentInfo));
} catch (Exception e) {
logger.error("", "app config client init error", e);
logger.error("", "qmonitor client init error", e);
}

try {
builder.add(JarDebugClients.create(instrumentInfo));
builder.add(JarInfoClients.create(instrumentInfo));
} catch (Exception e) {
logger.error("", "jar decompiler init error", e);
logger.error("", "jar info client init error", e);
}

clients = builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2019 Qunar, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package qunar.tc.bistoury.attach.file;

import qunar.tc.bistoury.clientside.common.store.BistouryStore;

import java.io.File;

/**
* @author leix.xie
* @date 2019/8/24 01:27
* @describe
*/
public class JarStorePathUtil {

private static final String STORE_PATH = BistouryStore.getStorePath("tomcat_webapp");

static {
File file = new File(STORE_PATH);
if (!file.exists() || !file.isDirectory()) {
file.mkdirs();
}
}

public static String getJarStorePath() {
return new File(STORE_PATH).getPath();
}

public static String getJarLibPath() {
return System.getProperty("bistoury.jar.lib.path", new File(getJarStorePath(), "BOOT-INF/lib/").getPath());
}

public static String getJarSourcePath() {
return System.getProperty("bistoury.jar.source.path", new File(getJarStorePath(), "BOOT-INF/classes/").getPath());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import com.google.common.io.Files;
import com.taobao.middleware.logger.Logger;
import qunar.tc.bistoury.attach.common.BistouryLoggger;
import qunar.tc.bistoury.attach.file.JarStorePathUtil;
import qunar.tc.bistoury.attach.file.URLUtil;
import qunar.tc.bistoury.clientside.common.store.BistouryStore;

import java.io.File;
import java.io.InputStream;
Expand All @@ -40,15 +40,10 @@ public class JarFileServiceWrapper {

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

private static final String STORE_PATH = BistouryStore.getStorePath("tomcat_webapp");

private static final AtomicBoolean STARTED = new AtomicBoolean(false);

public JarFileServiceWrapper() {
File file = new File(STORE_PATH);
if (!file.exists() || !file.isDirectory()) {
file.mkdirs();
}

}

/**
Expand All @@ -58,8 +53,7 @@ public JarFileServiceWrapper() {
* @return
*/
public String getJarPath(final String jarFile) {
final String jarFilePath = jarFile.substring(jarFile.lastIndexOf(File.separatorChar) + 1).replace(".jar", "");
File file = new File(STORE_PATH, jarFilePath);
File file = new File(JarStorePathUtil.getJarStorePath());
if (!file.exists() || !file.isDirectory() || !STARTED.get()) {
deleteDirectory(file);
unPackJar(jarFile, file);
Expand Down
2 changes: 1 addition & 1 deletion bistoury-dist/bin/bistoury-agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ if [[ -n $APP_PID ]]; then
fi

CLASSPATH="$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/sa-jdi.jar"
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}"
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}"
BISTOURY_PID_FILE="$BISTOURY_PID_DIR/bistoury-agent.pid"
BISTOURY_DAEMON_OUT="$BISTOURY_LOG_DIR/bistoury-agent.out"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import qunar.tc.bistoury.attach.file.JarStorePathUtil;

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

String appSourcePath = System.getProperty("bistoury.app.classes.path");
if (!Strings.isNullOrEmpty(appSourcePath)) {
supplier = new SettableAppClassPathSupplier(ImmutableList.of(appLibPath, appSourcePath));
//这两个路径用于spring boot,springboot会先将文件解压后放在缓存文件夹下,读取时可以从里面读取
String jarLibPath = JarStorePathUtil.getJarLibPath();
String jarSourcePath = JarStorePathUtil.getJarSourcePath();
ImmutableList<String> list = ImmutableList.of(appLibPath, appSourcePath, jarLibPath, jarSourcePath);
supplier = new SettableAppClassPathSupplier(list);
} else {
Iterator<AppClassPathSupplierFactory> factoryIterator = ServiceLoader.load(AppClassPathSupplierFactory.class).iterator();
if (factoryIterator.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package qunar.tc.bistoury.instrument.client.classpath;

import com.google.common.collect.ImmutableList;
import qunar.tc.bistoury.attach.file.JarStorePathUtil;

import java.io.File;
import java.util.List;
Expand All @@ -43,6 +44,11 @@ private List<String> findClassPath(String appLibPath) {
final File webRoot = libFile.getParentFile();
String sourcePath = new File(webRoot, "classes").getAbsolutePath();
String libPath = libFile.getAbsolutePath();
return ImmutableList.of(sourcePath, libPath);

//这两个路径用于spring boot,springboot会先将文件解压后放在缓存文件夹下,读取时可以从里面读取
String jarLibPath = JarStorePathUtil.getJarLibPath();
String jarSourcePath = JarStorePathUtil.getJarSourcePath();

return ImmutableList.of(sourcePath, libPath, jarLibPath, jarSourcePath);
}
}
2 changes: 1 addition & 1 deletion bistoury-proxy/src/bin/bistoury-proxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ else
JAVA=java;
fi
CLASSPATH="$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/sa-jdi.jar"
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}"
JAVA_OPTS="$JAVA_OPTS -Xloggc:${BISTOURY_LOG_DIR}/bistoury-gc-${TIMESTAMP}.log -XX:+PrintGC -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${BISTOURY_LOG_DIR}"
BISTOURY_PID_FILE="$BISTOURY_PID_DIR/bistoury-proxy.pid"
BISTOURY_DAEMON_OUT="$BISTOURY_LOG_DIR/bistoury-proxy.out"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public static void main(String[] args) throws Exception {

logger.info("Server配置加载完成,正在启动中...");
tomcat.start();
logger.info("Server启动成功");
tomcat.getServer().await();
} catch (Exception e) {
logger.error("Server启动失败...", e);
Expand Down
2 changes: 1 addition & 1 deletion bistoury-ui/src/bin/bistoury-ui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ else
JAVA=java;
fi
CLASSPATH="$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/sa-jdi.jar"
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}"
JAVA_OPTS="$JAVA_OPTS -Xloggc:${BISTOURY_LOG_DIR}/bistoury-gc-${TIMESTAMP}.log -XX:+PrintGC -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${BISTOURY_LOG_DIR}"
BISTOURY_PID_FILE="$BISTOURY_PID_DIR/bistoury-ui.pid"
BISTOURY_DAEMON_OUT="$BISTOURY_LOG_DIR/bistoury-ui.out"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public static void main(String[] args) {

logger.info("Server配置加载完成,正在启动中...");
tomcat.start();
logger.info("Server启动成功");
tomcat.getServer().await();
} catch (Exception e) {
logger.error("Server启动失败...", e);
Expand Down

0 comments on commit 8278398

Please sign in to comment.