print main class in welcome message. #1719

This commit is contained in:
hengyunabc 2021-03-02 14:52:39 +08:00
parent 4c1692650e
commit 7c71623f14
4 changed files with 28 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package com.taobao.arthas.common;
import java.lang.management.ManagementFactory;
import java.util.Map;
/**
*
@ -11,6 +12,8 @@ public class PidUtils {
private static String PID = "-1";
private static long pid = -1;
private static String MAIN_CLASS = "";
static {
// https://stackoverflow.com/a/7690178
try {
@ -24,6 +27,16 @@ public class PidUtils {
} catch (Throwable e) {
// ignore
}
try {
for (final Map.Entry<String, String> entry : System.getenv().entrySet()) {
if (entry.getKey().startsWith("JAVA_MAIN_CLASS")) // like JAVA_MAIN_CLASS_13328
MAIN_CLASS = entry.getValue();
}
} catch (Throwable e) {
// ignore
}
}
private PidUtils() {
@ -36,4 +49,8 @@ public class PidUtils {
public static long currentLongPid() {
return pid;
}
public static String mainClass() {
return MAIN_CLASS;
}
}

View File

@ -10,6 +10,7 @@ public class WelcomeModel extends ResultModel {
private String version;
private String wiki;
private String tutorials;
private String mainClass;
public WelcomeModel() {
}
@ -58,4 +59,12 @@ public class WelcomeModel extends ResultModel {
public void setTutorials(String tutorials) {
this.tutorials = tutorials;
}
public String getMainClass() {
return mainClass;
}
public void setMainClass(String mainClass) {
this.mainClass = mainClass;
}
}

View File

@ -286,6 +286,7 @@ public class HttpApiHandler {
welcomeModel.setVersion(ArthasBanner.version());
welcomeModel.setWiki(ArthasBanner.wiki());
welcomeModel.setTutorials(ArthasBanner.tutorials());
welcomeModel.setMainClass(PidUtils.mainClass());
welcomeModel.setPid(PidUtils.currentPid());
welcomeModel.setTime(DateUtils.getCurrentDate());
resultDistributor.appendResult(welcomeModel);

View File

@ -114,6 +114,7 @@ public class ArthasBanner {
.row("wiki", wiki())
.row("tutorials", tutorials())
.row("version", version())
.row("main_class", PidUtils.mainClass())
.row("pid", PidUtils.currentPid())
.row("time", DateUtils.getCurrentDate());
for (Entry<String, String> entry : infos.entrySet()) {