Skip to content

Commit

Permalink
improve banner, support app_name, start_time. #2990
Browse files Browse the repository at this point in the history
  • Loading branch information
hengyunabc committed Feb 14, 2025
1 parent 3144514 commit 091ce30
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
18 changes: 15 additions & 3 deletions core/src/main/java/com/taobao/arthas/core/util/ArthasBanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,25 @@ public static String welcome() {

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());
}
Expand Down
16 changes: 16 additions & 0 deletions core/src/main/java/com/taobao/arthas/core/util/DateUtils.java
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -21,4 +25,16 @@ public static String getCurrentDateTime() {
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";
}
}
}

0 comments on commit 091ce30

Please sign in to comment.