1- use std:: num:: NonZeroUsize ;
1+ use std:: { collections :: HashMap , num:: NonZeroUsize } ;
22
33use lru:: LruCache ;
44use prometheus_exporter:: prometheus:: {
@@ -19,6 +19,7 @@ pub struct State {
1919 pub checksums : Checksums ,
2020 pub blocks : LruCache < Height , Block > ,
2121 pub metrics : PrometheusMetrics ,
22+ pub chain_id : String ,
2223}
2324
2425#[ derive( Debug , Clone ) ]
@@ -35,15 +36,13 @@ pub struct PrometheusMetrics {
3536 registry : Registry ,
3637}
3738
38- impl Default for PrometheusMetrics {
39- fn default ( ) -> Self {
40- Self :: new ( )
41- }
42- }
43-
4439impl PrometheusMetrics {
45- pub fn new ( ) -> Self {
46- let registry = Registry :: new_custom ( None , None ) . expect ( "Failed to create registry" ) ;
40+ pub fn new ( chain_id : String ) -> Self {
41+ let registry = Registry :: new_custom (
42+ Some ( "namada" . to_string ( ) ) ,
43+ Some ( HashMap :: from_iter ( [ ( "chain_id" . to_string ( ) , chain_id) ] ) ) ,
44+ )
45+ . expect ( "Failed to create registry" ) ;
4746
4847 let block_height_counter =
4948 GenericCounter :: < AtomicU64 > :: new ( "block_height" , "the latest block height recorded" )
@@ -144,14 +143,15 @@ impl PrometheusMetrics {
144143}
145144
146145impl State {
147- pub fn new ( checksums : Checksums , block_height : u64 ) -> Self {
146+ pub fn new ( checksums : Checksums , block_height : u64 , chain_id : String ) -> Self {
148147 Self {
149148 latest_block_height : Some ( block_height) ,
150149 latest_epoch : None ,
151150 latest_total_supply_native : None ,
152151 checksums,
153152 blocks : LruCache :: new ( NonZeroUsize :: new ( 1024 ) . unwrap ( ) ) ,
154- metrics : PrometheusMetrics :: new ( ) ,
153+ metrics : PrometheusMetrics :: new ( chain_id. clone ( ) ) ,
154+ chain_id,
155155 }
156156 }
157157
0 commit comments