diff --git a/README.md b/README.md index 0f088ed..1be15d2 100644 --- a/README.md +++ b/README.md @@ -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 ======= diff --git a/cmd/php-fpm-exporter/main.go b/cmd/php-fpm-exporter/main.go index a193256..cb5979b 100644 --- a/cmd/php-fpm-exporter/main.go +++ b/cmd/php-fpm-exporter/main.go @@ -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() ) diff --git a/collector.go b/collector.go index 882283c..05dfaaa 100644 --- a/collector.go +++ b/collector.go @@ -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 } diff --git a/exporter.go b/exporter.go index 1bd48c9..72365f9 100644 --- a/exporter.go +++ b/exporter.go @@ -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 } @@ -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 }