mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 18:35:51 +02:00
feat: add field of nginx worker processes mode
This commit is contained in:
parent
d487af0567
commit
bdb347cb24
8 changed files with 36 additions and 20 deletions
|
@ -51,6 +51,7 @@ export interface NginxPerformanceInfo {
|
|||
memory_usage: number // 内存使用率(MB)
|
||||
worker_processes: number // worker_processes 配置
|
||||
worker_connections: number // worker_connections 配置
|
||||
process_mode: string // worker进程配置模式:'auto'或'manual'
|
||||
}
|
||||
|
||||
const ngx = {
|
||||
|
@ -74,6 +75,10 @@ const ngx = {
|
|||
return http.get('/nginx/detail_status')
|
||||
},
|
||||
|
||||
toggle_stub_status(enable: boolean): Promise<{ stub_status_enabled: boolean, error: string }> {
|
||||
return http.post('/nginx/stub_status', { enable })
|
||||
},
|
||||
|
||||
reload() {
|
||||
return http.post('/nginx/reload')
|
||||
},
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import type { NginxPerformanceInfo } from '@/api/ngx'
|
||||
import ngx from '@/api/ngx'
|
||||
import { fromNow } from '@/lib/helper'
|
||||
|
||||
export function useNginxPerformance() {
|
||||
const loading = ref(false)
|
||||
|
@ -17,7 +16,7 @@ export function useNginxPerformance() {
|
|||
const formattedUpdateTime = computed(() => {
|
||||
if (!lastUpdateTime.value)
|
||||
return $gettext('Unknown')
|
||||
return fromNow(lastUpdateTime.value.toLocaleString())
|
||||
return lastUpdateTime.value.toLocaleString()
|
||||
})
|
||||
|
||||
// Update the last update time
|
||||
|
|
|
@ -5,13 +5,12 @@ import { NginxStatus } from '@/constants'
|
|||
import { useUserStore } from '@/pinia'
|
||||
import { useGlobalStore } from '@/pinia/moudule/global'
|
||||
import { ClockCircleOutlined, ReloadOutlined } from '@ant-design/icons-vue'
|
||||
import axios from 'axios'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import ConnectionMetricsCard from './components/ConnectionMetricsCard.vue'
|
||||
import PerformanceStatisticsCard from './components/PerformanceStatisticsCard.vue'
|
||||
import PerformanceTablesCard from './components/PerformanceTablesCard.vue'
|
||||
import ProcessDistributionCard from './components/ProcessDistributionCard.vue'
|
||||
import ResourceUsageCard from './components/ResourceUsageCard.vue'
|
||||
import ngx from '@/api/ngx'
|
||||
|
||||
// Global state
|
||||
const global = useGlobalStore()
|
||||
|
@ -39,16 +38,14 @@ async function toggleStubStatus() {
|
|||
try {
|
||||
stubStatusLoading.value = true
|
||||
stubStatusError.value = ''
|
||||
const response = await axios.post('/api/nginx/stub_status', {
|
||||
enable: !stubStatusEnabled.value,
|
||||
})
|
||||
const response = await ngx.toggle_stub_status(!stubStatusEnabled.value)
|
||||
|
||||
if (response.data.stub_status_enabled !== undefined) {
|
||||
stubStatusEnabled.value = response.data.stub_status_enabled
|
||||
if (response.stub_status_enabled !== undefined) {
|
||||
stubStatusEnabled.value = response.stub_status_enabled
|
||||
}
|
||||
|
||||
if (response.data.error) {
|
||||
stubStatusError.value = response.data.error
|
||||
if (response.error) {
|
||||
stubStatusError.value = response.error
|
||||
}
|
||||
else {
|
||||
fetchInitialData().then(connectSSE)
|
||||
|
|
|
@ -196,7 +196,11 @@ const maxRPS = computed(() => {
|
|||
{{ $gettext('Maximum worker process number:') }}
|
||||
<strong>{{ nginxInfo.worker_processes }}</strong>
|
||||
<span class="text-gray-500 text-xs ml-2">
|
||||
{{ nginxInfo.worker_processes === nginxInfo.workers ? $gettext('auto = CPU cores') : $gettext('manually set') }}
|
||||
{{
|
||||
nginxInfo.process_mode === 'auto'
|
||||
? $gettext('auto = CPU cores')
|
||||
: $gettext('manually set')
|
||||
}}
|
||||
</span>
|
||||
</p>
|
||||
<p class="mb-0">
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
type NginxConfigInfo struct {
|
||||
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"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,13 +43,16 @@ func GetPerformanceData() NginxPerformanceResponse {
|
|||
logger.Warn("Failed to get Nginx config info:", err)
|
||||
}
|
||||
|
||||
return NginxPerformanceResponse{
|
||||
StubStatusEnabled: stubStatusEnabled,
|
||||
Running: running,
|
||||
Info: NginxPerformanceInfo{
|
||||
// 确保ProcessMode字段能够正确传递
|
||||
perfInfo := NginxPerformanceInfo{
|
||||
StubStatusData: *statusInfo,
|
||||
NginxProcessInfo: *processInfo,
|
||||
NginxConfigInfo: *configInfo,
|
||||
},
|
||||
}
|
||||
|
||||
return NginxPerformanceResponse{
|
||||
StubStatusEnabled: stubStatusEnabled,
|
||||
Running: running,
|
||||
Info: perfInfo,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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++
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue