Skip to content

Commit 35c42f2

Browse files
authored
feat: add node info metrics (#43)
* feat: add node info metrics * docs: update docs/metrics.md
1 parent 5d0bae6 commit 35c42f2

File tree

9 files changed

+237
-12
lines changed

9 files changed

+237
-12
lines changed

Cargo.lock

Lines changed: 152 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,7 @@ ethereum_ssz = "0.8.3"
6161
ssz_types = "0.10.1"
6262
tree_hash = "0.9.1"
6363
tree_hash_derive = "0.9.1"
64+
65+
# Build-time version info
66+
vergen = { version = "9", features = ["build", "rustc"] }
67+
vergen-git2 = "9"

bin/ethlambda/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ hex.workspace = true
2525

2626
ethereum-types.workspace = true
2727
clap.workspace = true
28+
29+
[build-dependencies]
30+
vergen.workspace = true
31+
vergen-git2.workspace = true

bin/ethlambda/build.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use vergen::{Emitter, RustcBuilder};
2+
use vergen_git2::Git2Builder;
3+
4+
fn main() -> Result<(), Box<dyn std::error::Error>> {
5+
let git2 = Git2Builder::default().branch(true).sha(true).build()?;
6+
let rustc = RustcBuilder::default()
7+
.semver(true)
8+
.host_triple(true)
9+
.build()?;
10+
11+
Emitter::default()
12+
.add_instructions(&rustc)?
13+
.add_instructions(&git2)?
14+
.emit()?;
15+
16+
Ok(())
17+
}

bin/ethlambda/src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
mod version;
2+
13
use std::{
24
collections::{BTreeMap, HashMap},
35
net::{IpAddr, SocketAddr},
@@ -27,6 +29,7 @@ const ASCII_ART: &str = r#"
2729
"#;
2830

2931
#[derive(Debug, clap::Parser)]
32+
#[command(name = "ethlambda", author = "LambdaClass", version = version::CLIENT_VERSION, about = "ethlambda consensus client")]
3033
struct CliOptions {
3134
#[arg(long)]
3235
custom_network_config_dir: PathBuf,
@@ -53,6 +56,10 @@ async fn main() {
5356

5457
let options = CliOptions::parse();
5558

59+
// Set node info metrics
60+
ethlambda_blockchain::metrics::set_node_info("ethlambda", version::CLIENT_VERSION);
61+
ethlambda_blockchain::metrics::set_node_start_time();
62+
5663
let metrics_socket = SocketAddr::new(options.metrics_address, options.metrics_port);
5764
let node_p2p_key = read_hex_file_bytes(&options.node_key);
5865
let p2p_socket = SocketAddr::new(IpAddr::from([0, 0, 0, 0]), options.gossipsub_port);

bin/ethlambda/src/version.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// Client version string with git info.
2+
/// Format: ethlambda/v0.1.0-main-892ad575.../x86_64-unknown-linux-gnu/rustc-v1.85.0
3+
pub const CLIENT_VERSION: &str = concat!(
4+
env!("CARGO_PKG_NAME"),
5+
"/v",
6+
env!("CARGO_PKG_VERSION"),
7+
"-",
8+
env!("VERGEN_GIT_BRANCH"),
9+
"-",
10+
env!("VERGEN_GIT_SHA"),
11+
"/",
12+
env!("VERGEN_RUSTC_HOST_TRIPLE"),
13+
"/rustc-v",
14+
env!("VERGEN_RUSTC_SEMVER")
15+
);

crates/blockchain/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use tokio::sync::mpsc;
1717
use tracing::{error, info, warn};
1818

1919
pub mod key_manager;
20-
mod metrics;
20+
pub mod metrics;
2121
pub mod store;
2222

2323
/// Messages sent from the blockchain to the P2P layer for publishing.

crates/blockchain/src/metrics.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,32 @@ pub fn update_safe_target_slot(slot: u64) {
5555
});
5656
LEAN_SAFE_TARGET_SLOT.set(slot.try_into().unwrap());
5757
}
58+
59+
pub 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+
});
69+
LEAN_NODE_INFO.with_label_values(&[name, version]).set(1);
70+
}
71+
72+
pub fn set_node_start_time() {
73+
static LEAN_NODE_START_TIME_SECONDS: std::sync::LazyLock<prometheus::IntGauge> =
74+
std::sync::LazyLock::new(|| {
75+
prometheus::register_int_gauge!(
76+
"lean_node_start_time_seconds",
77+
"Timestamp when node started"
78+
)
79+
.unwrap()
80+
});
81+
let timestamp = std::time::SystemTime::now()
82+
.duration_since(std::time::UNIX_EPOCH)
83+
.unwrap()
84+
.as_secs();
85+
LEAN_NODE_START_TIME_SECONDS.set(timestamp as i64);
86+
}

0 commit comments

Comments
 (0)