Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ To use the HTTP endpoint you must pass through `/status` in your webserver
and configure php-fpm to handle status requests. Example for nginx: https://easyengine.io/tutorials/php/fpm-status-page/

To use Fastcgi, set `--fastcgi` to a url such as `tcp://127.0.0.1:9090/status` if php-fpm is listening on a tcp socket or
`unix:///path/to/php.sock` for a unix socket. Note: php-fpm must be configured to use `/status` if using a unix socket, `php-fpm-exporter` does not currently support changing this.
`unix:///path/to/php.sock` for a unix socket.

When using a unix socket, you can change the path to use for php-status by using a URL fragment. If you have php-fpm configured to use
`/fpm-status` as your status path, then you would use the flag like `--fastcgi="unix:///path/to/php.sock#/fpm-status`

Metrics
=======
Expand Down
4 changes: 2 additions & 2 deletions cmd/php-fpm-exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
func main() {
var (
addr = kingpin.Flag("addr", "listen address for metrics handler").Default("127.0.0.1:8080").String()
endpoint = kingpin.Flag("endpoint", "url for php-fpm status").Default("http://127.0.0.1:9000/status").String()
fcgiEndpoint = kingpin.Flag("fastcgi", "fastcgi url. If this is set, fastcgi will be used instead of HTTP").String()
endpoint = kingpin.Flag("endpoint", "url for php-fpm status").Default("http://127.0.0.1:9000/status").URL()
fcgiEndpoint = kingpin.Flag("fastcgi", "fastcgi url. If this is set, fastcgi will be used instead of HTTP").URL()
metricsEndpoint = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics. Cannot be /").Default("/metrics").String()
)

Expand Down
6 changes: 5 additions & 1 deletion collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,12 @@ func getDataFastcgi(u *url.URL) ([]byte, error) {
host := u.Host

if path == "" || u.Scheme == "unix" {
path = "/status"
path = u.Fragment
if path == "" {
path = "/status"
}
}

if u.Scheme == "unix" {
host = u.Path
}
Expand Down
18 changes: 2 additions & 16 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,8 @@ func SetAddress(addr string) func(*Exporter) error {
// SetEndpoint creates a function that will set the URL endpoint to contact
// php-fpm.
// Generally only used when create a new Exporter.
func SetEndpoint(rawurl string) func(*Exporter) error {
func SetEndpoint(u *url.URL) func(*Exporter) error {
return func(e *Exporter) error {
if rawurl == "" {
return nil
}
u, err := url.Parse(rawurl)
if err != nil {
return errors.Wrap(err, "failed to parse url")
}
e.endpoint = u
return nil
}
Expand All @@ -98,15 +91,8 @@ func SetEndpoint(rawurl string) func(*Exporter) error {
// SetFastcgi creates a function that will set the fastcgi URL endpoint to contact
// php-fpm. If this is set, then fastcgi is used rather than HTTP.
// Generally only used when create a new Exporter.
func SetFastcgi(rawurl string) func(*Exporter) error {
func SetFastcgi(u *url.URL) func(*Exporter) error {
return func(e *Exporter) error {
if rawurl == "" {
return nil
}
u, err := url.Parse(rawurl)
if err != nil {
return errors.Wrap(err, "failed to parse url")
}
e.fcgiEndpoint = u
return nil
}
Expand Down