mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-09 18:50:26 +08:00
add disk usage
This commit is contained in:
@@ -98,14 +98,15 @@ 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>CPU</th><th>MEM</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>DISK</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><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><td>%v</td></tr>\n",
|
||||
date(time.Now()),
|
||||
uptime(),
|
||||
cpu(),
|
||||
mem(),
|
||||
disk(),
|
||||
byteCountSI(trafficUp+trafficDown),
|
||||
byteCountSI(trafficUp),
|
||||
byteCountSI(trafficDown),
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
C "github.com/shirou/gopsutil/cpu"
|
||||
D "github.com/shirou/gopsutil/disk"
|
||||
M "github.com/shirou/gopsutil/mem"
|
||||
)
|
||||
|
||||
@@ -23,6 +24,14 @@ func cpu() string {
|
||||
return fmt.Sprintf("%.1f%%", c[0])
|
||||
}
|
||||
|
||||
func disk() string {
|
||||
d, err := D.Usage("/")
|
||||
if err != nil {
|
||||
return "N/A"
|
||||
}
|
||||
return fmt.Sprintf("%.1f%%", d.UsedPercent)
|
||||
}
|
||||
|
||||
func mem() string {
|
||||
m, err := M.VirtualMemory()
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user