Browse Source

add platform

pull/15/head
Jason 5 years ago
parent
commit
fb3fe646ff
  1. 9
      component/session/server.go
  2. 9
      component/session/utils.go

9
component/session/server.go

@ -98,15 +98,16 @@ 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>Disk</th><th>Total</th><th>Upload</th><th>Download</th></tr>\n") _, _ = fmt.Fprintf(w, "<th>Platform</th><th>CPU</th><th>Mem</th><th>Disk</th><tr><th>Last Refresh Time</th><th>Uptime</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><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><td>%v</td></tr>\n",
date(time.Now()), platform(),
uptime(),
cpu(), cpu(),
mem(), mem(),
disk(), disk(),
date(time.Now()),
uptime(),
byteCountSI(trafficUp+trafficDown), byteCountSI(trafficUp+trafficDown),
byteCountSI(trafficUp), byteCountSI(trafficUp),
byteCountSI(trafficDown), byteCountSI(trafficDown),

9
component/session/utils.go

@ -7,6 +7,7 @@ import (
C "github.com/shirou/gopsutil/cpu" C "github.com/shirou/gopsutil/cpu"
D "github.com/shirou/gopsutil/disk" D "github.com/shirou/gopsutil/disk"
H "github.com/shirou/gopsutil/host"
M "github.com/shirou/gopsutil/mem" M "github.com/shirou/gopsutil/mem"
) )
@ -32,6 +33,14 @@ func disk() string {
return fmt.Sprintf("%.1f%%", d.UsedPercent) return fmt.Sprintf("%.1f%%", d.UsedPercent)
} }
func platform() string {
h, err := H.Info()
if err != nil {
return "N/A"
}
return fmt.Sprintf("%s-%s", h.Platform, h.PlatformVersion)
}
func mem() string { func mem() string {
m, err := M.VirtualMemory() m, err := M.VirtualMemory()
if err != nil { if err != nil {

Loading…
Cancel
Save