mirror of
https://github.com/alibaba/arthas.git
synced 2024-04-21 10:21:39 +00:00
support arthas.outputPath config. #1641
This commit is contained in:
@@ -11,3 +11,5 @@ arthas.enhanceLoaders=java.lang.ClassLoader
|
||||
#arthas.appName=demoapp
|
||||
#arthas.tunnelServer=ws://127.0.0.1:7777/ws
|
||||
#arthas.agentId=mmmmmmyiddddd
|
||||
|
||||
#arthas.outputPath=arthas-output
|
||||
@@ -433,10 +433,16 @@ public class ProfilerCommand extends AnnotatedCommand {
|
||||
return profilerModel;
|
||||
}
|
||||
|
||||
private String outputFile() {
|
||||
private String outputFile() throws IOException {
|
||||
if (this.file == null) {
|
||||
this.file = new File("arthas-output",
|
||||
new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date()) + "." + this.format).getAbsolutePath();
|
||||
File outputPath = ArthasBootstrap.getInstance().getOutputPath();
|
||||
if (outputPath != null) {
|
||||
this.file = new File(outputPath,
|
||||
new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date()) + "." + this.format)
|
||||
.getAbsolutePath();
|
||||
} else {
|
||||
this.file = File.createTempFile("arthas-output", "." + this.format).getAbsolutePath();
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,11 @@ public class Configure {
|
||||
private String tunnelServer;
|
||||
private String agentId;
|
||||
|
||||
/**
|
||||
* @see com.taobao.arthas.common.ArthasConstants#ARTHAS_OUTPUT
|
||||
*/
|
||||
private String outputPath;
|
||||
|
||||
/**
|
||||
* 需要被增强的ClassLoader的全类名,多个用英文 , 分隔
|
||||
*/
|
||||
@@ -148,6 +153,14 @@ public class Configure {
|
||||
this.enhanceLoaders = enhanceLoaders;
|
||||
}
|
||||
|
||||
public String getOutputPath() {
|
||||
return outputPath;
|
||||
}
|
||||
|
||||
public void setOutputPath(String outputPath) {
|
||||
this.outputPath = outputPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 序列化成字符串
|
||||
*
|
||||
|
||||
@@ -104,7 +104,7 @@ public class ArthasBootstrap {
|
||||
private SessionManager sessionManager;
|
||||
private TunnelClient tunnelClient;
|
||||
|
||||
private File arthasOutputDir;
|
||||
private File outputPath;
|
||||
|
||||
private static LoggerContext loggerContext;
|
||||
private EventExecutorGroup workerGroup;
|
||||
@@ -122,15 +122,20 @@ public class ArthasBootstrap {
|
||||
private ArthasBootstrap(Instrumentation instrumentation, Map<String, String> args) throws Throwable {
|
||||
this.instrumentation = instrumentation;
|
||||
|
||||
String outputPath = System.getProperty("arthas.output.dir", "arthas-output");
|
||||
arthasOutputDir = new File(outputPath);
|
||||
arthasOutputDir.mkdirs();
|
||||
initFastjson();
|
||||
|
||||
// 1. initSpy()
|
||||
initSpy();
|
||||
// 2. ArthasEnvironment
|
||||
initArthasEnvironment(args);
|
||||
|
||||
String outputPathStr = configure.getOutputPath();
|
||||
if (outputPathStr == null) {
|
||||
outputPathStr = ArthasConstants.ARTHAS_OUTPUT;
|
||||
}
|
||||
outputPath = new File(outputPathStr);
|
||||
outputPath.mkdirs();
|
||||
|
||||
// 3. init logger
|
||||
loggerContext = LogUtil.initLooger(arthasEnvironment);
|
||||
|
||||
@@ -622,4 +627,9 @@ public class ArthasBootstrap {
|
||||
public HttpApiHandler getHttpApiHandler() {
|
||||
return httpApiHandler;
|
||||
}
|
||||
|
||||
public File getOutputPath() {
|
||||
return outputPath;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
-2
@@ -55,7 +55,7 @@ public class DirectoryBrowser {
|
||||
private static String linePart1Str = "<a href=\"%s\" title=\"%s\">";
|
||||
private static String linePart2Str = "%-60s";
|
||||
|
||||
private static String renderDir(File dir) {
|
||||
static String renderDir(File dir) {
|
||||
File[] listFiles = dir.listFiles();
|
||||
|
||||
StringBuilder sb = new StringBuilder(8192);
|
||||
@@ -112,7 +112,9 @@ public class DirectoryBrowser {
|
||||
if (path.startsWith("/")) {
|
||||
path = path.substring(1, path.length());
|
||||
}
|
||||
File file = new File(path);
|
||||
// path maybe: arthas-output/20201225-203454.svg
|
||||
// 需要取 dir的parent来去掉前缀
|
||||
File file = new File(dir.getParent(), path);
|
||||
|
||||
if (isSubFile(dir, file)) {
|
||||
DefaultFullHttpResponse fullResp = new DefaultFullHttpResponse(version, HttpResponseStatus.OK);
|
||||
|
||||
@@ -46,6 +46,10 @@ public class HttpRequestHandler extends SimpleChannelInboundHandler<FullHttpRequ
|
||||
|
||||
private HttpApiHandler httpApiHandler;
|
||||
|
||||
public HttpRequestHandler(String wsUri) {
|
||||
this(wsUri, ArthasBootstrap.getInstance().getOutputPath());
|
||||
}
|
||||
|
||||
public HttpRequestHandler(String wsUri, File dir) {
|
||||
this.wsUri = wsUri;
|
||||
this.dir = dir;
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ public class LocalTtyServerInitializer extends ChannelInitializer<LocalChannel>
|
||||
pipeline.addLast(new HttpServerCodec());
|
||||
pipeline.addLast(new ChunkedWriteHandler());
|
||||
pipeline.addLast(new HttpObjectAggregator(ArthasConstants.MAX_HTTP_CONTENT_LENGTH));
|
||||
pipeline.addLast(workerGroup, "HttpRequestHandler", new HttpRequestHandler("/ws", new File(ArthasConstants.ARTHAS_OUTPUT)));
|
||||
pipeline.addLast(workerGroup, "HttpRequestHandler", new HttpRequestHandler("/ws"));
|
||||
pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
|
||||
pipeline.addLast(new TtyWebSocketFrameHandler(group, handler));
|
||||
}
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ public class TtyServerInitializer extends ChannelInitializer<SocketChannel> {
|
||||
pipeline.addLast(new HttpServerCodec());
|
||||
pipeline.addLast(new ChunkedWriteHandler());
|
||||
pipeline.addLast(new HttpObjectAggregator(ArthasConstants.MAX_HTTP_CONTENT_LENGTH));
|
||||
pipeline.addLast(workerGroup, "HttpRequestHandler", new HttpRequestHandler("/ws", new File(ArthasConstants.ARTHAS_OUTPUT)));
|
||||
pipeline.addLast(workerGroup, "HttpRequestHandler", new HttpRequestHandler("/ws"));
|
||||
pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
|
||||
pipeline.addLast(new TtyWebSocketFrameHandler(group, handler));
|
||||
}
|
||||
|
||||
+1
-1
@@ -86,7 +86,7 @@ public class ProtocolDetectHandler extends ChannelInboundHandlerAdapter {
|
||||
pipeline.addLast(new HttpServerCodec());
|
||||
pipeline.addLast(new ChunkedWriteHandler());
|
||||
pipeline.addLast(new HttpObjectAggregator(ArthasConstants.MAX_HTTP_CONTENT_LENGTH));
|
||||
pipeline.addLast(workerGroup, "HttpRequestHandler", new HttpRequestHandler("/ws", new File(ArthasConstants.ARTHAS_OUTPUT)));
|
||||
pipeline.addLast(workerGroup, "HttpRequestHandler", new HttpRequestHandler("/ws"));
|
||||
pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
|
||||
pipeline.addLast(new TtyWebSocketFrameHandler(channelGroup, ttyConnectionFactory));
|
||||
ctx.fireChannelActive();
|
||||
|
||||
Reference in New Issue
Block a user