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 package admin
import ( import (
"time"
"github.com/aerogo/aero" "github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils" "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. // Get admin page.
@ -14,5 +21,47 @@ func Get(ctx *aero.Context) string {
return ctx.Redirect("/") 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 h1.page-title Admin Panel
h3 Server .widgets
.widget.mountable
h3.widget-title Usage
table table
//- thead
//- tr
//- th Metric
//- th Value
tbody tbody
tr tr
td CPU count: 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() td= runtime.NumCPU()
.widget.mountable
h3.widget-title Go
table
tbody
tr
td Version:
td= runtime.Version()
tr tr
td Goroutines: td Goroutines:
td= runtime.NumGoroutine() td= runtime.NumGoroutine()
tr
td Go version:
td= runtime.Version()

View File

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