1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package cluster
- import (
- "net/http"
- "github.com/0xJacky/Nginx-UI/internal/analytic"
- "github.com/0xJacky/Nginx-UI/internal/version"
- "github.com/dustin/go-humanize"
- "github.com/gin-gonic/gin"
- "github.com/shirou/gopsutil/v4/cpu"
- "github.com/shirou/gopsutil/v4/disk"
- "github.com/uozi-tech/cosy"
- )
- func GetCurrentNode(c *gin.Context) {
- if _, ok := c.Get("Secret"); !ok {
- c.JSON(http.StatusNotAcceptable, gin.H{
- "message": "node secret not exist",
- })
- return
- }
- runtimeInfo, err := version.GetRuntimeInfo()
- if err != nil {
- cosy.ErrHandler(c, err)
- return
- }
- cpuInfo, _ := cpu.Info()
- memory, _ := analytic.GetMemoryStat()
- ver := version.GetVersionInfo()
- diskUsage, _ := disk.Usage(".")
- nodeInfo := analytic.NodeInfo{
- NodeRuntimeInfo: runtimeInfo,
- CPUNum: len(cpuInfo),
- MemoryTotal: memory.Total,
- DiskTotal: humanize.Bytes(diskUsage.Total),
- Version: ver.Version,
- }
- stat := analytic.GetNodeStat()
- c.JSON(http.StatusOK, analytic.Node{
- NodeInfo: nodeInfo,
- NodeStat: stat,
- })
- }
|