Improved admin page
This commit is contained in:
@ -1,9 +1,16 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
"github.com/animenotifier/notify.moe/utils"
|
||||
"github.com/shirou/gopsutil/cpu"
|
||||
"github.com/shirou/gopsutil/disk"
|
||||
"github.com/shirou/gopsutil/host"
|
||||
"github.com/shirou/gopsutil/mem"
|
||||
)
|
||||
|
||||
// Get admin page.
|
||||
@ -14,5 +21,47 @@ func Get(ctx *aero.Context) string {
|
||||
return ctx.Redirect("/")
|
||||
}
|
||||
|
||||
return ctx.HTML(components.Admin(user))
|
||||
// CPU
|
||||
cpuUsage := 0.0
|
||||
cpuUsages, err := cpu.Percent(1*time.Second, false)
|
||||
|
||||
if err == nil {
|
||||
cpuUsage = cpuUsages[0]
|
||||
}
|
||||
|
||||
// Memory
|
||||
memUsage := 0.0
|
||||
memInfo, _ := mem.VirtualMemory()
|
||||
|
||||
if err == nil {
|
||||
memUsage = memInfo.UsedPercent
|
||||
}
|
||||
|
||||
// Disk
|
||||
diskUsage := 0.0
|
||||
diskInfo, err := disk.Usage("/")
|
||||
|
||||
if err == nil {
|
||||
diskUsage = diskInfo.UsedPercent
|
||||
}
|
||||
|
||||
// Host
|
||||
platform, family, platformVersion, _ := host.PlatformInformation()
|
||||
kernelVersion, err := host.KernelVersion()
|
||||
|
||||
return ctx.HTML(components.Admin(user, cpuUsage, memUsage, diskUsage, platform, family, platformVersion, kernelVersion))
|
||||
}
|
||||
|
||||
func average(floatSlice []float64) float64 {
|
||||
if len(floatSlice) == 0 {
|
||||
return arn.DefaultAverageRating
|
||||
}
|
||||
|
||||
var sum float64
|
||||
|
||||
for _, value := range floatSlice {
|
||||
sum += value
|
||||
}
|
||||
|
||||
return sum / float64(len(floatSlice))
|
||||
}
|
||||
|
Reference in New Issue
Block a user