node.go 965 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package cluster
  2. import (
  3. "net/http"
  4. "github.com/0xJacky/Nginx-UI/internal/analytic"
  5. "github.com/0xJacky/Nginx-UI/internal/version"
  6. "github.com/gin-gonic/gin"
  7. "github.com/shirou/gopsutil/v4/cpu"
  8. "github.com/uozi-tech/cosy"
  9. )
  10. func GetCurrentNode(c *gin.Context) {
  11. if _, ok := c.Get("Secret"); !ok {
  12. c.JSON(http.StatusNotAcceptable, gin.H{
  13. "message": "node secret not exist",
  14. })
  15. return
  16. }
  17. runtimeInfo, err := version.GetRuntimeInfo()
  18. if err != nil {
  19. cosy.ErrHandler(c, err)
  20. return
  21. }
  22. cpuInfo, _ := cpu.Info()
  23. memory, _ := analytic.GetMemoryStat()
  24. ver := version.GetVersionInfo()
  25. diskUsage, _ := analytic.GetDiskStat()
  26. nodeInfo := analytic.NodeInfo{
  27. NodeRuntimeInfo: runtimeInfo,
  28. CPUNum: len(cpuInfo),
  29. MemoryTotal: memory.Total,
  30. DiskTotal: diskUsage.Total,
  31. Version: ver.Version,
  32. }
  33. stat := analytic.GetNodeStat()
  34. c.JSON(http.StatusOK, analytic.Node{
  35. NodeInfo: nodeInfo,
  36. NodeStat: stat,
  37. })
  38. }