Skip to content

Commit

Permalink
add pool labels to short syntax and use child index instead of pid
Browse files Browse the repository at this point in the history
  • Loading branch information
cdaguerre committed Feb 4, 2024
1 parent 376c62d commit 2db1ea7
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 77 deletions.
134 changes: 81 additions & 53 deletions sapi/fpm/fpm/fpm_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,41 +392,36 @@ int fpm_status_handle_request(void) /* {{{ */
short_syntax =
"# HELP phpfpm_up Could pool %s using a %s PM on PHP-FPM be reached?\n"
"# TYPE phpfpm_up gauge\n"
"phpfpm_up 1\n"
"# HELP phpfpm_start_since The number of seconds since FPM has started.\n"
"# TYPE phpfpm_start_since counter\n"
"# UNIT phpfpm_start_since seconds\n"
"phpfpm_start_since %lu\n"
"# HELP phpfpm_accepted_connections The number of requests accepted by the pool.\n"
"# TYPE phpfpm_accepted_connections counter\n"
"phpfpm_accepted_connections %lu\n"
"phpfpm_up{pool=\"%s\"} 1\n"
"# HELP phpfpm_start_since_seconds The number of seconds since FPM has started.\n"
"# TYPE phpfpm_start_since_seconds counter\n"
"# UNIT phpfpm_start_since_seconds seconds\n"
"phpfpm_start_since_seconds{pool=\"%s\"} %lu\n"
"# HELP phpfpm_accepted_connections_total The number of requests accepted by the pool.\n"
"# TYPE phpfpm_accepted_connections_total counter\n"
"phpfpm_accepted_connections_total{pool=\"%s\"} %lu\n"
"# HELP phpfpm_listen_queue The number of requests in the queue of pending connections.\n"
"# TYPE phpfpm_listen_queue gauge\n"
"phpfpm_listen_queue %d\n"
"phpfpm_listen_queue{pool=\"%s\"} %d\n"
"# HELP phpfpm_max_listen_queue The maximum number of requests in the queue of pending connections since FPM has started.\n"
"# TYPE phpfpm_max_listen_queue counter\n"
"phpfpm_max_listen_queue %d\n"
"phpfpm_max_listen_queue{pool=\"%s\"} %d\n"
"# TYPE phpfpm_listen_queue_length gauge\n"
"# HELP phpfpm_listen_queue_length The size of the socket queue of pending connections.\n"
"phpfpm_listen_queue_length %u\n"
"# HELP phpfpm_idle_processes The number of idle processes.\n"
"# TYPE phpfpm_idle_processes gauge\n"
"phpfpm_idle_processes %d\n"
"# HELP phpfpm_active_processes The number of active processes.\n"
"# TYPE phpfpm_active_processes gauge\n"
"phpfpm_active_processes %d\n"
"# HELP phpfpm_total_processes The number of idle + active processes.\n"
"# TYPE phpfpm_total_processes gauge\n"
"phpfpm_total_processes %d\n"
"phpfpm_listen_queue_length{pool=\"%s\"} %u\n"
"# HELP phpfpm_processes The number of processes.\n"
"# TYPE phpfpm_processes gauge\n"
"phpfpm_processes{pool=\"%s\",state=\"idle\"} %d\n"
"phpfpm_processes{pool=\"%s\",state=\"active\"} %d\n"
"# HELP phpfpm_max_active_processes The maximum number of active processes since FPM has started.\n"
"# TYPE phpfpm_max_active_processes counter\n"
"phpfpm_max_active_processes %d\n"
"phpfpm_max_active_processes{pool=\"%s\"} %d\n"
"# 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').\n"
"# TYPE phpfpm_max_children_reached counter\n"
"phpfpm_max_children_reached %u\n"
"# HELP phpfpm_slow_requests The number of requests that exceeded your 'request_slowlog_timeout' value.\n"
"# TYPE phpfpm_slow_requests counter\n"
"phpfpm_slow_requests %lu\n";
"phpfpm_max_children_reached{pool=\"%s\"} %u\n"
"# HELP phpfpm_slow_requests_total The number of requests that exceeded your 'request_slowlog_timeout' value.\n"
"# TYPE phpfpm_slow_requests_total counter\n"
"phpfpm_slow_requests_total{pool=\"%s\"} %lu\n";

has_start_time = 0;
if (!full) {
Expand All @@ -435,31 +430,34 @@ int fpm_status_handle_request(void) /* {{{ */
full_separator = "";
full_pre = "";
full_syntax =
"# HELP phpfpm_process_pid The id of the process.\n"
"# TYPE phpfpm_process_pid gauge\n"
"phpfpm_process_pid{pool=\"%s\",child=\"%d\"} %d\n"
"# HELP phpfpm_process_state The current state of the process (Idle, Running, ...).\n"
"# TYPE phpfpm_process_state gauge\n"
"phpfpm_process_state{pool=\"%s\",pid=\"%d\",state=\"%s\"} 1\n"
"phpfpm_process_state{pool=\"%s\",child=\"%d\",state=\"%s\"} 1\n"
"# HELP phpfpm_process_start_since_seconds The number of seconds since the process started.\n"
"# TYPE phpfpm_process_start_since_seconds counter\n"
"# UNIT phpfpm_process_start_since_seconds seconds\n"
"phpfpm_process_start_since_seconds{pool=\"%s\",pid=\"%d\"} %lu\n"
"phpfpm_process_start_since_seconds{pool=\"%s\",child=\"%d\"} %lu\n"
"# HELP phpfpm_process_requests_total The total number of requests served.\n"
"# TYPE phpfpm_process_requests_total counter\n"
"phpfpm_process_requests_total{pool=\"%s\",pid=\"%d\"} %lu\n"
"phpfpm_process_requests_total{pool=\"%s\",child=\"%d\"} %lu\n"
"# HELP phpfpm_process_request_seconds Time in seconds serving the current or last request.\n"
"# TYPE phpfpm_process_request_seconds gauge\n"
"# UNIT phpfpm_process_request_seconds seconds\n"
"phpfpm_process_request_seconds{pool=\"%s\",pid=\"%d\"} %.6f\n"
"phpfpm_process_request_seconds{pool=\"%s\",child=\"%d\"} %.6f\n"
"# HELP phpfpm_process_request_cpu The percentage of cpu of the last request. This will be 0 if the process is not Idle because the calculation is done when the request processing is complete.\n"
"# TYPE phpfpm_process_request_cpu gauge\n"
"phpfpm_process_request_cpu{pool=\"%s\",pid=\"%d\"} %.2f\n"
"phpfpm_process_request_cpu{pool=\"%s\",child=\"%d\"} %.2f\n"
"# HELP phpfpm_process_request_memory_bytes The maximum amount of memory consumed by the last request. This will be 0 if the process is not Idle because the calculation is done when the request processing is complete.\n"
"# TYPE phpfpm_process_request_memory_bytes gauge\n"
"# UNIT phpfpm_process_request_memory_bytes bytes\n"
"phpfpm_process_request_memory_bytes{pool=\"%s\",pid=\"%d\"} %zu\n"
"phpfpm_process_request_memory_bytes{pool=\"%s\",child=\"%d\"} %zu\n"
"# HELP phpfpm_process_request_content_length_bytes The length of the request body, in bytes, of the last request.\n"
"# TYPE phpfpm_process_request_content_length_bytes gauge\n"
"# UNIT phpfpm_process_request_content_length_bytes bytes\n"
"phpfpm_process_request_content_length_bytes{pool=\"%s\",pid=\"%d\"} %zu\n";
"phpfpm_process_request_content_length_bytes{pool=\"%s\",child=\"%d\"} %zu\n";
full_post = "# EOF\n";
}

Expand Down Expand Up @@ -523,20 +521,47 @@ int fpm_status_handle_request(void) /* {{{ */
scoreboard_p->max_children_reached,
scoreboard_p->slow_rq);
} else {
spprintf(&buffer, 0, short_syntax,
scoreboard_p->pool,
PM2STR(scoreboard_p->pm),
(unsigned long) (now_epoch - scoreboard_p->start_epoch),
scoreboard_p->requests,
scoreboard_p->lq,
scoreboard_p->lq_max,
scoreboard_p->lq_len,
scoreboard_p->idle,
scoreboard_p->active,
scoreboard_p->idle + scoreboard_p->active,
scoreboard_p->active_max,
scoreboard_p->max_children_reached,
scoreboard_p->slow_rq);
if (fpm_php_is_key_in_table(_GET_str, ZEND_STRL("openmetrics"))) {
spprintf(&buffer, 0, short_syntax,
scoreboard_p->pool,
PM2STR(scoreboard_p->pm),
scoreboard_p->pool,
scoreboard_p->pool,
(unsigned long) (now_epoch - scoreboard_p->start_epoch),
scoreboard_p->pool,
scoreboard_p->requests,
scoreboard_p->pool,
scoreboard_p->lq,
scoreboard_p->pool,
scoreboard_p->lq_max,
scoreboard_p->pool,
scoreboard_p->lq_len,
scoreboard_p->pool,
scoreboard_p->idle,
scoreboard_p->pool,
scoreboard_p->active,
scoreboard_p->pool,
scoreboard_p->active_max,
scoreboard_p->pool,
scoreboard_p->max_children_reached,
scoreboard_p->pool,
scoreboard_p->slow_rq);
} else {
spprintf(&buffer, 0, short_syntax,
scoreboard_p->pool,
PM2STR(scoreboard_p->pm),
(unsigned long) (now_epoch - scoreboard_p->start_epoch),
scoreboard_p->requests,
scoreboard_p->lq,
scoreboard_p->lq_max,
scoreboard_p->lq_len,
scoreboard_p->idle,
scoreboard_p->active,
scoreboard_p->idle + scoreboard_p->active,
scoreboard_p->active_max,
scoreboard_p->max_children_reached,
scoreboard_p->slow_rq);
}
}

PUTS(buffer);
Expand All @@ -562,7 +587,7 @@ int fpm_status_handle_request(void) /* {{{ */
PUTS(full_pre);
}

if (fpm_php_get_string_from_table(_GET_str, "openmetrics")) {
if (fpm_php_is_key_in_table(_GET_str, "openmetrics")) {
spprintf(&buffer, 0, "# HELP phpfpm_process_state The current state of the process (Idle, Running, ...).\n");
PUTS(buffer);
spprintf(&buffer, 0, "# TYPE phpfpm_process_state gauge\n");
Expand Down Expand Up @@ -756,25 +781,28 @@ int fpm_status_handle_request(void) /* {{{ */
if (fpm_php_is_key_in_table(_GET_str, ZEND_STRL("openmetrics"))) {
spprintf(&buffer, 0, full_syntax,
scoreboard_p->pool,
i + 1,
(int) proc->pid,
scoreboard_p->pool,
i + 1,
fpm_request_get_stage_name(proc->request_stage),
scoreboard_p->pool,
(int) proc->pid,
i + 1,
(unsigned long) (now_epoch - proc->start_epoch),
scoreboard_p->pool,
(int) proc->pid,
i + 1,
proc->requests,
scoreboard_p->pool,
(int) proc->pid,
i + 1,
(duration.tv_sec * 1000000UL + duration.tv_usec) / 1000000.,
scoreboard_p->pool,
(int) proc->pid,
i + 1,
(proc->request_stage == FPM_REQUEST_ACCEPTING ? cpu : 0.),
scoreboard_p->pool,
(int) proc->pid,
i + 1,
(proc->request_stage == FPM_REQUEST_ACCEPTING ? proc->memory : 0),
scoreboard_p->pool,
(int) proc->pid,
i + 1,
proc->content_length);
} else {
strftime(time_buffer, sizeof(time_buffer) - 1, time_format, localtime(&proc->start_epoch));
Expand Down
44 changes: 20 additions & 24 deletions sapi/fpm/tests/status.inc
Original file line number Diff line number Diff line change
Expand Up @@ -232,40 +232,36 @@ class Status
{
$pattern = "(# HELP phpfpm_up Could pool " . $fields['pool'] . " using a " . $fields['process manager'] . " PM on PHP-FPM be reached\?\n" .
"# TYPE phpfpm_up gauge\n" .
"phpfpm_up 1\n" .
"# HELP phpfpm_start_since The number of seconds since FPM has started\.\n" .
"# TYPE phpfpm_start_since counter\n" .
"phpfpm_start_since " . $fields['start since'] . "\n" .
"# HELP phpfpm_accepted_connections The number of requests accepted by the pool\.\n" .
"# TYPE phpfpm_accepted_connections counter\n" .
"phpfpm_accepted_connections " . $fields['accepted conn'] . "\n" .
"phpfpm_up{pool=\"" . $fields['pool'] . "\"} 1\n" .
"# HELP phpfpm_start_since_seconds The number of seconds since FPM has started\.\n" .
"# TYPE phpfpm_start_since_seconds counter\n" .
"# UNIT phpfpm_start_since_seconds seconds\n" .
"phpfpm_start_since_seconds{pool=\"" . $fields['pool'] . "\"} " . $fields['start since'] . "\n" .
"# HELP phpfpm_accepted_connections_total The number of requests accepted by the pool\.\n" .
"# TYPE phpfpm_accepted_connections_total counter\n" .
"phpfpm_accepted_connections_total{pool=\"" . $fields['pool'] . "\"} " . $fields['accepted conn'] . "\n" .
"# HELP phpfpm_listen_queue The number of requests in the queue of pending connections\.\n" .
"# TYPE phpfpm_listen_queue gauge\n" .
"phpfpm_listen_queue " . $fields['listen queue'] . "\n" .
"phpfpm_listen_queue{pool=\"" . $fields['pool'] . "\"} " . $fields['listen queue'] . "\n" .
"# HELP phpfpm_max_listen_queue The maximum number of requests in the queue of pending connections since FPM has started\.\n" .
"# TYPE phpfpm_max_listen_queue counter\n" .
"phpfpm_max_listen_queue " . $fields['max listen queue'] . "\n" .
"phpfpm_max_listen_queue{pool=\"" . $fields['pool'] . "\"} " . $fields['max listen queue'] . "\n" .
"# TYPE phpfpm_listen_queue_length gauge\n" .
"# HELP phpfpm_listen_queue_length The size of the socket queue of pending connections\.\n" .
"phpfpm_listen_queue_length " . $fields['listen queue len'] . "\n" .
"# HELP phpfpm_idle_processes The number of idle processes\.\n" .
"# TYPE phpfpm_idle_processes gauge\n" .
"phpfpm_idle_processes " . $fields['idle processes'] . "\n" .
"# HELP phpfpm_active_processes The number of active processes\.\n" .
"# TYPE phpfpm_active_processes gauge\n" .
"phpfpm_active_processes " . $fields['active processes'] . "\n" .
"# HELP phpfpm_total_processes The number of idle \+ active processes\.\n" .
"# TYPE phpfpm_total_processes gauge\n" .
"phpfpm_total_processes " . $fields['total processes'] . "\n" .
"phpfpm_listen_queue_length{pool=\"" . $fields['pool'] . "\"} " . $fields['listen queue len'] . "\n" .
"# HELP phpfpm_processes The number of processes\.\n" .
"# TYPE phpfpm_processes gauge\n" .
"phpfpm_processes{pool=\"" . $fields['pool'] . "\",state=\"idle\"} " . $fields['idle processes'] . "\n" .
"phpfpm_processes{pool=\"" . $fields['pool'] . "\",state=\"active\"} " . $fields['active processes'] . "\n" .
"# HELP phpfpm_max_active_processes The maximum number of active processes since FPM has started\.\n" .
"# TYPE phpfpm_max_active_processes counter\n" .
"phpfpm_max_active_processes " . $fields['max active processes'] . "\n" .
"phpfpm_max_active_processes{pool=\"" . $fields['pool'] . "\"} " . $fields['max active processes'] . "\n" .
"# 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'\)\.\n" .
"# TYPE phpfpm_max_children_reached counter\n" .
"phpfpm_max_children_reached " . $fields['max children reached'] . "\n" .
"# HELP phpfpm_slow_requests The number of requests that exceeded your 'request_slowlog_timeout' value\.\n" .
"# TYPE phpfpm_slow_requests counter\n" .
"phpfpm_slow_requests " . $fields['slow requests'] . "\n" .
"phpfpm_max_children_reached{pool=\"" . $fields['pool'] . "\"} " . $fields['max children reached'] . "\n" .
"# HELP phpfpm_slow_requests_total The number of requests that exceeded your 'request_slowlog_timeout' value\.\n" .
"# TYPE phpfpm_slow_requests_total counter\n" .
"phpfpm_slow_requests_total{pool=\"" . $fields['pool'] . "\"} " . $fields['slow requests'] . "\n" .
"# EOF)\n";

if (!preg_match($pattern, $body)) {
Expand Down

0 comments on commit 2db1ea7

Please sign in to comment.