From df49e167a9b8a693c245d90989508d78273ac43d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Wed, 20 Nov 2024 20:26:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96php=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E4=BD=BF=E7=94=A8json=E6=8E=A5=E5=8F=A3=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/apps/php/service.go | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/internal/apps/php/service.go b/internal/apps/php/service.go index 4d5fb26f..a69986b2 100644 --- a/internal/apps/php/service.go +++ b/internal/apps/php/service.go @@ -4,7 +4,6 @@ import ( "fmt" "net/http" "net/url" - "regexp" "slices" "strings" "time" @@ -93,26 +92,25 @@ func (s *Service) UpdateFPMConfig(w http.ResponseWriter, r *http.Request) { } func (s *Service) Load(w http.ResponseWriter, r *http.Request) { + var raw map[string]any client := resty.New().SetTimeout(10 * time.Second) - resp, err := client.R().Get(fmt.Sprintf("http://127.0.0.1/phpfpm_status/%d", s.version)) - if err != nil || !resp.IsSuccess() { + _, err := client.R().SetResult(&raw).Get(fmt.Sprintf("http://127.0.0.1/phpfpm_status/%d?json", s.version)) + if err != nil { service.Success(w, []types.NV{}) return } - raw := resp.String() dataKeys := []string{"应用池", "工作模式", "启动时间", "接受连接", "监听队列", "最大监听队列", "监听队列长度", "空闲进程数量", "活动进程数量", "总进程数量", "最大活跃进程数量", "达到进程上限次数", "慢请求"} - regexKeys := []string{"pool", "process manager", "start time", "accepted conn", "listen queue", "max listen queue", "listen queue len", "idle processes", "active processes", "total processes", "max active processes", "max children reached", "slow requests"} + rawKeys := []string{"pool", "process manager", "start time", "accepted conn", "listen queue", "max listen queue", "listen queue len", "idle processes", "active processes", "total processes", "max active processes", "max children reached", "slow requests"} - loads := make([]types.NV, len(dataKeys)) + loads := make([]types.NV, 0) for i := range dataKeys { - loads[i].Name = dataKeys[i] - - r := regexp.MustCompile(fmt.Sprintf("%s:\\s+(.*)", regexKeys[i])) - match := r.FindStringSubmatch(raw) - - if len(match) > 1 { - loads[i].Value = strings.TrimSpace(match[1]) + v, ok := raw[rawKeys[i]] + if ok { + loads = append(loads, types.NV{ + Name: dataKeys[i], + Value: cast.ToString(v), + }) } }