62 lines
1.2 KiB
Go
Raw Normal View History

2017-06-18 15:16:40 +00:00
package admin
import (
"github.com/aerogo/aero"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
2017-10-02 12:28:10 +00:00
"github.com/shirou/gopsutil/host"
2017-06-18 15:16:40 +00:00
)
// Get admin page.
func Get(ctx *aero.Context) string {
user := utils.GetUser(ctx)
2017-10-02 12:56:51 +00:00
if user == nil || (user.Role != "admin" && user.Role != "editor") {
2017-06-18 15:16:40 +00:00
return ctx.Redirect("/")
}
2017-11-03 08:34:21 +00:00
// // CPU
// cpuUsage := 0.0
// cpuUsages, err := cpu.Percent(1*time.Second, false)
2017-10-02 12:28:10 +00:00
2017-11-03 08:34:21 +00:00
// if err == nil {
// cpuUsage = cpuUsages[0]
// }
2017-10-02 12:28:10 +00:00
2017-11-03 08:34:21 +00:00
// // Memory
// memUsage := 0.0
// memInfo, _ := mem.VirtualMemory()
2017-10-02 12:28:10 +00:00
2017-11-03 08:34:21 +00:00
// if err == nil {
// memUsage = memInfo.UsedPercent
// }
2017-10-02 12:28:10 +00:00
2017-11-03 08:34:21 +00:00
// // Disk
// diskUsage := 0.0
// diskInfo, err := disk.Usage("/")
2017-10-02 12:28:10 +00:00
2017-11-03 08:34:21 +00:00
// if err == nil {
// diskUsage = diskInfo.UsedPercent
// }
2017-10-02 12:28:10 +00:00
// Host
platform, family, platformVersion, _ := host.PlatformInformation()
2017-11-03 08:34:21 +00:00
kernelVersion, _ := host.KernelVersion()
2017-10-02 12:28:10 +00:00
2017-11-03 08:34:21 +00:00
return ctx.HTML(components.Admin(user, platform, family, platformVersion, kernelVersion))
2017-10-02 12:28:10 +00:00
}
func average(floatSlice []float64) float64 {
if len(floatSlice) == 0 {
2017-11-03 08:34:21 +00:00
return 0
2017-10-02 12:28:10 +00:00
}
var sum float64
for _, value := range floatSlice {
sum += value
}
return sum / float64(len(floatSlice))
2017-06-18 15:16:40 +00:00
}