diff --git a/component/session/server.go b/component/session/server.go
index 5d86976..98398e9 100644
--- a/component/session/server.go
+++ b/component/session/server.go
@@ -98,12 +98,14 @@ table, th, td {
// Statistics table
_, _ = fmt.Fprintf(w, "
Statistics (%d)
", runtime.NumGoroutine())
_, _ = fmt.Fprintf(w, "")
- _, _ = fmt.Fprintf(w, "Last Refresh Time | Uptime | Total | Upload | Download |
\n")
+ _, _ = fmt.Fprintf(w, "Last Refresh Time | Uptime | CPU | MEM | Total | Upload | Download |
\n")
trafficUp := atomic.LoadInt64(&s.trafficUp)
trafficDown := atomic.LoadInt64(&s.trafficDown)
- _, _ = fmt.Fprintf(w, "%v | %v | %v | %v | %v |
\n",
+ _, _ = fmt.Fprintf(w, "%v | %v | %v | %v | %v | %v | %v |
\n",
date(time.Now()),
uptime(),
+ cpu(),
+ mem(),
byteCountSI(trafficUp+trafficDown),
byteCountSI(trafficUp),
byteCountSI(trafficDown),
diff --git a/component/session/utils.go b/component/session/utils.go
index 0b6d1a8..aca3583 100644
--- a/component/session/utils.go
+++ b/component/session/utils.go
@@ -4,6 +4,9 @@ import (
"fmt"
"strings"
"time"
+
+ C "github.com/shirou/gopsutil/cpu"
+ M "github.com/shirou/gopsutil/mem"
)
var startTime time.Time
@@ -12,6 +15,16 @@ func init() {
startTime = time.Now()
}
+func cpu() string {
+ c, _ := C.Percent(0, false)
+ return fmt.Sprintf("%.1f%%", c[0])
+}
+
+func mem() string {
+ m, _ := M.VirtualMemory()
+ return fmt.Sprintf("%.1f%%", m.UsedPercent)
+}
+
func date(t time.Time) string {
return t.Format("Mon Jan 2 15:04:05")
}