Improved admin page

This commit is contained in:
Eduard Urbach 2017-10-02 14:28:10 +02:00
parent 8ace9a6538
commit b0de2045d7
3 changed files with 112 additions and 18 deletions

View File

@ -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))
}

View File

@ -1,19 +1,63 @@
component Admin(user *arn.User)
component Admin(user *arn.User, cpuUsage, memUsage, diskUsage float64, platform, family, platformVersion, kernelVersion string)
h1.page-title Admin Panel
h3 Server
table
//- thead
//- tr
//- th Metric
//- th Value
tbody
tr
td CPU count:
td= runtime.NumCPU()
tr
td Goroutines:
td= runtime.NumGoroutine()
tr
td Go version:
td= runtime.Version()
.widgets
.widget.mountable
h3.widget-title Usage
table
tbody
tr
td CPU usage:
td
span= int(cpuUsage + 0.5)
span %
tr
td Memory usage:
td
span= int(memUsage + 0.5)
span %
tr
td Disk usage:
td
span= int(diskUsage + 0.5)
span %
.widget.mountable
h3.widget-title OS
table
tbody
tr
td Platform:
td= platform
tr
td Family:
td= family
tr
td Version:
td= platformVersion
tr
td Kernel:
td= kernelVersion
.widget.mountable
h3.widget-title Hardware
table
tbody
tr
td CPUs:
td= runtime.NumCPU()
.widget.mountable
h3.widget-title Go
table
tbody
tr
td Version:
td= runtime.Version()
tr
td Goroutines:
td= runtime.NumGoroutine()

View File

@ -6,6 +6,7 @@ const ETAGS = new Map<string, string>()
const CACHEREFRESH = new Map<string, Promise<void>>()
const EXCLUDECACHE = new Set<string>([
"/api/",
"/admin/",
"/paypal/",
"/import/",
"chrome-extension"