Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New PHP-FPM metricbeat module #3415

Merged
merged 10 commits into from
Jan 24, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
PR review: refactor data structures
Thiago Souza committed Jan 21, 2017
commit 70478068ed15aaef86754f5a6f4069825f8dd15c
42 changes: 1 addition & 41 deletions metricbeat/module/php_fpm/php_fpm.go
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ const (
var HostParser = parse.URLHostParserBuilder{
DefaultScheme: defaultScheme,
DefaultPath: defaultPath,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To define a config option to change the defaultPath you can use PathConfigKey. See https://github.com/elastic/beats/blob/master/metricbeat/module/prometheus/collector/collector.go#L25 as an example. I would suggest to use path or status_path as the config option. All other parts are done automatically by the HostParser.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

PathConfigKey: "status_path",
}.Build()

// StatsClient provides access to php-fpm stats api
@@ -60,44 +61,3 @@ func (c *StatsClient) Fetch() (io.ReadCloser, error) {

return resp.Body, nil
}

// PoolStats defines all stats fields from a php-fpm pool
type PoolStats struct {
Pool string `json:"pool"`
ProcessManager string `json:"process manager"`
StartTime int `json:"start time"`
StartSince int `json:"start since"`
AcceptedConn int `json:"accepted conn"`
ListenQueue int `json:"listen queue"`
MaxListQueue int `json:"max list queue"`
ListenQueueLen int `json:"listen queue len"`
IdleProcesses int `json:"idle processes"`
ActiveProcesses int `json:"active processes"`
TotalProcesses int `json:"total processes"`
MaxActiveProcesses int `json:"max active processes"`
MaxChildrenReached int `json:"max children reached"`
SlowRequests int `json:"slow requests"`
}

// ProcStats defines all stats fields from a process in php-fpm pool
type ProcStats struct {
Pid int `json:"pid"`
State string `json:"state"`
StartTime int `json:"start time"`
StartSince int `json:"start since"`
Requests int `json:"requests"`
RequestDuration int `json:"request duration"`
RequestMethod string `json:"request method"`
RequestURI string `json:"request uri"`
ContentLength int `json:"content length"`
User string `json:"user"`
Script string `json:"script"`
LastRequestCPU float64 `json:"last request cpu"`
LastRequestMemory int `json:"last request memory"`
}

// FullStats defines all stats fields of the full stats api call (pool + processes)
type FullStats struct {
PoolStats
Processes []ProcStats `json:"processes"`
}
18 changes: 18 additions & 0 deletions metricbeat/module/php_fpm/pool/data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package pool

type poolStats struct {
Pool string `json:"pool"`
ProcessManager string `json:"process manager"`
StartTime int `json:"start time"`
StartSince int `json:"start since"`
AcceptedConn int `json:"accepted conn"`
ListenQueue int `json:"listen queue"`
MaxListQueue int `json:"max list queue"`
ListenQueueLen int `json:"listen queue len"`
IdleProcesses int `json:"idle processes"`
ActiveProcesses int `json:"active processes"`
TotalProcesses int `json:"total processes"`
MaxActiveProcesses int `json:"max active processes"`
MaxChildrenReached int `json:"max children reached"`
SlowRequests int `json:"slow requests"`
}
11 changes: 3 additions & 8 deletions metricbeat/module/php_fpm/pool/pool.go
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import (
"fmt"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/metricbeat/mb"

"github.com/elastic/beats/metricbeat/module/php_fpm"
@@ -31,13 +32,7 @@ type MetricSet struct {
// Part of new is also setting up the configuration by processing additional
// configuration entries if needed.
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {

config := struct{}{}

if err := base.Module().UnpackConfig(&config); err != nil {
return nil, err
}

logp.Warn("EXPERIMENTAL: The php-fpm pool metricset is experimental")
return &MetricSet{
BaseMetricSet: base,
client: php_fpm.NewStatsClient(base, false),
@@ -56,7 +51,7 @@ func (m *MetricSet) Fetch() (common.MapStr, error) {

defer body.Close()

stats := &php_fpm.PoolStats{}
stats := &poolStats{}
err = json.NewDecoder(body).Decode(stats)
if err != nil {
return nil, fmt.Errorf("error parsing json: %v", err)
21 changes: 21 additions & 0 deletions metricbeat/module/php_fpm/proc/data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package proc

type procStats struct {
Pid int `json:"pid"`
State string `json:"state"`
StartTime int `json:"start time"`
StartSince int `json:"start since"`
Requests int `json:"requests"`
RequestDuration int `json:"request duration"`
RequestMethod string `json:"request method"`
RequestURI string `json:"request uri"`
ContentLength int `json:"content length"`
User string `json:"user"`
Script string `json:"script"`
LastRequestCPU float64 `json:"last request cpu"`
LastRequestMemory int `json:"last request memory"`
}

type fullStats struct {
Processes []procStats `json:"processes"`
}
11 changes: 3 additions & 8 deletions metricbeat/module/php_fpm/proc/proc.go
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import (
"strconv"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/metricbeat/mb"

"github.com/elastic/beats/metricbeat/module/php_fpm"
@@ -32,13 +33,7 @@ type MetricSet struct {
// Part of new is also setting up the configuration by processing additional
// configuration entries if needed.
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {

config := struct{}{}

if err := base.Module().UnpackConfig(&config); err != nil {
return nil, err
}

logp.Warn("EXPERIMENTAL: The php-fpm proc metricset is experimental")
return &MetricSet{
BaseMetricSet: base,
client: php_fpm.NewStatsClient(base, true),
@@ -57,7 +52,7 @@ func (m *MetricSet) Fetch() ([]common.MapStr, error) {

defer body.Close()

stats := &php_fpm.FullStats{}
stats := &fullStats{}
err = json.NewDecoder(body).Decode(stats)
if err != nil {
return nil, fmt.Errorf("error parsing json: %v", err)