mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 10:25:52 +02:00
refactor: structure of api-router directory
This commit is contained in:
parent
d272f7900f
commit
50b4fbcda4
38 changed files with 610 additions and 524 deletions
46
api/cluster/node.go
Normal file
46
api/cluster/node.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
package cluster
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
analytic2 "github.com/0xJacky/Nginx-UI/internal/analytic"
|
||||
"github.com/0xJacky/Nginx-UI/internal/upgrader"
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/shirou/gopsutil/v3/cpu"
|
||||
"github.com/shirou/gopsutil/v3/disk"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetCurrentNode(c *gin.Context) {
|
||||
if _, ok := c.Get("NodeSecret"); !ok {
|
||||
c.JSON(http.StatusNotAcceptable, gin.H{
|
||||
"message": "node secret not exist",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
runtimeInfo, err := upgrader.GetRuntimeInfo()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
cpuInfo, _ := cpu.Info()
|
||||
memory, _ := analytic2.GetMemoryStat()
|
||||
ver, _ := upgrader.GetCurrentVersion()
|
||||
diskUsage, _ := disk.Usage(".")
|
||||
|
||||
nodeInfo := analytic2.NodeInfo{
|
||||
NodeRuntimeInfo: runtimeInfo,
|
||||
CPUNum: len(cpuInfo),
|
||||
MemoryTotal: memory.Total,
|
||||
DiskTotal: humanize.Bytes(diskUsage.Total),
|
||||
Version: ver.Version,
|
||||
}
|
||||
|
||||
stat := analytic2.GetNodeStat()
|
||||
|
||||
c.JSON(http.StatusOK, analytic2.Node{
|
||||
NodeInfo: nodeInfo,
|
||||
NodeStat: stat,
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue