pages.php,橙子/hipages-php-fpm_exporter

php-fpm_exporter

badge.svg

php-fpm_exporter

php-fpm_exporter?status.svg

measure?project=hipages_php-fpm_exporter&metric=alert_status

php-fpm_exporter.svg

php-fpm_exporter.svg

php-fpm_exporter.svg

users.svg

all_contributors-4-orange.svg?style=flat-square

A prometheus exporter for PHP-FPM.

The exporter connects directly to PHP-FPM and exports the metrics via HTTP.

A webserver such as NGINX or Apache is NOT needed!

Table of Contents

Features

Export single or multiple pools

Export to CLI as text or JSON

Connects directly to PHP-FPM via TCP or Socket

Maps environment variables to CLI options

Fix for PHP-FPM metrics oddities

Usage

php-fpm_exporter is released as binary and docker image.

It uses sensible defaults which usually avoids the need to use command parameters or environment variables.

php-fpm_exporter supports 2 commands, get and server.

The get command allows to retrieve information from PHP-FPM without running as a server and exposing an endpoint.

The server command runs the server required for prometheus to retrieve the statistics.

Options and defaults

Option

Description

Environment variable

Default value

--web.listen-address

Address on which to expose metrics and web interface.

PHP_FPM_WEB_LISTEN_ADDRESS

--web.telemetry-path

Path under which to expose metrics.

PHP_FPM_WEB_TELEMETRY_PATH

/metrics

--phpfpm.scrape-uri

FastCGI address, e.g. unix:///tmp/php.sock;/status or tcp://127.0.0.1:9000/status

PHP_FPM_SCRAPE_URI

tcp://127.0.0.1:9000/status

--phpfpm.fix-process-count

Enable to calculate process numbers via php-fpm_exporter since PHP-FPM sporadically reports wrong active/idle/total process numbers.

PHP_FPM_FIX_PROCESS_COUNT

false

--log.level

Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal] (default "error")

PHP_FPM_LOG_LEVEL

info

Why --phpfpm.fix-process-count?

php-fpm_exporter implements an option to "fix" the reported metrics based on the provided processes list by PHP-FPM.

We have seen PHP-FPM provide metrics (e.g. active processes) which don't match reality.

Specially active processes being larger than max_children and the actual number of running processes on the host.

Looking briefly at the source code of PHP-FPM it appears a scoreboard is being kept and the values are increased/decreased once an action is executed.

The metric active processes is also an accumulation of multiple states (e.g. Reading headers, Getting request information, Running).

Which shouldn't matter and active processes should still be equal or lower to max_children.

--phpfpm.fix-process-count will emulate PHP-FPMs implementation including the accumulation of multiple states.

If you like to have a more granular reporting please use phpfpm_process_state.

CLI Examples

Retrieve information from PHP-FPM running on 127.0.0.1:9000 with status endpoint being /status

php-fpm_exporter get

Retrieve information from PHP-FPM running on 127.0.0.1:9000 and 127.0.0.1:9001

php-fpm_exporter get --phpfpm.scrape-uri tcp://127.0.0.1:9000/status,tcp://127.0.0.1:9001/status

Run as server with 2 pools:

php-fpm_exporter server --phpfpm.scrape-uri tcp://127.0.0.1:9000/status,tcp://127.0.0.1:9001/status

Run as server and enable process count fix via environment variable:

PHP_FPM_FIX_PROCESS_COUNT=1 go run main.go server --web.listen-address ":12345" --log.level=debug

Docker Examples

Run docker manually

docker pull hipages/php-fpm_exporter

docker run -it --rm -e PHP_FPM_SCRAPE_URI="tcp://127.0.0.1:9000/status,tcp://127.0.0.1:9001/status" hipages/php-fpm_exporter

Run the docker-compose example

git clone git@github.com:hipages/php-fpm_exporter.git

cd php-fpm_exporter/test

docker-compose -p php-fpm_exporter up

You can now access the following links:

58e386926bbee6e1b761bc461eb02a7d.png

Kubernetes Example

TBD

Metrics collected

# HELP phpfpm_accepted_connections The number of requests accepted by the pool.

# TYPE phpfpm_accepted_connections counter

# HELP phpfpm_active_processes The number of active processes.

# TYPE phpfpm_active_processes gauge

# HELP phpfpm_idle_processes The number of idle processes.

# TYPE phpfpm_idle_processes gauge

# HELP phpfpm_listen_queue The number of requests in the queue of pending connections.

# TYPE phpfpm_listen_queue gauge

# HELP phpfpm_listen_queue_length The size of the socket queue of pending connections.

# TYPE phpfpm_listen_queue_length gauge

# HELP phpfpm_max_active_processes The maximum number of active processes since FPM has started.

# TYPE phpfpm_max_active_processes counter

# HELP phpfpm_max_children_reached The number of times, the process limit has been reached, when pm tries to start more children (works only for pm 'dynamic' and 'ondemand').

# TYPE phpfpm_max_children_reached counter

# HELP phpfpm_max_listen_queue The maximum number of requests in the queue of pending connections since FPM has started.

# TYPE phpfpm_max_listen_queue counter

# HELP phpfpm_process_last_request_cpu The %cpu the last request consumed.

# TYPE phpfpm_process_last_request_cpu gauge

# HELP phpfpm_process_last_request_memory The max amount of memory the last request consumed.

# TYPE phpfpm_process_last_request_memory gauge

# HELP phpfpm_process_request_duration The duration in microseconds of the requests.

# TYPE phpfpm_process_request_duration gauge

# HELP phpfpm_process_requests The number of requests the process has served.

# TYPE phpfpm_process_requests counter

# HELP phpfpm_process_state The state of the process (Idle, Running, ...).

# TYPE phpfpm_process_state gauge

# HELP phpfpm_scrape_failures The number of failures scraping from PHP-FPM.

# TYPE phpfpm_scrape_failures counter

# HELP phpfpm_slow_requests The number of requests that exceeded your 'request_slowlog_timeout' value.

# TYPE phpfpm_slow_requests counter

# HELP phpfpm_start_since The number of seconds since FPM has started.

# TYPE phpfpm_start_since counter

# HELP phpfpm_total_processes The number of idle + active processes.

# TYPE phpfpm_total_processes gauge

# HELP phpfpm_up Could PHP-FPM be reached?

# TYPE phpfpm_up gauge

Grafana Dasbhoard for Kubernetes

The Grafana dashboard can be found here.

4c198870497cc777e0237f34c7707b59.png

FAQ

How to update "Metrics collected"?

Copy&paste the output from:

curl http://127.0.0.1:12345/metrics | grep phpfpm | grep "#"

Development

E2E Tests

The E2E tests are based on docker-compose and bats-core. Install the required components, e.g. via brew on MacOS:

brew tap kaos/shell

brew installdocker-compose bats-core kaos/shell/bats-assert kaos/shell/bats-support

After the components are installed run the E2E tests:

make tests-e2e

Contributing

Contributions are greatly appreciated.

The maintainers actively manage the issues list, and try to highlight issues suitable for newcomers.

The project follows the typical GitHub pull request model.

See " How to Contribute to Open Source " for more details.

Before starting any work, please either comment on an existing issue, or file a new one.

Contributors

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

Alternatives

编写php服务的dockerfile文档,满足如下要求: 1)基础镜像:centos:7 2)作者信息:姓名首字母 3)下载gcc gcc-c++ gd-devel libxml2-devel libcurl-devel libjpeg-devel libpng-devel openssl-devel make perl 4)将本地文件libzip-1.2.0.tar.gz解压并复制到容器中的/tmp中 5)通过以下命令对libzip进行配置编译: cd /tmp/libzip-1.2.0 && ./configure && make && make install 6)在容器中复制并解压文件php-7.3.9.tar.gz到/tmp文件夹中,然后进入到/tmp/php-7.3.9文件夹下,并通过以下命令进行编译: ./configure --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --with-mysql --with-mysqli \ --with-openssl --with-zlib --with-curl --with-gd \ --with-jpeg-dir --with-png-dir --with-iconv \ --enable-fpm --enable-zip --enable-mbstring 6)在容器中将/usr/local/lib/libzip/include/zipconf.h文件复制到 /usr/local/include/文件加下 7)继续进行编译make -j 4 && make install 8)在容器中将/usr/local/php/etc/php-fpm.conf.default文件复制为 /usr/local/php/etc/php-fpm.conf文件 9)在容器中将文件/usr/local/php/etc/php-fpm.d/www.conf.default 复制成/usr/local/php/etc/php-fpm.d/www.conf 文件 10)在容器中修改/usr/local/php/etc/php-fpm.d/www.conf文件中的127.0.0.1为0.0.0.0 11)在容器中复制./sapi/fpm/init.d.php-fpm文件成 /etc/init.d/php-fpm文件 12)在容器中修改/etc/init.d/php-fpm权限为可执行 13)端口9000 14)在容器启动时执行命令:/etc/init.d/php-fpm start && tail -F /var/log/messages
06-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值