mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-09 18:50:26 +08:00
add cpu & mem usage info
This commit is contained in:
@@ -98,12 +98,14 @@ table, th, td {
|
|||||||
// Statistics table
|
// Statistics table
|
||||||
_, _ = fmt.Fprintf(w, "<p>Statistics (%d)</p>", runtime.NumGoroutine())
|
_, _ = fmt.Fprintf(w, "<p>Statistics (%d)</p>", runtime.NumGoroutine())
|
||||||
_, _ = fmt.Fprintf(w, "<table style=\"border=4px solid\">")
|
_, _ = 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)
|
trafficUp := atomic.LoadInt64(&s.trafficUp)
|
||||||
trafficDown := atomic.LoadInt64(&s.trafficDown)
|
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()),
|
date(time.Now()),
|
||||||
uptime(),
|
uptime(),
|
||||||
|
cpu(),
|
||||||
|
mem(),
|
||||||
byteCountSI(trafficUp+trafficDown),
|
byteCountSI(trafficUp+trafficDown),
|
||||||
byteCountSI(trafficUp),
|
byteCountSI(trafficUp),
|
||||||
byteCountSI(trafficDown),
|
byteCountSI(trafficDown),
|
||||||
|
@@ -4,6 +4,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
C "github.com/shirou/gopsutil/cpu"
|
||||||
|
M "github.com/shirou/gopsutil/mem"
|
||||||
)
|
)
|
||||||
|
|
||||||
var startTime time.Time
|
var startTime time.Time
|
||||||
@@ -12,6 +15,16 @@ func init() {
|
|||||||
startTime = time.Now()
|
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 {
|
func date(t time.Time) string {
|
||||||
return t.Format("Mon Jan 2 15:04:05")
|
return t.Format("Mon Jan 2 15:04:05")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user