Skip to content

Commit a468fff

Browse files
committed
cli: add command to dump metrics
1 parent 068a281 commit a468fff

File tree

9 files changed

+96
-10
lines changed

9 files changed

+96
-10
lines changed

book/api/cli.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,20 @@ $ fdctl shred-version
152152
9065
153153
```
154154

155+
## `metrics`
156+
Prints the current validator metrics to stdout. Metrics can typically
157+
be accessed via. HTTP when the `metric` tile is enabled, but the
158+
command can be used even if the metrics server is not enabled, or the
159+
validator has crashed.
160+
161+
```sh [bash]
162+
$ fdctl metrics --config ~/config.toml
163+
# HELP tile_pid The process ID of the tile.
164+
# TYPE tile_pid gauge
165+
tile_pid{kind="netlnk",kind_id="0"} 627750
166+
tile_pid{kind="net",kind_id="0"} 627759
167+
```
168+
155169
## `set-identity`
156170
Changes the identity key of a running validator. The `<keypair>`
157171
argument is required and must be the path to an Agave style

src/app/fdctl/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ extern action_t fd_action_set_identity;
9696
extern action_t fd_action_get_identity;
9797
extern action_t fd_action_help;
9898
extern action_t fd_action_version;
99+
extern action_t fd_action_metrics;
99100

100101
action_t * ACTIONS[] = {
101102
&fd_action_run,
@@ -111,6 +112,7 @@ action_t * ACTIONS[] = {
111112
&fd_action_get_identity,
112113
&fd_action_help,
113114
&fd_action_version,
115+
&fd_action_metrics,
114116
NULL,
115117
};
116118

src/app/fddev/main.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ extern action_t fd_action_dev1;
125125
extern action_t fd_action_dump;
126126
extern action_t fd_action_flame;
127127
extern action_t fd_action_help;
128+
extern action_t fd_action_metrics;
128129
extern action_t fd_action_load;
129130
extern action_t fd_action_pktgen;
130131
extern action_t fd_action_quic_trace;
@@ -145,6 +146,7 @@ action_t * ACTIONS[] = {
145146
&fd_action_set_identity,
146147
&fd_action_get_identity,
147148
&fd_action_help,
149+
&fd_action_metrics,
148150
&fd_action_version,
149151
&fd_action_bench,
150152
&fd_action_bundle_client,

src/app/firedancer-dev/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ extern action_t fd_action_dev;
170170
extern action_t fd_action_dump;
171171
extern action_t fd_action_flame;
172172
extern action_t fd_action_help;
173+
extern action_t fd_action_metrics;
173174
extern action_t fd_action_load;
174175
extern action_t fd_action_pktgen;
175176
extern action_t fd_action_quic_trace;
@@ -195,6 +196,7 @@ action_t * ACTIONS[] = {
195196
&fd_action_netconf,
196197
&fd_action_set_identity,
197198
&fd_action_help,
199+
&fd_action_metrics,
198200
&fd_action_version,
199201
&fd_action_bench,
200202
&fd_action_bundle_client,

src/app/firedancer/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ extern action_t fd_action_mem;
125125
extern action_t fd_action_netconf;
126126
extern action_t fd_action_set_identity;
127127
extern action_t fd_action_help;
128+
extern action_t fd_action_metrics;
128129
extern action_t fd_action_version;
129130
extern action_t fd_action_shred_version;
130131

@@ -139,6 +140,7 @@ action_t * ACTIONS[] = {
139140
&fd_action_netconf,
140141
&fd_action_set_identity,
141142
&fd_action_help,
143+
&fd_action_metrics,
142144
&fd_action_version,
143145
&fd_action_shred_version,
144146
NULL,

src/app/shared/Local.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ $(call add-objs,boot/fd_boot,fdctl_shared)
1515
$(call add-objs,commands/help,fdctl_shared)
1616
$(call add-objs,commands/keys,fdctl_shared)
1717
$(call add-objs,commands/mem,fdctl_shared)
18+
$(call add-objs,commands/metrics,fdctl_shared)
1819
$(call add-objs,commands/netconf,fdctl_shared)
1920
$(call add-objs,commands/ready,fdctl_shared)
2021
$(call add-objs,commands/set_identity,fdctl_shared)

src/app/shared/commands/metrics.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
config_t * config ) {
16+
fd_http_server_params_t params = {
17+
.max_connection_cnt = 0UL,
18+
.max_ws_connection_cnt = 0UL,
19+
.max_request_len = 0UL,
20+
.max_ws_recv_frame_len = 0UL,
21+
.max_ws_send_frame_cnt = 0UL,
22+
.outgoing_buffer_sz = (1UL<<28UL), /* 256MiB */
23+
};
24+
25+
fd_topo_join_workspaces( &config->topo, FD_SHMEM_JOIN_MODE_READ_ONLY );
26+
fd_topo_fill( &config->topo );
27+
28+
void * mem = aligned_alloc( fd_http_server_align(), fd_http_server_footprint( params ) );
29+
FD_TEST( mem );
30+
fd_http_server_t * http = fd_http_server_new( mem, params, (fd_http_server_callbacks_t){0}, NULL );
31+
fd_prometheus_render_all( &config->topo, http );
32+
33+
ulong bytes_written = 0UL;
34+
while( bytes_written<http->oring_sz ) {
35+
long written = write( STDOUT_FILENO, http->oring+bytes_written, http->oring_sz-bytes_written );
36+
if( FD_UNLIKELY( -1==written ) ) FD_LOG_ERR(( "write() failed: %d (%s)", errno, fd_io_strerror( errno ) ));
37+
bytes_written += http->oring_sz;
38+
}
39+
}
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+
};

src/app/shared/commands/metrics.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef HEADER_fd_src_app_shared_commands_metrics_h
2+
#define HEADER_fd_src_app_shared_commands_metrics_h
3+
4+
#include "../fd_config.h"
5+
6+
FD_PROTOTYPES_BEGIN
7+
8+
void metrics_cmd_fn( args_t * args, config_t * config );
9+
10+
FD_PROTOTYPES_END
11+
12+
extern action_t fd_action_metrics;
13+
14+
#endif /* HEADER_fd_src_app_shared_commands_metrics_h */

src/waltz/http/fd_http_server.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,16 @@ fd_http_server_align( void ) {
104104
FD_FN_CONST ulong
105105
fd_http_server_footprint( fd_http_server_params_t params ) {
106106
ulong l = FD_LAYOUT_INIT;
107-
l = FD_LAYOUT_APPEND( l, FD_HTTP_SERVER_ALIGN, sizeof( fd_http_server_t ) );
108-
l = FD_LAYOUT_APPEND( l, conn_pool_align(), conn_pool_footprint( params.max_connection_cnt ) );
109-
l = FD_LAYOUT_APPEND( l, ws_conn_pool_align(), ws_conn_pool_footprint( params.max_ws_connection_cnt ) );
110-
l = FD_LAYOUT_APPEND( l, conn_treap_align(), conn_treap_footprint( params.max_connection_cnt ) );
111-
l = FD_LAYOUT_APPEND( l, ws_conn_treap_align(), ws_conn_treap_footprint( params.max_ws_connection_cnt ) );
112-
l = FD_LAYOUT_APPEND( l, alignof( struct pollfd ), (params.max_connection_cnt+params.max_ws_connection_cnt+1UL)*sizeof( struct pollfd ) );
113-
l = FD_LAYOUT_APPEND( l, 1UL, params.max_request_len*params.max_connection_cnt );
114-
l = FD_LAYOUT_APPEND( l, 1UL, params.max_ws_recv_frame_len*params.max_ws_connection_cnt );
115-
l = FD_LAYOUT_APPEND( l, alignof( struct fd_http_server_ws_frame ), params.max_ws_send_frame_cnt*params.max_ws_connection_cnt*sizeof( struct fd_http_server_ws_frame ) );
116-
l = FD_LAYOUT_APPEND( l, 1UL, params.outgoing_buffer_sz );
107+
l = FD_LAYOUT_APPEND( l, FD_HTTP_SERVER_ALIGN, sizeof( fd_http_server_t ) );
108+
l = FD_LAYOUT_APPEND( l, conn_pool_align(), conn_pool_footprint( params.max_connection_cnt ) );
109+
l = FD_LAYOUT_APPEND( l, ws_conn_pool_align(), ws_conn_pool_footprint( params.max_ws_connection_cnt ) );
110+
l = FD_LAYOUT_APPEND( l, conn_treap_align(), conn_treap_footprint( params.max_connection_cnt ) );
111+
l = FD_LAYOUT_APPEND( l, ws_conn_treap_align(), ws_conn_treap_footprint( params.max_ws_connection_cnt ) );
112+
l = FD_LAYOUT_APPEND( l, alignof( struct pollfd ), (params.max_connection_cnt+params.max_ws_connection_cnt+1UL)*sizeof( struct pollfd ) );
113+
l = FD_LAYOUT_APPEND( l, 1UL, params.max_request_len*params.max_connection_cnt );
114+
l = FD_LAYOUT_APPEND( l, 1UL, params.max_ws_recv_frame_len*params.max_ws_connection_cnt );
115+
l = FD_LAYOUT_APPEND( l, alignof( struct fd_http_server_ws_frame ), params.max_ws_send_frame_cnt*params.max_ws_connection_cnt*sizeof( struct fd_http_server_ws_frame ) );
116+
l = FD_LAYOUT_APPEND( l, 1UL, params.outgoing_buffer_sz );
117117
return FD_LAYOUT_FINI( l, fd_http_server_align() );
118118
}
119119

0 commit comments

Comments
 (0)