@@ -392,41 +392,36 @@ int fpm_status_handle_request(void) /* {{{ */
392
392
short_syntax =
393
393
"# HELP phpfpm_up Could pool %s using a %s PM on PHP-FPM be reached?\n"
394
394
"# TYPE phpfpm_up gauge\n"
395
- "phpfpm_up 1\n"
396
- "# HELP phpfpm_start_since The number of seconds since FPM has started.\n"
397
- "# TYPE phpfpm_start_since counter\n"
398
- "# UNIT phpfpm_start_since seconds\n"
399
- "phpfpm_start_since %lu\n"
400
- "# HELP phpfpm_accepted_connections The number of requests accepted by the pool.\n"
401
- "# TYPE phpfpm_accepted_connections counter\n"
402
- "phpfpm_accepted_connections %lu\n"
395
+ "phpfpm_up{pool=\"%s\"} 1\n"
396
+ "# HELP phpfpm_start_since_seconds The number of seconds since FPM has started.\n"
397
+ "# TYPE phpfpm_start_since_seconds counter\n"
398
+ "# UNIT phpfpm_start_since_seconds seconds\n"
399
+ "phpfpm_start_since_seconds{pool=\"%s\"} %lu\n"
400
+ "# HELP phpfpm_accepted_connections_total The number of requests accepted by the pool.\n"
401
+ "# TYPE phpfpm_accepted_connections_total counter\n"
402
+ "phpfpm_accepted_connections_total{pool=\"%s\"} %lu\n"
403
403
"# HELP phpfpm_listen_queue The number of requests in the queue of pending connections.\n"
404
404
"# TYPE phpfpm_listen_queue gauge\n"
405
- "phpfpm_listen_queue %d\n"
405
+ "phpfpm_listen_queue{pool=\"%s\"} %d\n"
406
406
"# HELP phpfpm_max_listen_queue The maximum number of requests in the queue of pending connections since FPM has started.\n"
407
407
"# TYPE phpfpm_max_listen_queue counter\n"
408
- "phpfpm_max_listen_queue %d\n"
408
+ "phpfpm_max_listen_queue{pool=\"%s\"} %d\n"
409
409
"# TYPE phpfpm_listen_queue_length gauge\n"
410
410
"# HELP phpfpm_listen_queue_length The size of the socket queue of pending connections.\n"
411
- "phpfpm_listen_queue_length %u\n"
412
- "# HELP phpfpm_idle_processes The number of idle processes.\n"
413
- "# TYPE phpfpm_idle_processes gauge\n"
414
- "phpfpm_idle_processes %d\n"
415
- "# HELP phpfpm_active_processes The number of active processes.\n"
416
- "# TYPE phpfpm_active_processes gauge\n"
417
- "phpfpm_active_processes %d\n"
418
- "# HELP phpfpm_total_processes The number of idle + active processes.\n"
419
- "# TYPE phpfpm_total_processes gauge\n"
420
- "phpfpm_total_processes %d\n"
411
+ "phpfpm_listen_queue_length{pool=\"%s\"} %u\n"
412
+ "# HELP phpfpm_processes The number of processes.\n"
413
+ "# TYPE phpfpm_processes gauge\n"
414
+ "phpfpm_processes{pool=\"%s\",state=\"idle\"} %d\n"
415
+ "phpfpm_processes{pool=\"%s\",state=\"active\"} %d\n"
421
416
"# HELP phpfpm_max_active_processes The maximum number of active processes since FPM has started.\n"
422
417
"# TYPE phpfpm_max_active_processes counter\n"
423
- "phpfpm_max_active_processes %d\n"
418
+ "phpfpm_max_active_processes{pool=\"%s\"} %d\n"
424
419
"# 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"
425
420
"# TYPE phpfpm_max_children_reached counter\n"
426
- "phpfpm_max_children_reached %u\n"
427
- "# HELP phpfpm_slow_requests The number of requests that exceeded your 'request_slowlog_timeout' value.\n"
428
- "# TYPE phpfpm_slow_requests counter\n"
429
- "phpfpm_slow_requests %lu\n" ;
421
+ "phpfpm_max_children_reached{pool=\"%s\"} %u\n"
422
+ "# HELP phpfpm_slow_requests_total The number of requests that exceeded your 'request_slowlog_timeout' value.\n"
423
+ "# TYPE phpfpm_slow_requests_total counter\n"
424
+ "phpfpm_slow_requests_total{pool=\"%s\"} %lu\n" ;
430
425
431
426
has_start_time = 0 ;
432
427
if (!full ) {
@@ -435,31 +430,34 @@ int fpm_status_handle_request(void) /* {{{ */
435
430
full_separator = "" ;
436
431
full_pre = "" ;
437
432
full_syntax =
433
+ "# HELP phpfpm_process_pid The id of the process.\n"
434
+ "# TYPE phpfpm_process_pid gauge\n"
435
+ "phpfpm_process_pid{pool=\"%s\",child=\"%d\"} %d\n"
438
436
"# HELP phpfpm_process_state The current state of the process (Idle, Running, ...).\n"
439
437
"# TYPE phpfpm_process_state gauge\n"
440
- "phpfpm_process_state{pool=\"%s\",pid =\"%d\",state=\"%s\"} 1\n"
438
+ "phpfpm_process_state{pool=\"%s\",child =\"%d\",state=\"%s\"} 1\n"
441
439
"# HELP phpfpm_process_start_since_seconds The number of seconds since the process started.\n"
442
440
"# TYPE phpfpm_process_start_since_seconds counter\n"
443
441
"# UNIT phpfpm_process_start_since_seconds seconds\n"
444
- "phpfpm_process_start_since_seconds{pool=\"%s\",pid =\"%d\"} %lu\n"
442
+ "phpfpm_process_start_since_seconds{pool=\"%s\",child =\"%d\"} %lu\n"
445
443
"# HELP phpfpm_process_requests_total The total number of requests served.\n"
446
444
"# TYPE phpfpm_process_requests_total counter\n"
447
- "phpfpm_process_requests_total{pool=\"%s\",pid =\"%d\"} %lu\n"
445
+ "phpfpm_process_requests_total{pool=\"%s\",child =\"%d\"} %lu\n"
448
446
"# HELP phpfpm_process_request_seconds Time in seconds serving the current or last request.\n"
449
447
"# TYPE phpfpm_process_request_seconds gauge\n"
450
448
"# UNIT phpfpm_process_request_seconds seconds\n"
451
- "phpfpm_process_request_seconds{pool=\"%s\",pid =\"%d\"} %.6f\n"
449
+ "phpfpm_process_request_seconds{pool=\"%s\",child =\"%d\"} %.6f\n"
452
450
"# 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"
453
451
"# TYPE phpfpm_process_request_cpu gauge\n"
454
- "phpfpm_process_request_cpu{pool=\"%s\",pid =\"%d\"} %.2f\n"
452
+ "phpfpm_process_request_cpu{pool=\"%s\",child =\"%d\"} %.2f\n"
455
453
"# 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"
456
454
"# TYPE phpfpm_process_request_memory_bytes gauge\n"
457
455
"# UNIT phpfpm_process_request_memory_bytes bytes\n"
458
- "phpfpm_process_request_memory_bytes{pool=\"%s\",pid =\"%d\"} %zu\n"
456
+ "phpfpm_process_request_memory_bytes{pool=\"%s\",child =\"%d\"} %zu\n"
459
457
"# HELP phpfpm_process_request_content_length_bytes The length of the request body, in bytes, of the last request.\n"
460
458
"# TYPE phpfpm_process_request_content_length_bytes gauge\n"
461
459
"# UNIT phpfpm_process_request_content_length_bytes bytes\n"
462
- "phpfpm_process_request_content_length_bytes{pool=\"%s\",pid =\"%d\"} %zu\n" ;
460
+ "phpfpm_process_request_content_length_bytes{pool=\"%s\",child =\"%d\"} %zu\n" ;
463
461
full_post = "# EOF\n" ;
464
462
}
465
463
@@ -523,20 +521,47 @@ int fpm_status_handle_request(void) /* {{{ */
523
521
scoreboard_p -> max_children_reached ,
524
522
scoreboard_p -> slow_rq );
525
523
} else {
526
- spprintf (& buffer , 0 , short_syntax ,
527
- scoreboard_p -> pool ,
528
- PM2STR (scoreboard_p -> pm ),
529
- (unsigned long ) (now_epoch - scoreboard_p -> start_epoch ),
530
- scoreboard_p -> requests ,
531
- scoreboard_p -> lq ,
532
- scoreboard_p -> lq_max ,
533
- scoreboard_p -> lq_len ,
534
- scoreboard_p -> idle ,
535
- scoreboard_p -> active ,
536
- scoreboard_p -> idle + scoreboard_p -> active ,
537
- scoreboard_p -> active_max ,
538
- scoreboard_p -> max_children_reached ,
539
- scoreboard_p -> slow_rq );
524
+ if (fpm_php_is_key_in_table (_GET_str , ZEND_STRL ("openmetrics" ))) {
525
+ spprintf (& buffer , 0 , short_syntax ,
526
+ scoreboard_p -> pool ,
527
+ PM2STR (scoreboard_p -> pm ),
528
+ scoreboard_p -> pool ,
529
+ scoreboard_p -> pool ,
530
+ (unsigned long ) (now_epoch - scoreboard_p -> start_epoch ),
531
+ scoreboard_p -> pool ,
532
+ scoreboard_p -> requests ,
533
+ scoreboard_p -> pool ,
534
+ scoreboard_p -> lq ,
535
+ scoreboard_p -> pool ,
536
+ scoreboard_p -> lq_max ,
537
+ scoreboard_p -> pool ,
538
+ scoreboard_p -> lq_len ,
539
+ scoreboard_p -> pool ,
540
+ scoreboard_p -> idle ,
541
+ scoreboard_p -> pool ,
542
+ scoreboard_p -> active ,
543
+ scoreboard_p -> pool ,
544
+ scoreboard_p -> active_max ,
545
+ scoreboard_p -> pool ,
546
+ scoreboard_p -> max_children_reached ,
547
+ scoreboard_p -> pool ,
548
+ scoreboard_p -> slow_rq );
549
+ } else {
550
+ spprintf (& buffer , 0 , short_syntax ,
551
+ scoreboard_p -> pool ,
552
+ PM2STR (scoreboard_p -> pm ),
553
+ (unsigned long ) (now_epoch - scoreboard_p -> start_epoch ),
554
+ scoreboard_p -> requests ,
555
+ scoreboard_p -> lq ,
556
+ scoreboard_p -> lq_max ,
557
+ scoreboard_p -> lq_len ,
558
+ scoreboard_p -> idle ,
559
+ scoreboard_p -> active ,
560
+ scoreboard_p -> idle + scoreboard_p -> active ,
561
+ scoreboard_p -> active_max ,
562
+ scoreboard_p -> max_children_reached ,
563
+ scoreboard_p -> slow_rq );
564
+ }
540
565
}
541
566
542
567
PUTS (buffer );
@@ -550,9 +575,6 @@ int fpm_status_handle_request(void) /* {{{ */
550
575
/* no need to test the var 'full' */
551
576
if (full_syntax ) {
552
577
unsigned int i ;
553
- int first ;
554
- zend_string * tmp_query_string ;
555
- char * query_string ;
556
578
struct timeval duration , now ;
557
579
float cpu ;
558
580
@@ -562,7 +584,7 @@ int fpm_status_handle_request(void) /* {{{ */
562
584
PUTS (full_pre );
563
585
}
564
586
565
- if (fpm_php_get_string_from_table (_GET_str , "openmetrics" )) {
587
+ if (fpm_php_is_key_in_table (_GET_str , ZEND_STRL ( "openmetrics" ) )) {
566
588
spprintf (& buffer , 0 , "# HELP phpfpm_process_state The current state of the process (Idle, Running, ...).\n" );
567
589
PUTS (buffer );
568
590
spprintf (& buffer , 0 , "# TYPE phpfpm_process_state gauge\n" );
@@ -701,106 +723,110 @@ int fpm_status_handle_request(void) /* {{{ */
701
723
zend_string * tmp_query_string ;
702
724
char * query_string ;
703
725
704
- first = 1 ;
705
- for (i = 0 ; i < scoreboard_p -> nprocs ; i ++ ) {
706
- if (!scoreboard_p -> procs [i ].used ) {
707
- continue ;
708
- }
709
- proc = & scoreboard_p -> procs [i ];
710
-
711
- if (first ) {
712
- first = 0 ;
713
- } else {
714
- if (full_separator ) {
715
- PUTS (full_separator );
726
+ first = 1 ;
727
+ for (i = 0 ; i < scoreboard_p -> nprocs ; i ++ ) {
728
+ if (!scoreboard_p -> procs [i ].used ) {
729
+ continue ;
716
730
}
717
- }
731
+ proc = & scoreboard_p -> procs [ i ];
718
732
719
- query_string = NULL ;
720
- tmp_query_string = NULL ;
721
- if (proc -> query_string [0 ] != '\0' ) {
722
- if (encode_html ) {
723
- tmp_query_string = php_escape_html_entities_ex (
724
- (const unsigned char * ) proc -> query_string ,
725
- strlen (proc -> query_string ), 1 , ENT_HTML_IGNORE_ERRORS & ENT_COMPAT ,
726
- NULL , /* double_encode */ 1 , /* quiet */ 0 );
727
- } else if (encode_json ) {
728
- tmp_query_string = php_json_encode_string (proc -> query_string ,
729
- strlen (proc -> query_string ), PHP_JSON_INVALID_UTF8_IGNORE );
733
+ if (first ) {
734
+ first = 0 ;
730
735
} else {
731
- query_string = proc -> query_string ;
736
+ if (full_separator ) {
737
+ PUTS (full_separator );
738
+ }
732
739
}
733
- if (tmp_query_string ) {
734
- query_string = ZSTR_VAL (tmp_query_string );
735
- /* remove quotes around the string */
736
- if (encode_json && ZSTR_LEN (tmp_query_string ) >= 2 ) {
737
- query_string [ZSTR_LEN (tmp_query_string ) - 1 ] = '\0' ;
738
- ++ query_string ;
740
+
741
+ query_string = NULL ;
742
+ tmp_query_string = NULL ;
743
+ if (proc -> query_string [0 ] != '\0' ) {
744
+ if (encode_html ) {
745
+ tmp_query_string = php_escape_html_entities_ex (
746
+ (const unsigned char * ) proc -> query_string ,
747
+ strlen (proc -> query_string ), 1 , ENT_HTML_IGNORE_ERRORS & ENT_COMPAT ,
748
+ NULL , /* double_encode */ 1 , /* quiet */ 0 );
749
+ } else if (encode_json ) {
750
+ tmp_query_string = php_json_encode_string (proc -> query_string ,
751
+ strlen (proc -> query_string ), PHP_JSON_INVALID_UTF8_IGNORE );
752
+ } else {
753
+ query_string = proc -> query_string ;
754
+ }
755
+ if (tmp_query_string ) {
756
+ query_string = ZSTR_VAL (tmp_query_string );
757
+ /* remove quotes around the string */
758
+ if (encode_json && ZSTR_LEN (tmp_query_string ) >= 2 ) {
759
+ query_string [ZSTR_LEN (tmp_query_string ) - 1 ] = '\0' ;
760
+ ++ query_string ;
761
+ }
739
762
}
740
763
}
741
- }
742
764
743
- /* prevent NaN */
744
- if (proc -> cpu_duration .tv_sec == 0 && proc -> cpu_duration .tv_usec == 0 ) {
745
- cpu = 0. ;
746
- } else {
747
- cpu = (proc -> last_request_cpu .tms_utime + proc -> last_request_cpu .tms_stime + proc -> last_request_cpu .tms_cutime + proc -> last_request_cpu .tms_cstime ) / fpm_scoreboard_get_tick () / (proc -> cpu_duration .tv_sec + proc -> cpu_duration .tv_usec / 1000000. ) * 100. ;
748
- }
765
+ /* prevent NaN */
766
+ if (proc -> cpu_duration .tv_sec == 0 && proc -> cpu_duration .tv_usec == 0 ) {
767
+ cpu = 0. ;
768
+ } else {
769
+ cpu = (proc -> last_request_cpu .tms_utime + proc -> last_request_cpu .tms_stime + proc -> last_request_cpu .tms_cutime + proc -> last_request_cpu .tms_cstime ) / fpm_scoreboard_get_tick () / (proc -> cpu_duration .tv_sec + proc -> cpu_duration .tv_usec / 1000000. ) * 100. ;
770
+ }
749
771
750
- if (proc -> request_stage == FPM_REQUEST_ACCEPTING ) {
751
- duration = proc -> duration ;
752
- } else {
753
- timersub (& now , & proc -> accepted , & duration );
754
- }
772
+ if (proc -> request_stage == FPM_REQUEST_ACCEPTING ) {
773
+ duration = proc -> duration ;
774
+ } else {
775
+ timersub (& now , & proc -> accepted , & duration );
776
+ }
755
777
756
- if (fpm_php_is_key_in_table (_GET_str , ZEND_STRL ("openmetrics" ))) {
757
- spprintf (& buffer , 0 , full_syntax ,
758
- scoreboard_p -> pool ,
759
- (int ) proc -> pid ,
760
- fpm_request_get_stage_name (proc -> request_stage ),
761
- scoreboard_p -> pool ,
762
- (int ) proc -> pid ,
763
- (unsigned long ) (now_epoch - proc -> start_epoch ),
764
- scoreboard_p -> pool ,
765
- (int ) proc -> pid ,
766
- proc -> requests ,
767
- scoreboard_p -> pool ,
768
- (int ) proc -> pid ,
769
- (duration .tv_sec * 1000000UL + duration .tv_usec ) / 1000000. ,
770
- scoreboard_p -> pool ,
771
- (int ) proc -> pid ,
772
- (proc -> request_stage == FPM_REQUEST_ACCEPTING ? cpu : 0. ),
773
- scoreboard_p -> pool ,
774
- (int ) proc -> pid ,
775
- (proc -> request_stage == FPM_REQUEST_ACCEPTING ? proc -> memory : 0 ),
776
- scoreboard_p -> pool ,
777
- (int ) proc -> pid ,
778
- proc -> content_length );
779
- } else {
780
- strftime (time_buffer , sizeof (time_buffer ) - 1 , time_format , localtime (& proc -> start_epoch ));
781
- spprintf (& buffer , 0 , full_syntax ,
782
- (int ) proc -> pid ,
783
- fpm_request_get_stage_name (proc -> request_stage ),
784
- time_buffer ,
785
- (unsigned long ) (now_epoch - proc -> start_epoch ),
786
- proc -> requests ,
787
- duration .tv_sec * 1000000UL + duration .tv_usec ,
788
- proc -> request_method [0 ] != '\0' ? proc -> request_method : "-" ,
789
- proc -> request_uri [0 ] != '\0' ? proc -> request_uri : "-" ,
790
- query_string ? "?" : "" ,
791
- query_string ? query_string : "" ,
792
- proc -> content_length ,
793
- proc -> auth_user [0 ] != '\0' ? proc -> auth_user : "-" ,
794
- proc -> script_filename [0 ] != '\0' ? proc -> script_filename : "-" ,
795
- proc -> request_stage == FPM_REQUEST_ACCEPTING ? cpu : 0. ,
796
- proc -> request_stage == FPM_REQUEST_ACCEPTING ? proc -> memory : 0 );
797
- }
778
+ if (fpm_php_is_key_in_table (_GET_str , ZEND_STRL ("openmetrics" ))) {
779
+ spprintf (& buffer , 0 , full_syntax ,
780
+ scoreboard_p -> pool ,
781
+ i + 1 ,
782
+ (int ) proc -> pid ,
783
+ scoreboard_p -> pool ,
784
+ i + 1 ,
785
+ fpm_request_get_stage_name (proc -> request_stage ),
786
+ scoreboard_p -> pool ,
787
+ i + 1 ,
788
+ (unsigned long ) (now_epoch - proc -> start_epoch ),
789
+ scoreboard_p -> pool ,
790
+ i + 1 ,
791
+ proc -> requests ,
792
+ scoreboard_p -> pool ,
793
+ i + 1 ,
794
+ (duration .tv_sec * 1000000UL + duration .tv_usec ) / 1000000. ,
795
+ scoreboard_p -> pool ,
796
+ i + 1 ,
797
+ (proc -> request_stage == FPM_REQUEST_ACCEPTING ? cpu : 0. ),
798
+ scoreboard_p -> pool ,
799
+ i + 1 ,
800
+ (proc -> request_stage == FPM_REQUEST_ACCEPTING ? proc -> memory : 0 ),
801
+ scoreboard_p -> pool ,
802
+ i + 1 ,
803
+ proc -> content_length );
804
+ } else {
805
+ strftime (time_buffer , sizeof (time_buffer ) - 1 , time_format , localtime (& proc -> start_epoch ));
806
+ spprintf (& buffer , 0 , full_syntax ,
807
+ (int ) proc -> pid ,
808
+ fpm_request_get_stage_name (proc -> request_stage ),
809
+ time_buffer ,
810
+ (unsigned long ) (now_epoch - proc -> start_epoch ),
811
+ proc -> requests ,
812
+ duration .tv_sec * 1000000UL + duration .tv_usec ,
813
+ proc -> request_method [0 ] != '\0' ? proc -> request_method : "-" ,
814
+ proc -> request_uri [0 ] != '\0' ? proc -> request_uri : "-" ,
815
+ query_string ? "?" : "" ,
816
+ query_string ? query_string : "" ,
817
+ proc -> content_length ,
818
+ proc -> auth_user [0 ] != '\0' ? proc -> auth_user : "-" ,
819
+ proc -> script_filename [0 ] != '\0' ? proc -> script_filename : "-" ,
820
+ proc -> request_stage == FPM_REQUEST_ACCEPTING ? cpu : 0. ,
821
+ proc -> request_stage == FPM_REQUEST_ACCEPTING ? proc -> memory : 0 );
822
+ }
798
823
799
- PUTS (buffer );
800
- efree (buffer );
824
+ PUTS (buffer );
825
+ efree (buffer );
801
826
802
- if (tmp_query_string ) {
803
- zend_string_free (tmp_query_string );
827
+ if (tmp_query_string ) {
828
+ zend_string_free (tmp_query_string );
829
+ }
804
830
}
805
831
}
806
832
0 commit comments