|
|
@@ -11,6 +11,7 @@ import (
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"sync"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
var lastCPU struct {
|
|
|
@@ -251,16 +252,38 @@ func systemLoadAverageHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ boot, uptime := noValue, noValue
|
|
|
+ if b, err := os.ReadFile("/proc/uptime"); err == nil {
|
|
|
+ if fields := strings.Fields(string(b)); len(fields) > 0 {
|
|
|
+ if sec, err := strconv.ParseFloat(fields[0], 64); err == nil {
|
|
|
+ d := time.Duration(sec) * time.Second
|
|
|
+ boot = time.Now().Add(-d).Format("2006-01-02 15:04:05")
|
|
|
+ day := int(d.Hours() / 24)
|
|
|
+ if day > 0 {
|
|
|
+ uptime = fmt.Sprintf("%d天 %02d:%02d:%02d",
|
|
|
+ int(d.Hours()/24), int(d.Hours())%24, int(d.Minutes())%60, int(d.Seconds())%60)
|
|
|
+ } else {
|
|
|
+ uptime = fmt.Sprintf("%02d:%02d:%02d",
|
|
|
+ int(d.Hours())%24, int(d.Minutes())%60, int(d.Seconds())%60)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
resp := struct {
|
|
|
Load1m string `json:"load1m"`
|
|
|
Load5m string `json:"load5m"`
|
|
|
Load15m string `json:"load15m"`
|
|
|
RunQueue string `json:"runQueue"`
|
|
|
+ BootTime string `json:"bootTime"`
|
|
|
+ UpTime string `json:"uptime"`
|
|
|
}{
|
|
|
Load1m: formatLoad(fields[0]),
|
|
|
Load5m: formatLoad(fields[1]),
|
|
|
Load15m: formatLoad(fields[2]),
|
|
|
RunQueue: fields[3],
|
|
|
+ BootTime: boot,
|
|
|
+ UpTime: uptime,
|
|
|
}
|
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|