PHP-FPM
PHP-FPM 采集器用于 PHP-FPM 指标采集,如活动进程总数、空闲进程总数、挂起连接队列中的请求数量、活动进程数的最大值等。
配置¶
前置条件¶
-
启用 PHP-FPM 状态页面
- 编辑 PHP-FPM 配置文件(路径通常为
/etc/php/8.x/fpm/pool.d/www.conf
或/etc/php-fpm.d/www.conf
),启用pm.status_path
:
shell ; 启用状态页面 pm.status_path = /status
- 重启 PHP-FPM
- 编辑 PHP-FPM 配置文件(路径通常为
shell
sudo systemctl restart php-fpm
sudo systemctl restart php8.x-fpm
-
配置 Web 服务器
- Nginx 示例:
location /status { include fastcgi_params; fastcgi_pass unix:/var/run/php/php8.x-fpm.sock; // unix socket 形式 # fastcgi_pass 127.0.0.1:9000; // TCP 形式 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }
- 重启 Nginx:
- 访问状态页(
/status
),确保可以正常访问并返回 PHP-FPM 的状态信息
采集器配置¶
进入 DataKit 安装目录下的 conf.d/phpfpm 目录,复制 phpfpm.conf.sample
并命名为 phpfpm.conf
。示例如下:
[[inputs.phpfpm]]
##(optional) collect interval, default is 10 seconds
interval = '10s'
## URL to fetch PHP-FPM pool metrics. Defaults to HTTP (e.g., http://localhost/status).
## For TCP (e.g., tcp://127.0.0.1:9000/status) or Unix socket (e.g., unix:///run/php/php-fpm.sock;/status),
## set use_fastcgi to true.
status_url = "http://localhost/status"
## (optional) use fastcgi, default is false (use http)
use_fastcgi = false
## Set true to enable election
election = true
[inputs.phpfpm.tags]
# some_tag = "some_value"
# more_tag = "some_other_value"
请根据实际环境调整以下配置:
- 默认使用 HTTP 协议时(如 http://localhost/status
),需保持 use_fastcgi = false
- 使用 Unix socket
或 TCP
协议时:
* 地址格式分别为 unix:///socket/path;/status
和 tcp://ip:port/status
* 必须设置 use_fastcgi = true
配置好后,重启 DataKit 即可。
可通过 ConfigMap 方式注入采集器配置 或 配置 ENV_DATAKIT_INPUTS 开启采集器。
也支持以环境变量的方式修改配置参数(需要在 ENV_DEFAULT_ENABLED_INPUTS 中加为默认采集器):
-
ENV_INPUT_PHPFPM_INTERVAL
采集器重复间隔时长
字段类型: Duration
采集器配置字段:
interval
默认值:
10s
-
ENV_INPUT_PHPFPM_STATUS_URL
用于获取 PHP-FPM 池指标的 URL(支持 HTTP 或 FastCGI)
字段类型: String
采集器配置字段:
status_url
默认值: http://localhost/status
-
ENV_INPUT_PHPFPM_USE_FAST_C_G_I
使用 FastCGI 协议而非 HTTP 获取指标
字段类型: Boolean
采集器配置字段:
use_fast_c_g_i
默认值:
false
指标¶
以下所有数据采集,默认会追加全局选举 tag,也可以在配置中通过 [inputs.phpfpm.tags]
指定其它标签:
phpfpm
¶
- 标签
Tag | Description |
---|---|
address | Pool Address. |
pid | The pid of the process. |
pool | The Pools Name of the FPM. |
process_manager | The type of the Process Manager (static, dynamic, ondemand). |
process_state | The state of the process (Idle, Running, ...). |
- 指标列表
Metric | Description |
---|---|
accepted_connections | The number of requests accepted by the pool. Type: int Unit: count |
active_processes | The number of active processes. Type: int Unit: count |
idle_processes | The number of idle processes. Type: int Unit: count |
listen_queue | The number of requests in the queue of pending connections. Type: int Unit: count |
listen_queue_length | The size of the socket queue of pending connections. Type: float Unit: count |
max_active_processes | The maximum number of active processes since FPM has started. Type: int Unit: count |
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: int Unit: count |
max_listen_queue | The maximum number of requests in the queue of pending connections since FPM has started. Type: int Unit: count |
process_last_request_cpu | The %cpu the last request consumed. Type: float Unit: percent,percent |
process_last_request_memory | The max amount of memory the last request consumed. Type: int Unit: count |
process_request_duration | The duration in microseconds of the requests. Type: int Unit: time,μs |
process_requests | The number of requests the process has served. Type: int Unit: count |
slow_requests | The number of requests that exceeded your 'request_slowlog_timeout' value. Type: int Unit: count |
total_processes | The number of idle + active processes. Type: int Unit: count |