Skip to content

Commit 8e906a0

Browse files
vishesh92dhslove
authored andcommitted
server: use /prod/stat to get uptime instead of the uptime command (apache#11670)
1 parent 415b918 commit 8e906a0

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

server/src/main/java/com/cloud/server/StatsCollector.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -972,12 +972,12 @@ private void getProcFileSystemData(@NotNull ManagementServerHostStatsEntry newEn
972972
logger.info(String.format("used memory from /proc: %d", newEntry.getSystemMemoryUsed()));
973973
}
974974
try {
975-
String bootTime = Script.runSimpleBashScript("uptime -s");
976-
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.ENGLISH);
975+
String bootTime = Script.runSimpleBashScript("date -d @$(grep btime /proc/stat | awk '{print $2}') '+%Y-%m-%d %H:%M:%S'");
976+
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
977977
Date date = formatter.parse(bootTime);
978978
newEntry.setSystemBootTime(date);
979979
} catch (ParseException e) {
980-
logger.error("can not retrieve system uptime");
980+
logger.error("can not retrieve system uptime", e);
981981
}
982982
String maxuse = Script.runSimpleBashScript(String.format("ps -o vsz= %d", newEntry.getPid()));
983983
newEntry.setSystemMemoryVirtualSize(Long.parseLong(maxuse) * 1024);

0 commit comments

Comments
 (0)