1
0

node.go 1.1 KB

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