@@ -395,6 +395,7 @@ int fpm_status_handle_request(void) /* {{{ */
395
395
"phpfpm_up 1\n"
396
396
"# HELP phpfpm_start_since The number of seconds since FPM has started.\n"
397
397
"# TYPE phpfpm_start_since counter\n"
398
+ "# UNIT phpfpm_start_since seconds\n"
398
399
"phpfpm_start_since %lu\n"
399
400
"# HELP phpfpm_accepted_connections The number of requests accepted by the pool.\n"
400
401
"# TYPE phpfpm_accepted_connections counter\n"
@@ -425,17 +426,41 @@ int fpm_status_handle_request(void) /* {{{ */
425
426
"phpfpm_max_children_reached %u\n"
426
427
"# HELP phpfpm_slow_requests The number of requests that exceeded your 'request_slowlog_timeout' value.\n"
427
428
"# TYPE phpfpm_slow_requests counter\n"
428
- "phpfpm_slow_requests %lu\n"
429
- "# EOF\n" ;
429
+ "phpfpm_slow_requests %lu\n" ;
430
430
431
431
has_start_time = 0 ;
432
432
if (!full ) {
433
- short_post = "" ;
433
+ short_post = "# EOF\n " ;
434
434
} else {
435
435
full_separator = "" ;
436
436
full_pre = "" ;
437
- full_syntax = "" ;
438
- full_post = "" ;
437
+ full_syntax =
438
+ "# HELP phpfpm_process_state The current state of the process (Idle, Running, ...).\n"
439
+ "# TYPE phpfpm_process_state gauge\n"
440
+ "phpfpm_process_state{pool=\"%s\",pid=\"%d\",state=\"%s\"} 1\n"
441
+ "# HELP phpfpm_process_start_since_seconds The number of seconds since the process started.\n"
442
+ "# TYPE phpfpm_process_start_since_seconds counter\n"
443
+ "# UNIT phpfpm_process_start_since_seconds seconds\n"
444
+ "phpfpm_process_start_since_seconds{pool=\"%s\",pid=\"%d\"} %lu\n"
445
+ "# HELP phpfpm_process_requests_total The total number of requests served.\n"
446
+ "# TYPE phpfpm_process_requests_total counter\n"
447
+ "phpfpm_process_requests_total{pool=\"%s\",pid=\"%d\"} %lu\n"
448
+ "# HELP phpfpm_process_request_seconds Time in seconds serving the current or last request.\n"
449
+ "# TYPE phpfpm_process_request_seconds gauge\n"
450
+ "# UNIT phpfpm_process_request_seconds seconds\n"
451
+ "phpfpm_process_request_seconds{pool=\"%s\",pid=\"%d\"} %.6f\n"
452
+ "# 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
+ "# TYPE phpfpm_process_request_cpu gauge\n"
454
+ "phpfpm_process_request_cpu{pool=\"%s\",pid=\"%d\"} %.2f\n"
455
+ "# 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
+ "# TYPE phpfpm_process_request_memory_bytes gauge\n"
457
+ "# UNIT phpfpm_process_request_memory_bytes bytes\n"
458
+ "phpfpm_process_request_memory_bytes{pool=\"%s\",pid=\"%d\"} %zu\n"
459
+ "# HELP phpfpm_process_request_content_length_bytes The length of the request body, in bytes, of the last request.\n"
460
+ "# TYPE phpfpm_process_request_content_length_bytes gauge\n"
461
+ "# UNIT phpfpm_process_request_content_length_bytes bytes\n"
462
+ "phpfpm_process_request_content_length_bytes{pool=\"%s\",pid=\"%d\"} %zu\n" ;
463
+ full_post = "# EOF\n" ;
439
464
}
440
465
441
466
/* TEXT */
@@ -588,23 +613,50 @@ int fpm_status_handle_request(void) /* {{{ */
588
613
} else {
589
614
timersub (& now , & proc -> accepted , & duration );
590
615
}
591
- strftime (time_buffer , sizeof (time_buffer ) - 1 , time_format , localtime (& proc -> start_epoch ));
592
- spprintf (& buffer , 0 , full_syntax ,
593
- (int ) proc -> pid ,
594
- fpm_request_get_stage_name (proc -> request_stage ),
595
- time_buffer ,
596
- (unsigned long ) (now_epoch - proc -> start_epoch ),
597
- proc -> requests ,
598
- duration .tv_sec * 1000000UL + duration .tv_usec ,
599
- proc -> request_method [0 ] != '\0' ? proc -> request_method : "-" ,
600
- proc -> request_uri [0 ] != '\0' ? proc -> request_uri : "-" ,
601
- query_string ? "?" : "" ,
602
- query_string ? query_string : "" ,
603
- proc -> content_length ,
604
- proc -> auth_user [0 ] != '\0' ? proc -> auth_user : "-" ,
605
- proc -> script_filename [0 ] != '\0' ? proc -> script_filename : "-" ,
606
- proc -> request_stage == FPM_REQUEST_ACCEPTING ? cpu : 0. ,
607
- proc -> request_stage == FPM_REQUEST_ACCEPTING ? proc -> memory : 0 );
616
+
617
+ if (fpm_php_is_key_in_table (_GET_str , ZEND_STRL ("openmetrics" ))) {
618
+ spprintf (& buffer , 0 , full_syntax ,
619
+ scoreboard_p -> pool ,
620
+ (int ) proc -> pid ,
621
+ fpm_request_get_stage_name (proc -> request_stage ),
622
+ scoreboard_p -> pool ,
623
+ (int ) proc -> pid ,
624
+ (unsigned long ) (now_epoch - proc -> start_epoch ),
625
+ scoreboard_p -> pool ,
626
+ (int ) proc -> pid ,
627
+ proc -> requests ,
628
+ scoreboard_p -> pool ,
629
+ (int ) proc -> pid ,
630
+ (duration .tv_sec * 1000000UL + duration .tv_usec ) / 1000000. ,
631
+ scoreboard_p -> pool ,
632
+ (int ) proc -> pid ,
633
+ (proc -> request_stage == FPM_REQUEST_ACCEPTING ? cpu : 0. ),
634
+ scoreboard_p -> pool ,
635
+ (int ) proc -> pid ,
636
+ (proc -> request_stage == FPM_REQUEST_ACCEPTING ? proc -> memory : 0 ),
637
+ scoreboard_p -> pool ,
638
+ (int ) proc -> pid ,
639
+ proc -> content_length );
640
+ } else {
641
+ strftime (time_buffer , sizeof (time_buffer ) - 1 , time_format , localtime (& proc -> start_epoch ));
642
+ spprintf (& buffer , 0 , full_syntax ,
643
+ (int ) proc -> pid ,
644
+ fpm_request_get_stage_name (proc -> request_stage ),
645
+ time_buffer ,
646
+ (unsigned long ) (now_epoch - proc -> start_epoch ),
647
+ proc -> requests ,
648
+ duration .tv_sec * 1000000UL + duration .tv_usec ,
649
+ proc -> request_method [0 ] != '\0' ? proc -> request_method : "-" ,
650
+ proc -> request_uri [0 ] != '\0' ? proc -> request_uri : "-" ,
651
+ query_string ? "?" : "" ,
652
+ query_string ? query_string : "" ,
653
+ proc -> content_length ,
654
+ proc -> auth_user [0 ] != '\0' ? proc -> auth_user : "-" ,
655
+ proc -> script_filename [0 ] != '\0' ? proc -> script_filename : "-" ,
656
+ proc -> request_stage == FPM_REQUEST_ACCEPTING ? cpu : 0. ,
657
+ proc -> request_stage == FPM_REQUEST_ACCEPTING ? proc -> memory : 0 );
658
+ }
659
+
608
660
PUTS (buffer );
609
661
efree (buffer );
610
662
0 commit comments