phpfpm: add socket fcgi support
This commit is contained in:
parent
e619845ffe
commit
019585f0db
|
@ -30,13 +30,14 @@ Using this configuration:
|
||||||
# An array of address to gather stats about. Specify an ip on hostname
|
# An array of address to gather stats about. Specify an ip on hostname
|
||||||
# with optional port and path. ie localhost, 10.10.3.33/server-status, etc.
|
# with optional port and path. ie localhost, 10.10.3.33/server-status, etc.
|
||||||
#
|
#
|
||||||
# We can configure int two modes:
|
# We can configure in three modes:
|
||||||
# - unixsocket: the string is the path to fpm socket like
|
# - unixsocket: the string is the path to fpm socket like
|
||||||
# /var/run/php5-fpm.sock
|
# /var/run/php5-fpm.sock
|
||||||
# - http: the URL has to start with http:// or https://
|
# - http: the URL has to start with http:// or https://
|
||||||
|
# - fcgi: the URL has to start with fcgi:// or cgi://, and socket port must present
|
||||||
#
|
#
|
||||||
# If no servers are specified, then default to 127.0.0.1/server-status
|
# If no servers are specified, then default to 127.0.0.1/server-status
|
||||||
urls = ["http://localhost/status", "10.0.0.12:/var/run/php5-fpm-www2.sock"]
|
urls = ["http://localhost/status", "10.0.0.12:/var/run/php5-fpm-www2.sock", "fcgi://10.0.0.12:9000/status"]
|
||||||
```
|
```
|
||||||
|
|
||||||
When run with:
|
When run with:
|
||||||
|
@ -70,4 +71,15 @@ It produces:
|
||||||
> [url="localhost" pool="www2"] phpfpm_max_active_processes value=2
|
> [url="localhost" pool="www2"] phpfpm_max_active_processes value=2
|
||||||
> [url="localhost" pool="www2"] phpfpm_accepted_conn value=306
|
> [url="localhost" pool="www2"] phpfpm_accepted_conn value=306
|
||||||
> [url="localhost" pool="www2"] phpfpm_listen_queue value=0
|
> [url="localhost" pool="www2"] phpfpm_listen_queue value=0
|
||||||
|
|
||||||
|
> [url="10.0.0.12:9000" pool="www3"] phpfpm_max_children_reached value=0
|
||||||
|
> [url="10.0.0.12:9000" pool="www3"] phpfpm_slow_requests value=1
|
||||||
|
> [url="10.0.0.12:9000" pool="www3"] phpfpm_max_listen_queue value=0
|
||||||
|
> [url="10.0.0.12:9000" pool="www3"] phpfpm_active_processes value=1
|
||||||
|
> [url="10.0.0.12:9000" pool="www3"] phpfpm_listen_queue_len value=0
|
||||||
|
> [url="10.0.0.12:9000" pool="www3"] phpfpm_idle_processes value=2
|
||||||
|
> [url="10.0.0.12:9000" pool="www3"] phpfpm_total_processes value=2
|
||||||
|
> [url="10.0.0.12:9000" pool="www3"] phpfpm_max_active_processes value=2
|
||||||
|
> [url="10.0.0.12:9000" pool="www3"] phpfpm_accepted_conn value=307
|
||||||
|
> [url="10.0.0.12:9000" pool="www3"] phpfpm_listen_queue value=0
|
||||||
```
|
```
|
||||||
|
|
|
@ -42,13 +42,16 @@ var sampleConfig = `
|
||||||
# An array of addresses to gather stats about. Specify an ip or hostname
|
# An array of addresses to gather stats about. Specify an ip or hostname
|
||||||
# with optional port and path.
|
# with optional port and path.
|
||||||
#
|
#
|
||||||
# Plugin can be configured in two modes (both can be used):
|
# Plugin can be configured in three modes (both can be used):
|
||||||
# - http: the URL must start with http:// or https://, ex:
|
# - http: the URL must start with http:// or https://, ex:
|
||||||
# "http://localhost/status"
|
# "http://localhost/status"
|
||||||
# "http://192.168.130.1/status?full"
|
# "http://192.168.130.1/status?full"
|
||||||
# - unixsocket: path to fpm socket, ex:
|
# - unixsocket: path to fpm socket, ex:
|
||||||
# "/var/run/php5-fpm.sock"
|
# "/var/run/php5-fpm.sock"
|
||||||
# "192.168.10.10:/var/run/php5-fpm-www2.sock"
|
# "192.168.10.10:/var/run/php5-fpm-www2.sock"
|
||||||
|
# - fcgi: the URL mush start with fcgi:// or cgi://, and port must present, ex:
|
||||||
|
# "fcgi://10.0.0.12:9000/status"
|
||||||
|
# "cgi://10.0.10.12:9001/status"
|
||||||
#
|
#
|
||||||
# If no servers are specified, then default to 127.0.0.1/server-status
|
# If no servers are specified, then default to 127.0.0.1/server-status
|
||||||
urls = ["http://localhost/status"]
|
urls = ["http://localhost/status"]
|
||||||
|
@ -114,10 +117,26 @@ func (g *phpfpm) gatherServer(addr string, acc plugins.Accumulator) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
importMetric(res.Body, acc, u.Host)
|
importMetric(res.Body, acc, u.Host)
|
||||||
|
} else {
|
||||||
|
var (
|
||||||
|
fcgi *FCGIClient
|
||||||
|
fcgiAddr string
|
||||||
|
)
|
||||||
|
if strings.HasPrefix(addr, "fcgi://") || strings.HasPrefix(addr, "cgi://") {
|
||||||
|
u, err := url.Parse(addr)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Unable parse server address '%s': %s", addr, err)
|
||||||
|
}
|
||||||
|
socketAddr := strings.Split(u.Host, ":")
|
||||||
|
fcgiIp := socketAddr[0]
|
||||||
|
fcgiPort, _ := strconv.Atoi(socketAddr[1])
|
||||||
|
fcgiAddr = u.Host
|
||||||
|
fcgi, _ = NewClient(fcgiIp, fcgiPort)
|
||||||
} else {
|
} else {
|
||||||
socketAddr := strings.Split(addr, ":")
|
socketAddr := strings.Split(addr, ":")
|
||||||
|
fcgiAddr = socketAddr[0]
|
||||||
fcgi, _ := NewClient("unix", socketAddr[1])
|
fcgi, _ = NewClient("unix", socketAddr[1])
|
||||||
|
}
|
||||||
resOut, resErr, err := fcgi.Request(map[string]string{
|
resOut, resErr, err := fcgi.Request(map[string]string{
|
||||||
"SCRIPT_NAME": "/status",
|
"SCRIPT_NAME": "/status",
|
||||||
"SCRIPT_FILENAME": "status",
|
"SCRIPT_FILENAME": "status",
|
||||||
|
@ -125,7 +144,7 @@ func (g *phpfpm) gatherServer(addr string, acc plugins.Accumulator) error {
|
||||||
}, "")
|
}, "")
|
||||||
|
|
||||||
if len(resErr) == 0 && err == nil {
|
if len(resErr) == 0 && err == nil {
|
||||||
importMetric(bytes.NewReader(resOut), acc, socketAddr[0])
|
importMetric(bytes.NewReader(resOut), acc, fcgiAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue