performance.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package nginx
  2. import "github.com/uozi-tech/cosy/logger"
  3. type NginxPerformanceInfo struct {
  4. StubStatusData
  5. NginxProcessInfo
  6. NginxConfigInfo
  7. }
  8. type NginxPerformanceResponse struct {
  9. StubStatusEnabled bool `json:"stub_status_enabled"`
  10. Running bool `json:"running"`
  11. Info NginxPerformanceInfo `json:"info"`
  12. }
  13. func GetPerformanceData() NginxPerformanceResponse {
  14. // Check if Nginx is running
  15. running := IsNginxRunning()
  16. if !running {
  17. return NginxPerformanceResponse{
  18. StubStatusEnabled: false,
  19. Running: false,
  20. Info: NginxPerformanceInfo{},
  21. }
  22. }
  23. // Get Nginx status information
  24. stubStatusEnabled, statusInfo, err := GetStubStatusData()
  25. if err != nil {
  26. logger.Warn("Failed to get Nginx status:", err)
  27. }
  28. // Get Nginx process information
  29. processInfo, err := GetNginxProcessInfo()
  30. if err != nil {
  31. logger.Warn("Failed to get Nginx process info:", err)
  32. }
  33. // Get Nginx config information
  34. configInfo, err := GetNginxWorkerConfigInfo()
  35. if err != nil {
  36. logger.Warn("Failed to get Nginx config info:", err)
  37. }
  38. return NginxPerformanceResponse{
  39. StubStatusEnabled: stubStatusEnabled,
  40. Running: running,
  41. Info: NginxPerformanceInfo{
  42. StubStatusData: *statusInfo,
  43. NginxProcessInfo: *processInfo,
  44. NginxConfigInfo: *configInfo,
  45. },
  46. }
  47. }