mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-09 02:30:05 +08:00
add cpu & mem usage info
This commit is contained in:
@@ -98,12 +98,14 @@ table, th, td {
|
||||
// Statistics table
|
||||
_, _ = fmt.Fprintf(w, "<p>Statistics (%d)</p>", runtime.NumGoroutine())
|
||||
_, _ = fmt.Fprintf(w, "<table style=\"border=4px solid\">")
|
||||
_, _ = fmt.Fprintf(w, "<tr><th>Last Refresh Time</th><th>Uptime</th><th>Total</th><th>Upload</th><th>Download</th></tr>\n")
|
||||
_, _ = fmt.Fprintf(w, "<tr><th>Last Refresh Time</th><th>Uptime</th><th>CPU</th><th>MEM</th><th>Total</th><th>Upload</th><th>Download</th></tr>\n")
|
||||
trafficUp := atomic.LoadInt64(&s.trafficUp)
|
||||
trafficDown := atomic.LoadInt64(&s.trafficDown)
|
||||
_, _ = fmt.Fprintf(w, "<tr><td>%v</td><td>%v</td><td>%v</td><td>%v</td><td>%v</td></tr>\n",
|
||||
_, _ = fmt.Fprintf(w, "<tr><td>%v</td><td>%v</td><td>%v</td><td>%v</td><td>%v</td><td>%v</td><td>%v</td></tr>\n",
|
||||
date(time.Now()),
|
||||
uptime(),
|
||||
cpu(),
|
||||
mem(),
|
||||
byteCountSI(trafficUp+trafficDown),
|
||||
byteCountSI(trafficUp),
|
||||
byteCountSI(trafficDown),
|
||||
|
@@ -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")
|
||||
}
|
||||
|
Reference in New Issue
Block a user