diff --git a/pages/admin/admin.go b/pages/admin/admin.go index 9ef619e3..94912e64 100644 --- a/pages/admin/admin.go +++ b/pages/admin/admin.go @@ -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)) } diff --git a/pages/admin/admin.pixy b/pages/admin/admin.pixy index e4d08109..77d8b121 100644 --- a/pages/admin/admin.pixy +++ b/pages/admin/admin.pixy @@ -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() \ No newline at end of file + .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() \ No newline at end of file diff --git a/sw/service-worker.ts b/sw/service-worker.ts index 6f800784..da79784a 100644 --- a/sw/service-worker.ts +++ b/sw/service-worker.ts @@ -6,6 +6,7 @@ const ETAGS = new Map() const CACHEREFRESH = new Map>() const EXCLUDECACHE = new Set([ "/api/", + "/admin/", "/paypal/", "/import/", "chrome-extension"