performance.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. }
  16. func GetPerformanceData() NginxPerformanceResponse {
  17. // Check if Nginx is running
  18. running := nginx.IsNginxRunning()
  19. if !running {
  20. return NginxPerformanceResponse{
  21. StubStatusEnabled: false,
  22. Running: false,
  23. Info: NginxPerformanceInfo{},
  24. }
  25. }
  26. // Get Nginx status information
  27. stubStatusEnabled, statusInfo, err := GetStubStatusData()
  28. if err != nil {
  29. logger.Warn("Failed to get Nginx status:", err)
  30. }
  31. // Get Nginx process information
  32. processInfo, err := GetNginxProcessInfo()
  33. if err != nil {
  34. logger.Warn("Failed to get Nginx process info:", err)
  35. }
  36. // Get Nginx config information
  37. configInfo, err := GetNginxWorkerConfigInfo()
  38. if err != nil {
  39. logger.Warn("Failed to get Nginx config info:", err)
  40. }
  41. // Ensure ProcessMode field is correctly passed
  42. perfInfo := NginxPerformanceInfo{
  43. StubStatusData: *statusInfo,
  44. NginxProcessInfo: *processInfo,
  45. NginxConfigInfo: *configInfo,
  46. }
  47. return NginxPerformanceResponse{
  48. StubStatusEnabled: stubStatusEnabled,
  49. Running: running,
  50. Info: perfInfo,
  51. }
  52. }