11//! Prometheus metrics for the blockchain module.
22
3+ use ethlambda_metrics:: * ;
4+
35pub fn update_head_slot ( slot : u64 ) {
4- static LEAN_HEAD_SLOT : std:: sync:: LazyLock < prometheus:: IntGauge > =
5- std:: sync:: LazyLock :: new ( || {
6- prometheus:: register_int_gauge!( "lean_head_slot" , "Latest slot of the lean chain" )
7- . unwrap ( )
8- } ) ;
6+ static LEAN_HEAD_SLOT : std:: sync:: LazyLock < IntGauge > = std:: sync:: LazyLock :: new ( || {
7+ register_int_gauge ! ( "lean_head_slot" , "Latest slot of the lean chain" ) . unwrap ( )
8+ } ) ;
99 LEAN_HEAD_SLOT . set ( slot. try_into ( ) . unwrap ( ) ) ;
1010}
1111
1212pub fn update_latest_justified_slot ( slot : u64 ) {
13- static LEAN_LATEST_JUSTIFIED_SLOT : std:: sync:: LazyLock < prometheus :: IntGauge > =
13+ static LEAN_LATEST_JUSTIFIED_SLOT : std:: sync:: LazyLock < IntGauge > =
1414 std:: sync:: LazyLock :: new ( || {
15- prometheus:: register_int_gauge!( "lean_latest_justified_slot" , "Latest justified slot" )
16- . unwrap ( )
15+ register_int_gauge ! ( "lean_latest_justified_slot" , "Latest justified slot" ) . unwrap ( )
1716 } ) ;
1817 LEAN_LATEST_JUSTIFIED_SLOT . set ( slot. try_into ( ) . unwrap ( ) ) ;
1918}
2019
2120pub fn update_latest_finalized_slot ( slot : u64 ) {
22- static LEAN_LATEST_FINALIZED_SLOT : std:: sync:: LazyLock < prometheus :: IntGauge > =
21+ static LEAN_LATEST_FINALIZED_SLOT : std:: sync:: LazyLock < IntGauge > =
2322 std:: sync:: LazyLock :: new ( || {
24- prometheus:: register_int_gauge!( "lean_latest_finalized_slot" , "Latest finalized slot" )
25- . unwrap ( )
23+ register_int_gauge ! ( "lean_latest_finalized_slot" , "Latest finalized slot" ) . unwrap ( )
2624 } ) ;
2725 LEAN_LATEST_FINALIZED_SLOT . set ( slot. try_into ( ) . unwrap ( ) ) ;
2826}
2927
3028pub fn update_current_slot ( slot : u64 ) {
31- static LEAN_CURRENT_SLOT : std:: sync:: LazyLock < prometheus:: IntGauge > =
32- std:: sync:: LazyLock :: new ( || {
33- prometheus:: register_int_gauge!( "lean_current_slot" , "Current slot of the lean chain" )
34- . unwrap ( )
35- } ) ;
29+ static LEAN_CURRENT_SLOT : std:: sync:: LazyLock < IntGauge > = std:: sync:: LazyLock :: new ( || {
30+ register_int_gauge ! ( "lean_current_slot" , "Current slot of the lean chain" ) . unwrap ( )
31+ } ) ;
3632 LEAN_CURRENT_SLOT . set ( slot. try_into ( ) . unwrap ( ) ) ;
3733}
3834
3935pub fn update_validators_count ( count : u64 ) {
40- static LEAN_VALIDATORS_COUNT : std:: sync:: LazyLock < prometheus:: IntGauge > =
41- std:: sync:: LazyLock :: new ( || {
42- prometheus:: register_int_gauge!(
43- "lean_validators_count" ,
44- "Number of validators managed by a node"
45- )
46- . unwrap ( )
47- } ) ;
36+ static LEAN_VALIDATORS_COUNT : std:: sync:: LazyLock < IntGauge > = std:: sync:: LazyLock :: new ( || {
37+ register_int_gauge ! (
38+ "lean_validators_count" ,
39+ "Number of validators managed by a node"
40+ )
41+ . unwrap ( )
42+ } ) ;
4843 LEAN_VALIDATORS_COUNT . set ( count. try_into ( ) . unwrap ( ) ) ;
4944}
5045
5146pub fn update_safe_target_slot ( slot : u64 ) {
52- static LEAN_SAFE_TARGET_SLOT : std:: sync:: LazyLock < prometheus:: IntGauge > =
53- std:: sync:: LazyLock :: new ( || {
54- prometheus:: register_int_gauge!( "lean_safe_target_slot" , "Safe target slot" ) . unwrap ( )
55- } ) ;
47+ static LEAN_SAFE_TARGET_SLOT : std:: sync:: LazyLock < IntGauge > = std:: sync:: LazyLock :: new ( || {
48+ register_int_gauge ! ( "lean_safe_target_slot" , "Safe target slot" ) . unwrap ( )
49+ } ) ;
5650 LEAN_SAFE_TARGET_SLOT . set ( slot. try_into ( ) . unwrap ( ) ) ;
5751}
5852
5953pub fn set_node_info ( name : & str , version : & str ) {
60- static LEAN_NODE_INFO : std:: sync:: LazyLock < prometheus:: IntGaugeVec > =
61- std:: sync:: LazyLock :: new ( || {
62- prometheus:: register_int_gauge_vec!(
63- "lean_node_info" ,
64- "Node information (always 1)" ,
65- & [ "name" , "version" ]
66- )
67- . unwrap ( )
68- } ) ;
54+ static LEAN_NODE_INFO : std:: sync:: LazyLock < IntGaugeVec > = std:: sync:: LazyLock :: new ( || {
55+ register_int_gauge_vec ! (
56+ "lean_node_info" ,
57+ "Node information (always 1)" ,
58+ & [ "name" , "version" ]
59+ )
60+ . unwrap ( )
61+ } ) ;
6962 LEAN_NODE_INFO . with_label_values ( & [ name, version] ) . set ( 1 ) ;
7063}
7164
7265pub fn set_node_start_time ( ) {
73- static LEAN_NODE_START_TIME_SECONDS : std:: sync:: LazyLock < prometheus :: IntGauge > =
66+ static LEAN_NODE_START_TIME_SECONDS : std:: sync:: LazyLock < IntGauge > =
7467 std:: sync:: LazyLock :: new ( || {
75- prometheus :: register_int_gauge!(
68+ register_int_gauge ! (
7669 "lean_node_start_time_seconds" ,
7770 "Timestamp when node started"
7871 )
@@ -87,9 +80,9 @@ pub fn set_node_start_time() {
8780
8881/// Increment the valid attestations counter.
8982pub fn inc_attestations_valid ( source : & str ) {
90- static LEAN_ATTESTATIONS_VALID_TOTAL : std:: sync:: LazyLock < prometheus :: IntCounterVec > =
83+ static LEAN_ATTESTATIONS_VALID_TOTAL : std:: sync:: LazyLock < IntCounterVec > =
9184 std:: sync:: LazyLock :: new ( || {
92- prometheus :: register_int_counter_vec!(
85+ register_int_counter_vec ! (
9386 "lean_attestations_valid_total" ,
9487 "Count of valid attestations" ,
9588 & [ "source" ]
@@ -103,9 +96,9 @@ pub fn inc_attestations_valid(source: &str) {
10396
10497/// Increment the invalid attestations counter.
10598pub fn inc_attestations_invalid ( source : & str ) {
106- static LEAN_ATTESTATIONS_INVALID_TOTAL : std:: sync:: LazyLock < prometheus :: IntCounterVec > =
99+ static LEAN_ATTESTATIONS_INVALID_TOTAL : std:: sync:: LazyLock < IntCounterVec > =
107100 std:: sync:: LazyLock :: new ( || {
108- prometheus :: register_int_counter_vec!(
101+ register_int_counter_vec ! (
109102 "lean_attestations_invalid_total" ,
110103 "Count of invalid attestations" ,
111104 & [ "source" ]
@@ -119,13 +112,41 @@ pub fn inc_attestations_invalid(source: &str) {
119112
120113/// Increment the fork choice reorgs counter.
121114pub fn inc_fork_choice_reorgs ( ) {
122- static LEAN_FORK_CHOICE_REORGS_TOTAL : std:: sync:: LazyLock < prometheus :: IntCounter > =
115+ static LEAN_FORK_CHOICE_REORGS_TOTAL : std:: sync:: LazyLock < IntCounter > =
123116 std:: sync:: LazyLock :: new ( || {
124- prometheus :: register_int_counter!(
117+ register_int_counter ! (
125118 "lean_fork_choice_reorgs_total" ,
126119 "Count of fork choice reorganizations"
127120 )
128121 . unwrap ( )
129122 } ) ;
130123 LEAN_FORK_CHOICE_REORGS_TOTAL . inc ( ) ;
131124}
125+
126+ /// Start timing fork choice block processing. Records duration when the guard is dropped.
127+ pub fn time_fork_choice_block_processing ( ) -> TimingGuard {
128+ static LEAN_FORK_CHOICE_BLOCK_PROCESSING_TIME_SECONDS : std:: sync:: LazyLock < Histogram > =
129+ std:: sync:: LazyLock :: new ( || {
130+ register_histogram ! (
131+ "lean_fork_choice_block_processing_time_seconds" ,
132+ "Duration to process a block" ,
133+ vec![ 0.005 , 0.01 , 0.025 , 0.05 , 0.1 , 1.0 ]
134+ )
135+ . unwrap ( )
136+ } ) ;
137+ TimingGuard :: new ( & LEAN_FORK_CHOICE_BLOCK_PROCESSING_TIME_SECONDS )
138+ }
139+
140+ /// Start timing attestation validation. Records duration when the guard is dropped.
141+ pub fn time_attestation_validation ( ) -> TimingGuard {
142+ static LEAN_ATTESTATION_VALIDATION_TIME_SECONDS : std:: sync:: LazyLock < Histogram > =
143+ std:: sync:: LazyLock :: new ( || {
144+ register_histogram ! (
145+ "lean_attestation_validation_time_seconds" ,
146+ "Duration to validate an attestation" ,
147+ vec![ 0.005 , 0.01 , 0.025 , 0.05 , 0.1 , 1.0 ]
148+ )
149+ . unwrap ( )
150+ } ) ;
151+ TimingGuard :: new ( & LEAN_ATTESTATION_VALIDATION_TIME_SECONDS )
152+ }
0 commit comments