diff options
author | Cees-Jan Kiewiet <ceesjank@gmail.com> | 2020-06-09 16:01:57 +0200 |
---|---|---|
committer | Jakub Zelenka <bukka@php.net> | 2021-03-21 18:08:53 +0000 |
commit | d36ac9640af2941169cb97f0764d8e21d930c7c8 (patch) | |
tree | d72c3a4fb3a01e1a39264aea761a0aef1ba1e5e9 /sapi | |
parent | cd40fc3cb1892197a462e013f930859a5d8064b3 (diff) | |
download | php-git-d36ac9640af2941169cb97f0764d8e21d930c7c8.tar.gz |
Add support for openmetrics formatting to FPM status
Diffstat (limited to 'sapi')
-rw-r--r-- | sapi/fpm/fpm/fpm_status.c | 55 | ||||
-rw-r--r-- | sapi/fpm/tests/status.inc | 66 | ||||
-rw-r--r-- | sapi/fpm/tests/tester.inc | 2 |
3 files changed, 118 insertions, 5 deletions
diff --git a/sapi/fpm/fpm/fpm_status.c b/sapi/fpm/fpm/fpm_status.c index ecce6e32c4..02717fc97f 100644 --- a/sapi/fpm/fpm/fpm_status.c +++ b/sapi/fpm/fpm/fpm_status.c @@ -388,6 +388,61 @@ int fpm_status_handle_request(void) /* {{{ */ full_post = "]}"; } + /* OpenMetrics */ + } else if (fpm_php_get_string_from_table(_GET_str, "openmetrics")) { + sapi_add_header_ex(ZEND_STRL("Content-Type: application/openmetrics-text; version=1.0.0; charset=utf-8"), 1, 1); + time_format = "%s"; + + 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_time When FPM has started.\n" + "# TYPE phpfpm_start_time gauge\n" + "phpfpm_start_time %lu\n" + "# HELP phpfpm_start_since_total The number of seconds since FPM has started.\n" + "# TYPE phpfpm_start_since_total counter\n" + "phpfpm_start_since_total %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 %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 %lu\n" + "# HELP phpfpm_max_listen_queue_total The maximum number of requests in the queue of pending connections since FPM has started.\n" + "# TYPE phpfpm_max_listen_queue_total counter\n" + "phpfpm_max_listen_queue_total %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" + "# HELP phpfpm_max_active_processes_total The maximum number of active processes since FPM has started.\n" + "# TYPE phpfpm_max_active_processes_total counter\n" + "phpfpm_max_active_processes_total %d\n" + "# 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" + "# TYPE phpfpm_max_children_reached_total counter\n" + "phpfpm_max_children_reached_total %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 %lu\n"; + + if (!full) { + short_post = ""; + } else { + full_separator = ""; + full_pre = ""; + full_syntax = ""; + full_post = ""; + } + /* TEXT */ } else { sapi_add_header_ex(ZEND_STRL("Content-Type: text/plain"), 1, 1); diff --git a/sapi/fpm/tests/status.inc b/sapi/fpm/tests/status.inc index 39005de568..7706942b3d 100644 --- a/sapi/fpm/tests/status.inc +++ b/sapi/fpm/tests/status.inc @@ -10,10 +10,11 @@ class Status * @var array */ private $contentTypes = [ - 'plain' => 'text/plain', - 'html' => 'text/html', - 'xml' => 'text/xml', - 'json' => 'application/json', + 'plain' => 'text/plain', + 'html' => 'text/html', + 'xml' => 'text/xml', + 'json' => 'application/json', + 'openmetrics' => 'application/openmetrics-text; version=1.0.0; charset=utf-8', ]; /** @@ -196,4 +197,61 @@ class Status true ); } + + /** + * Check openmetrics status page. + * + * @param string $body + * @param array $fields + */ + protected function checkStatusOpenmetrics(string $body, array $fields) + { + $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_time When FPM has started\.\n" . + "# TYPE phpfpm_start_time gauge\n" . + "phpfpm_start_time \d+\n" . + "# HELP phpfpm_start_since_total The number of seconds since FPM has started\.\n" . + "# TYPE phpfpm_start_since_total counter\n" . + "phpfpm_start_since_total " . $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 " . $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" . + "# HELP phpfpm_max_listen_queue_total The maximum number of requests in the queue of pending connections since FPM has started\.\n" . + "# TYPE phpfpm_max_listen_queue_total counter\n" . + "phpfpm_max_listen_queue_total " . $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" . + "# HELP phpfpm_max_active_processes_total The maximum number of active processes since FPM has started\.\n" . + "# TYPE phpfpm_max_active_processes_total counter\n" . + "phpfpm_max_active_processes_total " . $fields['max active processes'] . "\n" . + "# 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" . + "# TYPE phpfpm_max_children_reached_total counter\n" . + "phpfpm_max_children_reached_total " . $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 " . $fields['slow requests'] . "|"; + + if (!preg_match($pattern, $body)) { + echo "ERROR: Expected body does not match pattern\n"; + echo "BODY:\n"; + var_dump($body); + echo "PATTERN:\n"; + var_dump($pattern); + } + } } diff --git a/sapi/fpm/tests/tester.inc b/sapi/fpm/tests/tester.inc index 5c57652d88..b8cdd417cd 100644 --- a/sapi/fpm/tests/tester.inc +++ b/sapi/fpm/tests/tester.inc @@ -499,7 +499,7 @@ class Tester array $expectedFields, string $address = null, string $statusPath = '/status', - $formats = ['plain', 'html', 'xml', 'json'] + $formats = ['plain', 'html', 'xml', 'json', 'openmetrics'] ) { if (!is_array($formats)) { $formats = [$formats]; |