Skip to content

Commit

Permalink
Merge pull request #1254 from kmuto/php8.4-fpm
Browse files Browse the repository at this point in the history
support memory peak value which is introduced in PHP 8.4 on mackerel-plugin-php-fpm
  • Loading branch information
kmuto authored Feb 19, 2025
2 parents 43d16b2 + 33a25d6 commit 673f952
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
18 changes: 16 additions & 2 deletions mackerel-plugin-php-fpm/lib/php-fpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ type PhpFpmStatus struct {
MaxActiveProcesses uint64 `json:"max active processes"`
MaxChildrenReached uint64 `json:"max children reached"`
SlowRequests uint64 `json:"slow requests"`
MemoryPeak uint64 `json:"memory peak"`
}

// MetricKeyPrefix interface for PluginWithPrefix
Expand Down Expand Up @@ -186,6 +187,13 @@ func (p PhpFpmPlugin) GraphDefinition() map[string]mp.Graphs {
{Name: "slow_requests_delta", Label: "Slow Requests Delta", Diff: true, Type: "uint64"},
},
},
"memory_peak": {
Label: p.LabelPrefix + " Memory Peak",
Unit: "bytes",
Metrics: []mp.Metrics{
{Name: "memory_peak", Label: "Memory Peak", Diff: false, Type: "uint64"},
},
},
}
}

Expand All @@ -196,7 +204,7 @@ func (p PhpFpmPlugin) FetchMetrics() (map[string]interface{}, error) {
return nil, fmt.Errorf("Failed to fetch PHP-FPM metrics: %s", err)
}

return map[string]interface{}{
result := map[string]interface{}{
"total_processes": status.TotalProcesses,
"active_processes": status.ActiveProcesses,
"idle_processes": status.IdleProcesses,
Expand All @@ -207,7 +215,13 @@ func (p PhpFpmPlugin) FetchMetrics() (map[string]interface{}, error) {
"max_listen_queue": status.MaxListenQueue,
"slow_requests": status.SlowRequests,
"slow_requests_delta": status.SlowRequests,
}, nil
}

if status.MemoryPeak > 0 {
result["memory_peak"] = status.MemoryPeak
}

return result, nil
}

func getStatus(p PhpFpmPlugin) (*PhpFpmStatus, error) {
Expand Down
37 changes: 37 additions & 0 deletions mackerel-plugin-php-fpm/lib/php-fpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,43 @@ func TestGetStatus(t *testing.T) {
assert.EqualValues(t, 2, status.ListenQueueLen)
assert.EqualValues(t, 3, status.MaxListenQueue)
assert.EqualValues(t, 1000, status.SlowRequests)
assert.EqualValues(t, 0, status.MemoryPeak)
}

func TestGetStatus_MemoryPeak(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()

jsonStr := `{
"pool":"www",
"process manager":"dynamic",
"start time":1461398921,
"start since":1624,
"accepted conn":664,
"listen queue":1,
"max listen queue":3,
"listen queue len":2,
"idle processes":40,
"active processes":10,
"total processes":50,
"max active processes":100,
"max children reached":200,
"slow requests":1000,
"memory peak":1280000
}`

httpmock.RegisterResponder("GET", "http://httpmock/status",
httpmock.NewStringResponder(200, jsonStr))

p := PhpFpmPlugin{
URL: "http://httpmock/status",
Prefix: "php-fpm",
Timeout: 5,
}
status, err := getStatus(p)

require.NoError(t, err)
assert.EqualValues(t, 1280000, status.MemoryPeak)
}

func TestSocketFlag_Set(t *testing.T) {
Expand Down

0 comments on commit 673f952

Please sign in to comment.