improve banner, support app_name, start_time. #2990

master
hengyunabc 1 week ago
parent 3144514717
commit 091ce30f31

@ -112,13 +112,25 @@ public class ArthasBanner {
public static String welcome(Map<String, String> infos) {
logger.info("Current arthas version: {}, recommend latest version: {}", version(), latestVersion());
String appName = System.getProperty("project.name");
if (appName == null) {
appName = System.getProperty("app.name");
}
if (appName == null) {
appName = System.getProperty("spring.application.name");
}
TableElement table = new TableElement().rightCellPadding(1)
.row("wiki", wiki())
.row("tutorials", tutorials())
.row("version", version())
.row("main_class", PidUtils.mainClass())
.row("pid", PidUtils.currentPid())
.row("time", DateUtils.getCurrentDateTime());
.row("main_class", PidUtils.mainClass());
if (appName != null) {
table.row("app_name", appName);
}
table.row("pid", PidUtils.currentPid())
.row("start_time", DateUtils.getStartDateTime())
.row("currnt_time", DateUtils.getCurrentDateTime());
for (Entry<String, String> entry : infos.entrySet()) {
table.row(entry.getKey(), entry.getValue());
}

@ -1,6 +1,10 @@
package com.taobao.arthas.core.util;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
/**
@ -21,4 +25,16 @@ public final class DateUtils {
public static String formatDateTime(LocalDateTime dateTime) {
return DATE_TIME_FORMATTER.format(dateTime);
}
public static String getStartDateTime() {
try {
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
long startTime = runtimeMXBean.getStartTime();
Instant startInstant = Instant.ofEpochMilli(startTime);
LocalDateTime startDateTime = LocalDateTime.ofInstant(startInstant, ZoneId.systemDefault());
return DATE_TIME_FORMATTER.format(startDateTime);
} catch (Throwable e) {
return "unknown";
}
}
}

Loading…
Cancel
Save