]> granicus.if.org Git - php/commitdiff
Fix types in FPM status openmetrics format
authorJakub Zelenka <bukka@php.net>
Mon, 22 Mar 2021 21:32:15 +0000 (21:32 +0000)
committerJakub Zelenka <bukka@php.net>
Mon, 22 Mar 2021 21:32:15 +0000 (21:32 +0000)
sapi/fpm/fpm/fpm_status.c

index 94e3d256ae19f49108347249739216601807da06..6ba42f43dd93ffcd683fcaf809ce41f2fa2f2541 100644 (file)
@@ -140,7 +140,7 @@ int fpm_status_handle_request(void) /* {{{ */
        struct fpm_scoreboard_proc_s proc;
        char *buffer, *time_format, time_buffer[64];
        time_t now_epoch;
-       int full, encode;
+       int full, encode, is_start_time_str;
        char *short_syntax, *short_post;
        char *full_pre, *full_syntax, *full_post, *full_separator;
        zend_string *_GET_str;
@@ -223,6 +223,7 @@ int fpm_status_handle_request(void) /* {{{ */
                short_syntax = short_post = NULL;
                full_separator = full_pre = full_syntax = full_post = NULL;
                encode = 0;
+               is_start_time_str = 1;
 
                /* HTML */
                if (fpm_php_get_string_from_table(_GET_str, "html")) {
@@ -399,7 +400,7 @@ int fpm_status_handle_request(void) /* {{{ */
                                "phpfpm_up 1\n"
                                "# HELP phpfpm_start_time When FPM has started.\n"
                                "# TYPE phpfpm_start_time gauge\n"
-                               "phpfpm_start_time %lu\n"
+                               "phpfpm_start_time %lld\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"
@@ -408,7 +409,7 @@ int fpm_status_handle_request(void) /* {{{ */
                                "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"
+                               "phpfpm_listen_queue %d\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"
@@ -434,6 +435,7 @@ int fpm_status_handle_request(void) /* {{{ */
                                "# TYPE phpfpm_slow_requests_total counter\n"
                                "phpfpm_slow_requests_total %lu\n";
 
+                       is_start_time_str = 0;
                        if (!full) {
                                short_post = "";
                        } else {
@@ -484,23 +486,41 @@ int fpm_status_handle_request(void) /* {{{ */
                                }
                }
 
-               strftime(time_buffer, sizeof(time_buffer) - 1, time_format, localtime(&scoreboard.start_epoch));
                now_epoch = time(NULL);
-               spprintf(&buffer, 0, short_syntax,
-                               scoreboard.pool,
-                               PM2STR(scoreboard.pm),
-                               time_buffer,
-                               (unsigned long) (now_epoch - scoreboard.start_epoch),
-                               scoreboard.requests,
-                               scoreboard.lq,
-                               scoreboard.lq_max,
-                               scoreboard.lq_len,
-                               scoreboard.idle,
-                               scoreboard.active,
-                               scoreboard.idle + scoreboard.active,
-                               scoreboard.active_max,
-                               scoreboard.max_children_reached,
-                               scoreboard.slow_rq);
+               if (is_start_time_str) {
+                       strftime(time_buffer, sizeof(time_buffer) - 1, time_format, localtime(&scoreboard.start_epoch));
+                       spprintf(&buffer, 0, short_syntax,
+                                       scoreboard.pool,
+                                       PM2STR(scoreboard.pm),
+                                       time_buffer,
+                                       (unsigned long) (now_epoch - scoreboard.start_epoch),
+                                       scoreboard.requests,
+                                       scoreboard.lq,
+                                       scoreboard.lq_max,
+                                       scoreboard.lq_len,
+                                       scoreboard.idle,
+                                       scoreboard.active,
+                                       scoreboard.idle + scoreboard.active,
+                                       scoreboard.active_max,
+                                       scoreboard.max_children_reached,
+                                       scoreboard.slow_rq);
+               } else {
+                       spprintf(&buffer, 0, short_syntax,
+                                       scoreboard.pool,
+                                       PM2STR(scoreboard.pm),
+                                       scoreboard.start_epoch,
+                                       (unsigned long) (now_epoch - scoreboard.start_epoch),
+                                       scoreboard.requests,
+                                       scoreboard.lq,
+                                       scoreboard.lq_max,
+                                       scoreboard.lq_len,
+                                       scoreboard.idle,
+                                       scoreboard.active,
+                                       scoreboard.idle + scoreboard.active,
+                                       scoreboard.active_max,
+                                       scoreboard.max_children_reached,
+                                       scoreboard.slow_rq);
+               }
 
                PUTS(buffer);
                efree(buffer);