Code Monkey home page Code Monkey logo

phpfpm_exporter's Introduction

PHP-FPM Exporter for Prometheus Build Status

GitHub release GitHub Downloads Docker Repository on Quay Docker Pulls

Prometheus Exporter for the PHP-FPM status page.

Metrics are scrapped via unix socket and made available on port 9253.

This exporter also provides a way for embedding the output of arbitrary PHP scripts into its metrics page, analogous to the node exporter's textfile collector. Scripts that are specified with the --phpfpm.script-collector-paths flag will be run through PHP-FPM. Any metrics printed by the PHP script will be merged into the metrics provided by this exported. An example use case includes printing metrics for PHP's opcache.

Usage:

Run the exporter

./phpfpm_exporter --phpfpm.socket-paths /var/run/phpfpm.sock

Include additional metrics from a PHP script

E.g. export OPcache metrics (using contrib/php_opcache_exporter.php)

Bear in mind these metrics are global, all FPM pools share the same cache.

./phpfpm_exporter --phpfpm.socket-paths /var/run/phpfpm.sock \
--phpfpm.script-collector-paths /usr/local/bin/php_exporter/phpfpm_opcache_exporter.php

Run with Docker

SOCK="/run/php/php7.2-fpm.sock"; \
docker run -d -p 9253:9253 -v $SOCK:$SOCK  \
lusotycoon/phpfpm-exporter \
--phpfpm.socket-paths=$SOCK

Help on flags

./phpfpm_exporter -h
usage: phpfpm_exporter [<flags>]

Flags:
  -h, --help     Show context-sensitive help (also try --help-long and --help-man).
      --web.listen-address=":9253"
                 Address to listen on for web interface and telemetry.
      --web.telemetry-path="/metrics"
                 Path under which to expose metrics.
      --phpfpm.socket-paths=PHPFPM.SOCKET-PATHS ...
                 Path(s) of the PHP-FPM sockets.
      --phpfpm.socket-directories=PHPFPM.SOCKET-DIRECTORIES ...
                 Path(s) of the directory where PHP-FPM sockets are located.
      --phpfpm.status-path="/status"
                 Path which has been configured in PHP-FPM to show status page.
      --version  Print version information.
      --phpfpm.script-collector-paths=PHPFPM.SCRIPT-COLLECTOR-PATHS ...
                 Paths of the PHP file whose output needs to be collected.

When using --phpfpm.socket-directories make sure to use dedicated directories for PHP-FPM sockets to avoid timeouts.

Metrics emitted by PHP-FPM:

php_fpm_accepted_connections_total{socket_path="/var/run/phpfpm.sock"} 300940
php_fpm_active_processes{socket_path="/var/run/phpfpm.sock"} 1
php_fpm_idle_processes{socket_path="/var/run/phpfpm.sock"} 5
php_fpm_listen_queue{socket_path="/var/run/phpfpm.sock"} 0
php_fpm_listen_queue_length{socket_path="/var/run/phpfpm.sock"} 0
php_fpm_max_active_processes{socket_path="/var/run/phpfpm.sock"} 10
php_fpm_max_children_reached{socket_path="/var/run/phpfpm.sock"} 3
php_fpm_max_listen_queue{socket_path="/var/run/phpfpm.sock"} 0
php_fpm_slow_requests{socket_path="/var/run/phpfpm.sock"} 0
php_fpm_start_time_seconds{socket_path="/var/run/phpfpm.sock"} 1.49277445e+09
php_fpm_total_processes{socket_path="/var/run/phpfpm.sock"} 3
php_fpm_up{socket_path="/var/run/phpfpm.sock"} 1

Requirements

The FPM status page must be enabled in every pool you'd like to monitor by defining pm.status_path = /status.

Grafana Dashboards

There's multiple grafana dashboards available for this exporter, find them at the urls below or in contrib/.

Basic: for analyzing a single fpm pool in detail.

Multi Pool: for analyzing a cluster of fpm pools.

Basic: basic

Multi Pool: multi pool

phpfpm_exporter's People

Contributors

bartverc avatar edschouten avatar grummfy avatar jwhitcraft avatar klatys avatar lusitaniae avatar meroje avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

phpfpm_exporter's Issues

Failed to scrape socket: malformed MIME header line: Primary script unknown

Hello,

While running the exporter I found this error coming up:
2017/09/08 14:12:55 Failed to scrape socket: malformed MIME header line: Primary script unknown
Which result in all metrics specific to phpfpm not being printed.

After some analysis I managed to fix by replacing the default value for scriptName from

/server-status-fpm.php

to

/status

I'm using ubuntu 16.04 with the typical lemp stack.

I try to run it in docker and get an error in the logs

Run with Docker

SOCK="/run/php/php7.2-fpm.sock"; \
docker run -d -p 9253:9253 -v $SOCK:$SOCK  \
lusotycoon/phpfpm-exporter \
--phpfpm.socket-paths=$SOCK

docker logs quirky_yonath

2021/02/26 11:25:30 Starting phpfpm_exporter (version=0.5.0, branch=HEAD, revision=9cb855b0e40f98db3bfae60d34d7b87834329310)
2021/02/26 11:25:30 Build context (go=go1.12.6, user=root@a53eecf46f97, date=20190621-12:09:02)
2021/02/26 11:25:30 Starting Server: :9253
2021/02/26 11:25:39 Failed to scrape socket: malformed MIME header line: Primary script unknown
2021/02/26 11:25:49 Failed to scrape socket: malformed MIME header line: Primary script unknown
2021/02/26 11:25:59 Failed to scrape socket: malformed MIME header line: Primary script unknown

Failed to scrape socket: Failed to parse File not found.

Hi there!

I've downloaded the PHP-FPM Exporter and installed it in /opt/phpfpm_exporter/ and have written an Unit-File with the following content:

[Unit]
Description=PHP-FPM Exporter
After=network.target

[Service]
Type=simple
User=nginx
Group=nginx
ExecStart=/opt/phpfpm_exporter/phpfpm_exporter --phpfpm.socket-directories=/var/run/
SyslogIdentifier=php-fpm-exporter
Restart=always

[Install]
WantedBy=multi-user.target`

I've multiple Sockets under '/var/run/' which I wanna have a in my Grafana Dashboard. When I start it I can see the following in '/var/log/messages':

Oct 14 22:05:25 host11 php-fpm-exporter: 2021/10/14 22:05:25 Failed to scrape socket: dial unix /var/run/systemd/cgroups-agent: connect: permission denied
Oct 14 22:05:25 host11 php-fpm-exporter: 2021/10/14 22:05:25 Failed to scrape socket: dial unix /var/run/systemd/journal/socket: connect: protocol wrong type for socket
Oct 14 22:05:25 host11 php-fpm-exporter: 2021/10/14 22:05:25 Failed to scrape socket: unexpected EOF
Oct 14 22:05:25 host11 php-fpm-exporter: 2021/10/14 22:05:25 Failed to scrape socket: dial unix /var/run/systemd/notify: connect: protocol wrong type for socket
Oct 14 22:05:25 host11 systemd: Incoming private connection from unprivileged client, refusing: Operation not permitted
Oct 14 22:05:25 host11 php-fpm-exporter: 2021/10/14 22:05:25 Failed to scrape socket: read unix @->/run/systemd/private: read: connection reset by peer
Oct 14 22:05:25 host11 php-fpm-exporter: 2021/10/14 22:05:25 Failed to scrape socket: dial unix /var/run/systemd/shutdownd: connect: permission denied
Oct 14 22:05:25 host11 php-fpm-exporter: 2021/10/14 22:05:25 Failed to scrape socket: dial unix /var/run/udev/control: connect: permission denied
Oct 14 22:05:55 host11 php-fpm-exporter: 2021/10/14 22:05:55 Failed to scrape socket: read unix @->/run/dbus/system_bus_socket: read: connection reset by peer
Oct 14 22:05:55 host11 php-fpm-exporter: 2021/10/14 22:05:55 Failed to scrape socket: Failed to parse 403 Forbidden
Oct 14 22:05:55 host11 php-fpm-exporter: 2021/10/14 22:05:55 Failed to scrape socket: read unix @->/run/gssproxy.sock: read: connection reset by peer
Oct 14 22:05:55 host11 php-fpm-exporter: 2021/10/14 22:05:55 Failed to scrape socket: Failed to parse File not found.
Oct 14 22:05:55 host11 php-fpm-exporter: 2021/10/14 22:05:55 Failed to scrape socket: Failed to parse File not found.
Oct 14 22:05:55 host11 php-fpm-exporter: 2021/10/14 22:05:55 Failed to scrape socket: Failed to parse File not found.
Oct 14 22:05:55 host11 php-fpm-exporter: 2021/10/14 22:05:55 Failed to scrape socket: Failed to parse File not found.
Oct 14 22:05:55 host11 php-fpm-exporter: 2021/10/14 22:05:55 Failed to scrape socket: Failed to parse File not found.
Oct 14 22:05:55 host11 php-fpm-exporter: 2021/10/14 22:05:55 Failed to scrape socket: Failed to parse File not found.
Oct 14 22:05:55 host11 php-fpm-exporter: 2021/10/14 22:05:55 Failed to scrape socket: Failed to parse File not found.
Oct 14 22:05:55 host11 php-fpm-exporter: 2021/10/14 22:05:55 Failed to scrape socket: Failed to parse File not found.
Oct 14 22:05:55 host11 php-fpm-exporter: 2021/10/14 22:05:55 Failed to scrape socket: Failed to parse File not found.
Oct 14 22:05:55 host11 php-fpm-exporter: 2021/10/14 22:05:55 Failed to scrape socket: Failed to parse File not found.
Oct 14 22:05:55 host11 php-fpm-exporter: 2021/10/14 22:05:55 Failed to scrape socket: read unix @->/var/run/rpcbind.sock: read: connection reset by peer
Oct 14 22:05:55 host11 php-fpm-exporter: 2021/10/14 22:05:55 Failed to scrape socket: dial unix /var/run/systemd/cgroups-agent: connect: permission denied
Oct 14 22:05:55 host11 php-fpm-exporter: 2021/10/14 22:05:55 Failed to scrape socket: dial unix /var/run/systemd/journal/socket: connect: protocol wrong type for socket
Oct 14 22:05:55 host11 systemd: Incoming private connection from unprivileged client, refusing: Operation not permitted
Oct 14 22:05:55 host11 php-fpm-exporter: 2021/10/14 22:05:55 Failed to scrape socket: unexpected EOF
Oct 14 22:05:55 host11 php-fpm-exporter: 2021/10/14 22:05:55 Failed to scrape socket: dial unix /var/run/systemd/notify: connect: protocol wrong type for socket
Oct 14 22:05:55 host11 php-fpm-exporter: 2021/10/14 22:05:55 Failed to scrape socket: write unix @->/run/systemd/private: write: broken pipe
Oct 14 22:05:55 host11 php-fpm-exporter: 2021/10/14 22:05:55 Failed to scrape socket: dial unix /var/run/systemd/shutdownd: connect: permission denied
Oct 14 22:05:55 host11 php-fpm-exporter: 2021/10/14 22:05:55 Failed to scrape socket: dial unix /var/run/udev/control: connect: permission denied

What is wrong with my code especially under 'ExecStart' in my Unit-File?

Exporter unavailable during socket timeouts

Hi,

we are using this exporter for a while and I notice patterns, where exporter start logging errors (lines before end), then exporter hang as well. Is there any debug option how could I can track this more?

I would expect behavior that exporter should be responsive all the time, but report php_fpm_up{socket_path="..."} 0. Now we loosing all data when single socket is down.

Using exporter:
phpfpm_exporter, version 0.5.0 (branch: HEAD, revision: 9cb855b)

Started under supervisor:

command=/opt/prometheus/bin/php-fpm_exporter --web.listen-address=":XXXX"
        --phpfpm.status-path=/fpm-status
        --phpfpm.socket-directories=/var/lib/php/7.X/fpm/
# we use directories because on some machines we have 200+ sockets for different web sites

Exporter error log (Prague so UTC+2):

2020/10/20 10:14:24 Failed to scrape socket: dial unix /var/lib/php/7.2/fpm/sock.sock: connect: resource temporarily unavailable
...
2020/10/20 10:16:05 Failed to scrape socket: dial unix /var/lib/php/7.2/fpm/sock.sock: connect: resource temporarily unavailable

Screens from grafana dashboard (Prague so UTC+2):
Screenshot 2020-10-20 at 12 50 22
Screenshot 2020-10-20 at 12 52 18

Prometheus graf on up metric for job (UTC):
Screenshot 2020-10-20 at 13 03 54

Metrics endpoint with HTTPS

Hi,
I've been using PHP-FPM Exporter for a few weeks, and I must say that it's great!
However I noticed that the metrics endpoint is exposed only over http.
As I have other exporters (i.e. Telegraf) that exposes their metrics over https, I was wondering if your exporter could be set over https as well.
Regards

Failed to scrape socket: Failed to parse File not found.

Hi,
I have download phpfpm_exporter and installed on some of my web server on AWS EC2 with Bitnami/NGINX package.

Here is my phpfpm_exporter.service

[Unit]
Description = PHP-FPM Prometheus Exporter

[Service]
SyslogIdentifier = phpfpm_exporter

ExecStart =/usr/local/bin/phpfpm_exporter --phpfpm.socket-paths /opt/bitnami/php/var/run/www.sock

[Install]
WantedBy = multi-user.target

For some odd reason, one of the servers works perfectly fine, but then I am encourting this following error with others.

Oct 27 08:02:52 ip-10-129-19-93 systemd[1]: Started PHP-FPM Prometheus Exporter.
Oct 27 08:02:52 ip-10-129-19-93 phpfpm_exporter[18333]: 2022/10/27 08:02:52 Starting phpfpm_exporter (version=0.6.0, branch=HEAD, revision=7177e606317822df06d567a4c14d085c40d54ef6)
Oct 27 08:02:52 ip-10-129-19-93 phpfpm_exporter[18333]: 2022/10/27 08:02:52 Build context (go=go1.16.5, user=root@742eee, date=20210605-16:49:46)
Oct 27 08:02:52 ip-10-129-19-93 phpfpm_exporter[18333]: 2022/10/27 08:02:52 Starting Server: :9253
Oct 27 08:03:05 ip-10-129-19-93 phpfpm_exporter[18333]: 2022/10/27 08:03:05 Failed to scrape socket: Failed to parse File not found.
Oct 27 08:03:35 ip-10-129-19-93 phpfpm_exporter[18333]: 2022/10/27 08:03:35 Failed to scrape socket: Failed to parse File not found.
Oct 27 08:04:05 ip-10-129-19-93 phpfpm_exporter[18333]: 2022/10/27 08:04:05 Failed to scrape socket: Failed to parse File not found.

Am I missing something? Can't figure out what's causing this.

exporting multiple pools

So i understand that multiple socket paths can be used

phpfpm_exporter-0.6.0.linux-amd64/phpfpm_exporter --phpfpm.socket-paths /var/run/php-fpm/php-fpm-pool1.sock --phpfpm.socket-paths /var/run/php-fpm/php-fpm-pool2.sock

but only one phpfpm.status-path can be used? I thought that each pool will need its own unique pm.status_path defined. I use nginx but i'm not really sure how to set this up. Any guidance would be much appreciated!

fpm detected as down

Hello,
my fpm process is detected as down (using sockets).
the socket is well detected but _up stats = 0.

Any idea where it came from (the process is running well)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.