add disk usage

This commit is contained in:
Jason
2019-08-16 17:02:12 +08:00
parent 494551190e
commit 924e470661
2 changed files with 12 additions and 2 deletions

View File

@@ -98,14 +98,15 @@ 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>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) 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><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()), date(time.Now()),
uptime(), uptime(),
cpu(), cpu(),
mem(), mem(),
disk(),
byteCountSI(trafficUp+trafficDown), byteCountSI(trafficUp+trafficDown),
byteCountSI(trafficUp), byteCountSI(trafficUp),
byteCountSI(trafficDown), byteCountSI(trafficDown),

View File

@@ -6,6 +6,7 @@ import (
"time" "time"
C "github.com/shirou/gopsutil/cpu" C "github.com/shirou/gopsutil/cpu"
D "github.com/shirou/gopsutil/disk"
M "github.com/shirou/gopsutil/mem" M "github.com/shirou/gopsutil/mem"
) )
@@ -23,6 +24,14 @@ func cpu() string {
return fmt.Sprintf("%.1f%%", c[0]) 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 { func mem() string {
m, err := M.VirtualMemory() m, err := M.VirtualMemory()
if err != nil { if err != nil {