Updated admin panel

This commit is contained in:
Eduard Urbach 2018-11-06 16:20:44 +09:00
parent a4a20366f1
commit 81764b981c
4 changed files with 126 additions and 60 deletions

View File

@ -1,10 +1,16 @@
package admin
import (
"runtime"
"strings"
"github.com/aerogo/aero"
"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.
@ -16,32 +22,61 @@ func Get(ctx *aero.Context) string {
}
// // CPU
// cpuUsage := 0.0
// cpuUsages, err := cpu.Percent(1*time.Second, false)
cpuModel := ""
cpuInfo, err := cpu.Info()
// if err == nil {
// cpuUsage = cpuUsages[0]
// }
if err == nil {
cpuModel = cpuInfo[0].ModelName
}
// // Memory
// memUsage := 0.0
// memInfo, _ := mem.VirtualMemory()
cpuUsage := 0.0
cpuUsages, err := cpu.Percent(0, false)
// if err == nil {
// memUsage = memInfo.UsedPercent
// }
if err == nil {
cpuUsage = cpuUsages[0]
}
// // Disk
// diskUsage := 0.0
// diskInfo, err := disk.Usage("/")
// Memory
memUsage := 0.0
memTotal := uint64(0)
memInfo, err := mem.VirtualMemory()
// if err == nil {
// diskUsage = diskInfo.UsedPercent
// }
if err == nil {
memUsage = memInfo.UsedPercent
memTotal = memInfo.Total
}
// Disk
diskUsage := 0.0
diskTotal := uint64(0)
diskInfo, err := disk.Usage("/")
if err == nil {
diskUsage = diskInfo.UsedPercent
diskTotal = diskInfo.Total
}
// GC
memStats := &runtime.MemStats{}
runtime.ReadMemStats(memStats)
// Host
platform, family, platformVersion, _ := host.PlatformInformation()
kernelVersion, _ := host.KernelVersion()
kernelVersion = strings.Replace(kernelVersion, "-generic", "", 1)
return ctx.HTML(components.Admin(user, platform, family, platformVersion, kernelVersion))
return ctx.HTML(components.Admin(
user,
platform,
family,
platformVersion,
kernelVersion,
cpuUsage,
memUsage,
diskUsage,
cpuModel,
memTotal,
diskTotal,
memStats,
))
}

View File

@ -12,68 +12,85 @@ component AdminTabs
Icon("pencil")
span.tab-text Editor
component Admin(user *arn.User, platform, family, platformVersion, kernelVersion string)
component Admin(user *arn.User, platform, family, platformVersion, kernelVersion string, cpuUsage, memUsage, diskUsage float64, cpuModel string, memTotal, diskTotal uint64, memStats *runtime.MemStats)
h1.page-title Admin Panel
AdminTabs
.admin
//- .widget.mountable
//- h3.widget-title Usage
.admin-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 %
table
tbody
tr
td.admin-info-key CPU usage:
td.admin-info-value
span= int(cpuUsage + 0.5)
span %
tr
td.admin-info-key Memory usage:
td.admin-info-value
span= int(memUsage + 0.5)
span %
tr
td.admin-info-key Disk usage:
td.admin-info-value
span= int(diskUsage + 0.5)
span %
.widget.mountable
.admin-widget.mountable
h3.widget-title OS
table
tbody
tr
td Platform:
td= platform
td.admin-info-key Platform:
td.admin-info-value= platform
tr
td Family:
td= family
td.admin-info-key Family:
td.admin-info-value= family
tr
td Version:
td= platformVersion
td.admin-info-key Version:
td.admin-info-value= platformVersion
tr
td Kernel:
td= kernelVersion
td.admin-info-key Kernel:
td.admin-info-value= kernelVersion
.widget.mountable
.admin-widget.mountable
h3.widget-title Hardware
table
tbody
tr
td CPUs:
td= runtime.NumCPU()
td.admin-info-key CPU model:
td.admin-info-value= cpuModel
tr
td.admin-info-key CPU cores:
td.admin-info-value= runtime.NumCPU()
tr
td.admin-info-key RAM:
td.admin-info-value= humanize.IBytes(memTotal)
.widget.mountable
tr
td.admin-info-key Disk:
td.admin-info-value= humanize.IBytes(diskTotal)
.admin-widget.mountable
h3.widget-title Go
table
tbody
tr
td Version:
td= runtime.Version()
td.admin-info-key Version:
td.admin-info-value= runtime.Version()
tr
td Goroutines:
td= runtime.NumGoroutine()
td.admin-info-key Goroutines:
td.admin-info-value= humanize.Comma(int64(runtime.NumGoroutine()))
tr
td.admin-info-key Objects:
td.admin-info-value= humanize.Comma(int64(memStats.HeapObjects))

14
pages/admin/admin.scarlet Normal file
View File

@ -0,0 +1,14 @@
.admin
vertical
align-items center
.admin-widget
width 100%
max-width 500px
margin-bottom content-padding
.admin-info-key
opacity 0.6
.admin-info-value
text-align right

View File

@ -7,14 +7,14 @@ component GlobalPaymentHistory(payments []*arn.PayPalPayment)
thead
tr.mountable
th User
th Amount
th Currency
th.history-price Amount
th.history-price Currency
th.history-date Date
tbody
each payment in payments
tr.mountable
td
a(href=payment.User().Link())= payment.User().Nick
td= payment.Amount
td= payment.Currency
td.utc-date(data-date=payment.Created)
td.history-price= payment.Amount
td.history-price= payment.Currency
td.history-date.utc-date(data-date=payment.Created)