node.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/dustin/go-humanize"
  7. "github.com/gin-gonic/gin"
  8. "github.com/shirou/gopsutil/v4/cpu"
  9. "github.com/shirou/gopsutil/v4/disk"
  10. "github.com/uozi-tech/cosy"
  11. )
  12. func GetCurrentNode(c *gin.Context) {
  13. if _, ok := c.Get("Secret"); !ok {
  14. c.JSON(http.StatusNotAcceptable, gin.H{
  15. "message": "node secret not exist",
  16. })
  17. return
  18. }
  19. runtimeInfo, err := version.GetRuntimeInfo()
  20. if err != nil {
  21. cosy.ErrHandler(c, err)
  22. return
  23. }
  24. cpuInfo, _ := cpu.Info()
  25. memory, _ := analytic.GetMemoryStat()
  26. ver := version.GetVersionInfo()
  27. diskUsage, _ := disk.Usage(".")
  28. nodeInfo := analytic.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 := analytic.GetNodeStat()
  36. c.JSON(http.StatusOK, analytic.Node{
  37. NodeInfo: nodeInfo,
  38. NodeStat: stat,
  39. })
  40. }