performance.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package performance
  2. import (
  3. "github.com/0xJacky/Nginx-UI/internal/nginx"
  4. "github.com/uozi-tech/cosy/logger"
  5. )
  6. type NginxPerformanceInfo struct {
  7. StubStatusData
  8. NginxProcessInfo
  9. NginxConfigInfo
  10. }
  11. type NginxPerformanceResponse struct {
  12. StubStatusEnabled bool `json:"stub_status_enabled"`
  13. Running bool `json:"running"`
  14. Info NginxPerformanceInfo `json:"info"`
  15. Error string `json:"error"`
  16. }
  17. func GetPerformanceData() NginxPerformanceResponse {
  18. // Check if Nginx is running
  19. running := nginx.IsRunning()
  20. if !running {
  21. return NginxPerformanceResponse{
  22. StubStatusEnabled: false,
  23. Running: false,
  24. Info: NginxPerformanceInfo{},
  25. }
  26. }
  27. // Get Nginx status information
  28. stubStatusEnabled, statusInfo, err := GetStubStatusData()
  29. if err != nil {
  30. logger.Warn("Failed to get Nginx status:", err)
  31. return NginxPerformanceResponse{
  32. StubStatusEnabled: false,
  33. Running: running,
  34. Info: NginxPerformanceInfo{},
  35. Error: err.Error(),
  36. }
  37. }
  38. // Get Nginx process information
  39. processInfo, err := GetNginxProcessInfo()
  40. if err != nil {
  41. logger.Warn("Failed to get Nginx process info:", err)
  42. return NginxPerformanceResponse{
  43. StubStatusEnabled: stubStatusEnabled,
  44. Running: running,
  45. Info: NginxPerformanceInfo{},
  46. Error: err.Error(),
  47. }
  48. }
  49. // Get Nginx config information
  50. configInfo, err := GetNginxWorkerConfigInfo()
  51. if err != nil {
  52. logger.Warn("Failed to get Nginx config info:", err)
  53. return NginxPerformanceResponse{
  54. StubStatusEnabled: stubStatusEnabled,
  55. Running: running,
  56. Info: NginxPerformanceInfo{},
  57. Error: err.Error(),
  58. }
  59. }
  60. // Ensure ProcessMode field is correctly passed
  61. perfInfo := NginxPerformanceInfo{
  62. StubStatusData: *statusInfo,
  63. NginxProcessInfo: *processInfo,
  64. NginxConfigInfo: *configInfo,
  65. }
  66. return NginxPerformanceResponse{
  67. StubStatusEnabled: stubStatusEnabled,
  68. Running: running,
  69. Info: perfInfo,
  70. }
  71. }