Skip to content

Commit 590af46

Browse files
committed
Sync the FPM openmetrics status with php-fpm_exporter
1 parent bf294d5 commit 590af46

File tree

2 files changed

+41
-48
lines changed

2 files changed

+41
-48
lines changed

sapi/fpm/fpm/fpm_status.c

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ int fpm_status_handle_request(void) /* {{{ */
140140
struct fpm_scoreboard_proc_s proc;
141141
char *buffer, *time_format, time_buffer[64];
142142
time_t now_epoch;
143-
int full, encode, is_start_time_str;
143+
int full, encode, has_start_time;
144144
char *short_syntax, *short_post;
145145
char *full_pre, *full_syntax, *full_post, *full_separator;
146146
zend_string *_GET_str;
@@ -223,7 +223,7 @@ int fpm_status_handle_request(void) /* {{{ */
223223
short_syntax = short_post = NULL;
224224
full_separator = full_pre = full_syntax = full_post = NULL;
225225
encode = 0;
226-
is_start_time_str = 1;
226+
has_start_time = 1;
227227

228228
/* HTML */
229229
if (fpm_php_get_string_from_table(_GET_str, "html")) {
@@ -398,21 +398,18 @@ int fpm_status_handle_request(void) /* {{{ */
398398
"# HELP phpfpm_up Could pool %s using a %s PM on PHP-FPM be reached?\n"
399399
"# TYPE phpfpm_up gauge\n"
400400
"phpfpm_up 1\n"
401-
"# HELP phpfpm_start_time When FPM has started.\n"
402-
"# TYPE phpfpm_start_time gauge\n"
403-
"phpfpm_start_time %lld\n"
404-
"# HELP phpfpm_start_since_total The number of seconds since FPM has started.\n"
405-
"# TYPE phpfpm_start_since_total counter\n"
406-
"phpfpm_start_since_total %lu\n"
407-
"# HELP phpfpm_accepted_connections_total The number of requests accepted by the pool.\n"
408-
"# TYPE phpfpm_accepted_connections_total counter\n"
409-
"phpfpm_accepted_connections_total %lu\n"
401+
"# HELP phpfpm_start_since The number of seconds since FPM has started.\n"
402+
"# TYPE phpfpm_start_since counter\n"
403+
"phpfpm_start_since %lu\n"
404+
"# HELP phpfpm_accepted_connections The number of requests accepted by the pool.\n"
405+
"# TYPE phpfpm_accepted_connections counter\n"
406+
"phpfpm_accepted_connections %lu\n"
410407
"# HELP phpfpm_listen_queue The number of requests in the queue of pending connections.\n"
411408
"# TYPE phpfpm_listen_queue gauge\n"
412409
"phpfpm_listen_queue %d\n"
413-
"# HELP phpfpm_max_listen_queue_total The maximum number of requests in the queue of pending connections since FPM has started.\n"
414-
"# TYPE phpfpm_max_listen_queue_total counter\n"
415-
"phpfpm_max_listen_queue_total %d\n"
410+
"# HELP phpfpm_max_listen_queue The maximum number of requests in the queue of pending connections since FPM has started.\n"
411+
"# TYPE phpfpm_max_listen_queue counter\n"
412+
"phpfpm_max_listen_queue %d\n"
416413
"# TYPE phpfpm_listen_queue_length gauge\n"
417414
"# HELP phpfpm_listen_queue_length The size of the socket queue of pending connections.\n"
418415
"phpfpm_listen_queue_length %u\n"
@@ -425,17 +422,17 @@ int fpm_status_handle_request(void) /* {{{ */
425422
"# HELP phpfpm_total_processes The number of idle + active processes.\n"
426423
"# TYPE phpfpm_total_processes gauge\n"
427424
"phpfpm_total_processes %d\n"
428-
"# HELP phpfpm_max_active_processes_total The maximum number of active processes since FPM has started.\n"
429-
"# TYPE phpfpm_max_active_processes_total counter\n"
430-
"phpfpm_max_active_processes_total %d\n"
431-
"# HELP phpfpm_max_children_reached_total 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"
432-
"# TYPE phpfpm_max_children_reached_total counter\n"
433-
"phpfpm_max_children_reached_total %u\n"
434-
"# HELP phpfpm_slow_requests_total The number of requests that exceeded your 'request_slowlog_timeout' value.\n"
435-
"# TYPE phpfpm_slow_requests_total counter\n"
436-
"phpfpm_slow_requests_total %lu\n";
437-
438-
is_start_time_str = 0;
425+
"# HELP phpfpm_max_active_processes The maximum number of active processes since FPM has started.\n"
426+
"# TYPE phpfpm_max_active_processes counter\n"
427+
"phpfpm_max_active_processes %d\n"
428+
"# 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"
429+
"# TYPE phpfpm_max_children_reached counter\n"
430+
"phpfpm_max_children_reached %u\n"
431+
"# HELP phpfpm_slow_requests The number of requests that exceeded your 'request_slowlog_timeout' value.\n"
432+
"# TYPE phpfpm_slow_requests counter\n"
433+
"phpfpm_slow_requests %lu\n";
434+
435+
has_start_time = 0;
439436
if (!full) {
440437
short_post = "";
441438
} else {
@@ -487,7 +484,7 @@ int fpm_status_handle_request(void) /* {{{ */
487484
}
488485

489486
now_epoch = time(NULL);
490-
if (is_start_time_str) {
487+
if (has_start_time) {
491488
strftime(time_buffer, sizeof(time_buffer) - 1, time_format, localtime(&scoreboard.start_epoch));
492489
spprintf(&buffer, 0, short_syntax,
493490
scoreboard.pool,
@@ -508,7 +505,6 @@ int fpm_status_handle_request(void) /* {{{ */
508505
spprintf(&buffer, 0, short_syntax,
509506
scoreboard.pool,
510507
PM2STR(scoreboard.pm),
511-
(unsigned long long) scoreboard.start_epoch,
512508
(unsigned long) (now_epoch - scoreboard.start_epoch),
513509
scoreboard.requests,
514510
scoreboard.lq,

sapi/fpm/tests/status.inc

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -209,21 +209,18 @@ class Status
209209
$pattern = "|# HELP phpfpm_up Could pool " . $fields['pool'] . " using a " . $fields['process manager'] . " PM on PHP-FPM be reached\?\n" .
210210
"# TYPE phpfpm_up gauge\n" .
211211
"phpfpm_up 1\n" .
212-
"# HELP phpfpm_start_time When FPM has started\.\n" .
213-
"# TYPE phpfpm_start_time gauge\n" .
214-
"phpfpm_start_time \d+\n" .
215-
"# HELP phpfpm_start_since_total The number of seconds since FPM has started\.\n" .
216-
"# TYPE phpfpm_start_since_total counter\n" .
217-
"phpfpm_start_since_total " . $fields['start since'] . "\n" .
218-
"# HELP phpfpm_accepted_connections_total The number of requests accepted by the pool\.\n" .
219-
"# TYPE phpfpm_accepted_connections_total counter\n" .
220-
"phpfpm_accepted_connections_total " . $fields['accepted conn'] . "\n" .
212+
"# HELP phpfpm_start_since The number of seconds since FPM has started\.\n" .
213+
"# TYPE phpfpm_start_since counter\n" .
214+
"phpfpm_start_since " . $fields['start since'] . "\n" .
215+
"# HELP phpfpm_accepted_connections The number of requests accepted by the pool\.\n" .
216+
"# TYPE phpfpm_accepted_connections counter\n" .
217+
"phpfpm_accepted_connections " . $fields['accepted conn'] . "\n" .
221218
"# HELP phpfpm_listen_queue The number of requests in the queue of pending connections\.\n" .
222219
"# TYPE phpfpm_listen_queue gauge\n" .
223220
"phpfpm_listen_queue " . $fields['listen queue'] . "\n" .
224-
"# HELP phpfpm_max_listen_queue_total The maximum number of requests in the queue of pending connections since FPM has started\.\n" .
225-
"# TYPE phpfpm_max_listen_queue_total counter\n" .
226-
"phpfpm_max_listen_queue_total " . $fields['max listen queue'] . "\n" .
221+
"# HELP phpfpm_max_listen_queue The maximum number of requests in the queue of pending connections since FPM has started\.\n" .
222+
"# TYPE phpfpm_max_listen_queue counter\n" .
223+
"phpfpm_max_listen_queue " . $fields['max listen queue'] . "\n" .
227224
"# TYPE phpfpm_listen_queue_length gauge\n" .
228225
"# HELP phpfpm_listen_queue_length The size of the socket queue of pending connections\.\n" .
229226
"phpfpm_listen_queue_length " . $fields['listen queue len'] . "\n" .
@@ -236,15 +233,15 @@ class Status
236233
"# HELP phpfpm_total_processes The number of idle \+ active processes\.\n" .
237234
"# TYPE phpfpm_total_processes gauge\n" .
238235
"phpfpm_total_processes " . $fields['total processes'] . "\n" .
239-
"# HELP phpfpm_max_active_processes_total The maximum number of active processes since FPM has started\.\n" .
240-
"# TYPE phpfpm_max_active_processes_total counter\n" .
241-
"phpfpm_max_active_processes_total " . $fields['max active processes'] . "\n" .
242-
"# HELP phpfpm_max_children_reached_total 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" .
243-
"# TYPE phpfpm_max_children_reached_total counter\n" .
244-
"phpfpm_max_children_reached_total " . $fields['max children reached'] . "\n" .
245-
"# HELP phpfpm_slow_requests_total The number of requests that exceeded your 'request_slowlog_timeout' value\.\n" .
246-
"# TYPE phpfpm_slow_requests_total counter\n" .
247-
"phpfpm_slow_requests_total " . $fields['slow requests'] . "|";
236+
"# HELP phpfpm_max_active_processes The maximum number of active processes since FPM has started\.\n" .
237+
"# TYPE phpfpm_max_active_processes counter\n" .
238+
"phpfpm_max_active_processes " . $fields['max active processes'] . "\n" .
239+
"# 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" .
240+
"# TYPE phpfpm_max_children_reached counter\n" .
241+
"phpfpm_max_children_reached " . $fields['max children reached'] . "\n" .
242+
"# HELP phpfpm_slow_requests The number of requests that exceeded your 'request_slowlog_timeout' value\.\n" .
243+
"# TYPE phpfpm_slow_requests counter\n" .
244+
"phpfpm_slow_requests " . $fields['slow requests'] . "|";
248245

249246
if (!preg_match($pattern, $body)) {
250247
echo "ERROR: Expected body does not match pattern\n";

0 commit comments

Comments
 (0)