node.go 920 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package api
  2. import (
  3. "github.com/0xJacky/Nginx-UI/server/service"
  4. "github.com/dustin/go-humanize"
  5. "github.com/gin-gonic/gin"
  6. "github.com/shirou/gopsutil/v3/cpu"
  7. "github.com/shirou/gopsutil/v3/disk"
  8. "net/http"
  9. )
  10. func GetCurrentNode(c *gin.Context) {
  11. if _, ok := c.Get("NodeSecret"); !ok {
  12. c.JSON(http.StatusNotAcceptable, gin.H{
  13. "message": "node secret not exist",
  14. })
  15. return
  16. }
  17. runtimeInfo, err := service.GetRuntimeInfo()
  18. if err != nil {
  19. ErrHandler(c, err)
  20. return
  21. }
  22. cpuInfo, _ := cpu.Info()
  23. memory, _ := getMemoryStat()
  24. ver, _ := service.GetCurrentVersion()
  25. diskUsage, _ := disk.Usage(".")
  26. c.JSON(http.StatusOK, gin.H{
  27. "request_node_secret": c.MustGet("NodeSecret"),
  28. "node_runtime_info": runtimeInfo,
  29. "cpu_num": len(cpuInfo),
  30. "memory_total": memory.Total,
  31. "disk_total": humanize.Bytes(diskUsage.Total),
  32. "version": ver.Version,
  33. })
  34. }