修改dashboard页面
This commit is contained in:
@ -1,41 +1,10 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"next-terminal/pkg/model"
|
||||
"fmt"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/shirou/gopsutil/cpu"
|
||||
"github.com/shirou/gopsutil/load"
|
||||
"github.com/shirou/gopsutil/mem"
|
||||
"time"
|
||||
"next-terminal/pkg/model"
|
||||
)
|
||||
|
||||
type OverviewStatus struct {
|
||||
Load Load `json:"load"`
|
||||
Memory Memory `json:"memory"`
|
||||
CPU CPU `json:"cpu"`
|
||||
}
|
||||
|
||||
type Load struct {
|
||||
Load1 float64 `json:"load1"`
|
||||
Load5 float64 `json:"load5"`
|
||||
Load15 float64 `json:"load15"`
|
||||
}
|
||||
|
||||
type Memory struct {
|
||||
Total uint64 `json:"total"`
|
||||
Available uint64 `json:"available"`
|
||||
UsedPercent float64 `json:"usedPercent"`
|
||||
Used uint64 `json:"used"`
|
||||
}
|
||||
|
||||
type CPU struct {
|
||||
PhysicalCount int `json:"physicalCount"`
|
||||
LogicalCount int `json:"logicalCount"`
|
||||
Percent float64 `json:"percent"`
|
||||
ModelName string `json:"modelName"`
|
||||
}
|
||||
|
||||
type Counter struct {
|
||||
User int64 `json:"user"`
|
||||
Asset int64 `json:"asset"`
|
||||
@ -43,44 +12,6 @@ type Counter struct {
|
||||
OnlineSession int64 `json:"onlineSession"`
|
||||
}
|
||||
|
||||
func OverviewStatusEndPoint(c echo.Context) error {
|
||||
info, _ := load.Avg()
|
||||
memory, _ := mem.VirtualMemory()
|
||||
infoStats, _ := cpu.Info()
|
||||
physicalCount, _ := cpu.Counts(false)
|
||||
logicalCount, _ := cpu.Counts(true)
|
||||
cps, _ := cpu.Percent(time.Second, false)
|
||||
|
||||
fmt.Printf("%+v\n", info)
|
||||
fmt.Printf("%+v\n", memory)
|
||||
fmt.Printf("%+v\n", infoStats)
|
||||
fmt.Printf("%+v\n", physicalCount)
|
||||
fmt.Printf("%+v\n", logicalCount)
|
||||
fmt.Printf("%+v\n", cps)
|
||||
|
||||
overviewStatus := OverviewStatus{
|
||||
Load: Load{
|
||||
Load1: info.Load1,
|
||||
Load5: info.Load5,
|
||||
Load15: info.Load15,
|
||||
},
|
||||
Memory: Memory{
|
||||
Total: memory.Total,
|
||||
Available: memory.Available,
|
||||
UsedPercent: memory.UsedPercent,
|
||||
Used: memory.Used,
|
||||
},
|
||||
CPU: CPU{
|
||||
PhysicalCount: physicalCount,
|
||||
LogicalCount: logicalCount,
|
||||
Percent: cps[0],
|
||||
ModelName: infoStats[0].ModelName,
|
||||
},
|
||||
}
|
||||
|
||||
return Success(c, overviewStatus)
|
||||
}
|
||||
|
||||
func OverviewCounterEndPoint(c echo.Context) error {
|
||||
countUser, _ := model.CountUser()
|
||||
countOnlineSession, _ := model.CountOnlineSession()
|
||||
@ -96,3 +27,17 @@ func OverviewCounterEndPoint(c echo.Context) error {
|
||||
|
||||
return Success(c, counter)
|
||||
}
|
||||
|
||||
func OverviewSessionPoint(c echo.Context) (err error) {
|
||||
d := c.QueryParam("d")
|
||||
var results []model.D
|
||||
if d == "m" {
|
||||
results, err = model.CountSessionByDay(30)
|
||||
} else {
|
||||
results, err = model.CountSessionByDay(7)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return Success(c, results)
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"next-terminal/pkg/model"
|
||||
"fmt"
|
||||
"github.com/labstack/echo/v4"
|
||||
"next-terminal/pkg/model"
|
||||
)
|
||||
|
||||
func PropertyGetEndpoint(c echo.Context) error {
|
||||
properties := model.FindAllProperties()
|
||||
properties := model.FindAllTemp()
|
||||
return Success(c, properties)
|
||||
}
|
||||
|
||||
|
@ -97,8 +97,8 @@ func SetupRoutes() *echo.Echo {
|
||||
e.GET("/properties", PropertyGetEndpoint)
|
||||
e.PUT("/properties", PropertyUpdateEndpoint)
|
||||
|
||||
e.GET("/overview/status", OverviewStatusEndPoint)
|
||||
e.GET("/overview/counter", OverviewCounterEndPoint)
|
||||
e.GET("/overview/sessions", OverviewSessionPoint)
|
||||
|
||||
return e
|
||||
}
|
||||
|
@ -1,33 +0,0 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
//v, _ := mem.VirtualMemory()
|
||||
//c, _ := cpu.Info()
|
||||
//cc, _ := cpu.Percent(time.Second, false)
|
||||
//d, _ := disk.Usage("/")
|
||||
//n, _ := host.Info()
|
||||
//nv, _ := net.IOCounters(true)
|
||||
//boottime, _ := host.BootTime()
|
||||
//btime := time.Unix(int64(boottime), 0).Format("2006-01-02 15:04:05")
|
||||
//
|
||||
//fmt.Printf(" Mem : %v MB Free: %v MB Used:%v Usage:%f%%\n", v.Total/1024/1024, v.Available/1024/1024, v.Used/1024/1024, v.UsedPercent)
|
||||
//if len(c) > 1 {
|
||||
// for _, sub_cpu := range c {
|
||||
// modelname := sub_cpu.ModelName
|
||||
// cores := sub_cpu.Cores
|
||||
// fmt.Printf(" CPU : %v %v cores \n", modelname, cores)
|
||||
// }
|
||||
//} else {
|
||||
// sub_cpu := c[0]
|
||||
// modelname := sub_cpu.ModelName
|
||||
// cores := sub_cpu.Cores
|
||||
// fmt.Printf(" CPU : %v %v cores \n", modelname, cores)
|
||||
//
|
||||
//}
|
||||
//fmt.Printf(" Network: %v bytes / %v bytes\n", nv[0].BytesRecv, nv[0].BytesSent)
|
||||
//fmt.Printf(" SystemBoot:%v\n", btime)
|
||||
//fmt.Printf(" CPU Used : used %f%% \n", cc[0])
|
||||
//fmt.Printf(" HD : %v GB Free: %v GB Usage:%f%%\n", d.Total/1024/1024/1024, d.Free/1024/1024/1024, d.UsedPercent)
|
||||
//fmt.Printf(" OS : %v(%v) %v \n", n.Platform, n.PlatformFamily, n.PlatformVersion)
|
||||
//fmt.Printf(" Hostname : %v \n", n.Hostname)
|
||||
}
|
Reference in New Issue
Block a user