Line data Source code
1 : #include "../fd_config.h" 2 : #include "../fd_action.h" 3 : 4 : #include "../../../disco/metrics/fd_prometheus.h" 5 : #include "../../../waltz/http/fd_http_server_private.h" 6 : 7 : #include <unistd.h> 8 : #include <errno.h> 9 : #include <stdlib.h> 10 : 11 : extern action_t * ACTIONS[]; 12 : 13 : void 14 : metrics_cmd_fn( args_t * args FD_PARAM_UNUSED, 15 0 : config_t * config ) { 16 0 : fd_http_server_params_t params = { 17 0 : .max_connection_cnt = 0UL, 18 0 : .max_ws_connection_cnt = 0UL, 19 0 : .max_request_len = 0UL, 20 0 : .max_ws_recv_frame_len = 0UL, 21 0 : .max_ws_send_frame_cnt = 0UL, 22 0 : .outgoing_buffer_sz = (1UL<<28UL), /* 256MiB */ 23 0 : }; 24 : 25 0 : fd_topo_join_workspaces( &config->topo, FD_SHMEM_JOIN_MODE_READ_ONLY ); 26 0 : fd_topo_fill( &config->topo ); 27 : 28 0 : void * mem = aligned_alloc( fd_http_server_align(), fd_http_server_footprint( params ) ); 29 0 : FD_TEST( mem ); 30 0 : fd_http_server_t * http = fd_http_server_new( mem, params, (fd_http_server_callbacks_t){0}, NULL ); 31 0 : fd_prometheus_render_all( &config->topo, http ); 32 : 33 0 : ulong bytes_written = 0UL; 34 0 : while( bytes_written<http->oring_sz ) { 35 0 : long written = write( STDOUT_FILENO, http->oring+bytes_written, http->oring_sz-bytes_written ); 36 0 : if( FD_UNLIKELY( -1==written ) ) FD_LOG_ERR(( "write() failed: %d (%s)", errno, fd_io_strerror( errno ) )); 37 0 : bytes_written += http->oring_sz; 38 0 : } 39 0 : } 40 : 41 : action_t fd_action_metrics = { 42 : .name = "metrics", 43 : .args = NULL, 44 : .fn = metrics_cmd_fn, 45 : .perm = NULL, 46 : .description = "Print the current validator Prometheus metrics to STDOUT", 47 : .is_immediate = 0, 48 : .is_diagnostic = 1, 49 : };