node.go 1.0 KB

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