feat: add field of nginx worker processes mode

This commit is contained in:
Akino 2025-04-10 13:53:39 +00:00
parent d487af0567
commit bdb347cb24
No known key found for this signature in database
GPG key ID: FB2F74D193A40907
8 changed files with 36 additions and 20 deletions

View file

@ -10,8 +10,9 @@ import (
)
type NginxConfigInfo struct {
WorkerProcesses int `json:"worker_processes"`
WorkerConnections int `json:"worker_connections"`
WorkerProcesses int `json:"worker_processes"`
WorkerConnections int `json:"worker_connections"`
ProcessMode string `json:"process_mode"`
}
// GetNginxWorkerConfigInfo Get Nginx config info of worker_processes and worker_connections
@ -19,6 +20,7 @@ func GetNginxWorkerConfigInfo() (*NginxConfigInfo, error) {
result := &NginxConfigInfo{
WorkerProcesses: 1,
WorkerConnections: 1024,
ProcessMode: "manual",
}
// Get worker_processes config
@ -33,8 +35,10 @@ func GetNginxWorkerConfigInfo() (*NginxConfigInfo, error) {
if matches := wpRe.FindStringSubmatch(string(output)); len(matches) > 1 {
if matches[1] == "auto" {
result.WorkerProcesses = runtime.NumCPU()
result.ProcessMode = "auto"
} else {
result.WorkerProcesses, _ = strconv.Atoi(matches[1])
result.ProcessMode = "manual"
}
}

View file

@ -43,13 +43,16 @@ func GetPerformanceData() NginxPerformanceResponse {
logger.Warn("Failed to get Nginx config info:", err)
}
// 确保ProcessMode字段能够正确传递
perfInfo := NginxPerformanceInfo{
StubStatusData: *statusInfo,
NginxProcessInfo: *processInfo,
NginxConfigInfo: *configInfo,
}
return NginxPerformanceResponse{
StubStatusEnabled: stubStatusEnabled,
Running: running,
Info: NginxPerformanceInfo{
StubStatusData: *statusInfo,
NginxProcessInfo: *processInfo,
NginxConfigInfo: *configInfo,
},
Info: perfInfo,
}
}

View file

@ -8,6 +8,7 @@ import (
"time"
"github.com/shirou/gopsutil/v4/process"
"github.com/uozi-tech/cosy/logger"
)
type NginxProcessInfo struct {
@ -120,6 +121,7 @@ func GetNginxProcessInfo() (*NginxProcessInfo, error) {
// Distinguish between worker processes, cache processes, and other processes
if ppid == masterPID || strings.Contains(cmdline, "worker process") {
logger.Debug(cmdline)
workerCount++
} else if strings.Contains(cmdline, "cache") {
cacheCount++

View file

@ -11,6 +11,7 @@ import (
"time"
"github.com/pkg/errors"
"github.com/uozi-tech/cosy/logger"
)
// StubStatusInfo Store the stub_status module status
@ -32,7 +33,7 @@ type StubStatusData struct {
const (
StubStatusPort = 51828
StubStatusPath = "/stub_status"
StubStatusHost = "localhost"
StubStatusHost = "127.0.0.1"
StubStatusProtocol = "http"
StubStatusAllow = "127.0.0.1"
StubStatusDeny = "all"
@ -53,6 +54,7 @@ func GetStubStatusData() (bool, *StubStatusData, error) {
// Get the stub_status status information
enabled, statusURL := IsStubStatusEnabled()
logger.Info("GetStubStatusData", "enabled", enabled, "statusURL", statusURL)
if !enabled {
return false, result, fmt.Errorf("stub_status is not enabled")
}