-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from supernovahs/supernovahs/metrics
feat(metrics)
- Loading branch information
Showing
17 changed files
with
1,320 additions
and
42 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,41 @@ | ||
use alloy_primitives::{Address, U256}; | ||
use eigen_client_avsregistry::reader::AvsRegistryChainReader; | ||
use eigen_client_elcontracts::reader::ELChainReader; | ||
use std::collections::HashMap; | ||
use eigen_metrics_derive::Metrics; | ||
use metrics::{Gauge, Key, Label}; | ||
|
||
pub struct Collector { | ||
elreader: ELChainReader, | ||
avs_registry_reader: AvsRegistryChainReader, | ||
operator_addr: Address, | ||
operator_id: [u8; 32], | ||
quorum_names: HashMap<u8, String>, | ||
#[derive(Clone, Metrics)] | ||
#[metrics(scope = "eigen.registeredstakes")] | ||
pub struct RegisteredStakes { | ||
#[metric( | ||
rename = "eigen_registered_stakes", | ||
describe = " A gauge with weighted delegation of delegated shares in delegation manager contract " | ||
)] | ||
registered_stake: Gauge, | ||
} | ||
|
||
impl Collector { | ||
pub fn new( | ||
elreader: ELChainReader, | ||
avs_registry_reader: AvsRegistryChainReader, | ||
operator_addr: Address, | ||
operator_id: [u8; 32], | ||
quorum_names: HashMap<u8, String>, | ||
) -> Self { | ||
Self { | ||
elreader, | ||
avs_registry_reader, | ||
operator_addr, | ||
operator_id, | ||
quorum_names, | ||
} | ||
impl RegisteredStakes { | ||
pub fn new() -> Self { | ||
let gauge = Self { | ||
registered_stake: metrics::register_gauge!("eigen_registered_stakes"), | ||
}; | ||
RegisteredStakes::describe(); | ||
|
||
gauge | ||
} | ||
|
||
pub fn describe(&self) {} | ||
pub fn set_stake(&self, quorum_number: &str, quorum_name: &str, value: f64) { | ||
// Create the metric key with dynamic labels | ||
let key = Key::from_parts( | ||
"eigen_registered_stakes", | ||
vec![ | ||
Label::new("quorum_number", quorum_number.to_string()), | ||
Label::new("quorum_name", quorum_name.to_string()), | ||
], | ||
); | ||
|
||
pub fn init_operator_id(&self) {} | ||
// Register or retrieve the gauge with the specified key and set the value | ||
metrics::gauge!(key.to_string(), value); | ||
} | ||
|
||
pub fn collect(&self) {} | ||
pub fn registered_stakes(&self) -> Gauge { | ||
self.registered_stake.clone() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,74 @@ | ||
pub struct Collector {} | ||
use eigen_metrics_derive::Metrics; | ||
use metrics::{Counter, Histogram, Key, Label}; | ||
|
||
#[derive(Clone, Metrics)] | ||
#[metrics(scope = "eigen.rpcmetrics")] | ||
pub struct RpcCalls { | ||
#[metric( | ||
rename = "eigen_rpc_request_duration_seconds", | ||
describe = " Duration of json-rpc <method> in seconds from Ethereum Execution client <client> " | ||
)] | ||
rpc_request_duration_seconds: Histogram, | ||
#[metric( | ||
rename = "eigen_rpc_request_total", | ||
describe = "Total of json-rpc <method> requests from Ethereum Execution client <client> " | ||
)] | ||
rpc_request_total: Counter, | ||
} | ||
|
||
impl RpcCalls { | ||
pub fn new() -> Self { | ||
let rpc_calls = Self { | ||
rpc_request_duration_seconds: metrics::register_histogram!( | ||
"eigen_rpc_request_duration_seconds" | ||
), | ||
rpc_request_total: metrics::register_counter!("eigen_rpc_request_total"), | ||
}; | ||
|
||
RpcCalls::describe(); | ||
|
||
rpc_calls | ||
} | ||
|
||
pub fn rpc_request_duration_seconds(&self) -> Histogram { | ||
self.rpc_request_duration_seconds.clone() | ||
} | ||
|
||
pub fn rpc_request_total(&self) -> Counter { | ||
self.rpc_request_total.clone() | ||
} | ||
|
||
pub fn set_rpc_request_duration_seconds( | ||
&self, | ||
method: &str, | ||
client_version: &str, | ||
duration: f64, | ||
) { | ||
let key = Key::from_parts( | ||
"eigen_rpc_request_duration_seconds", | ||
vec![ | ||
Label::new("method", method.to_string()), | ||
Label::new("client_version", client_version.to_string()), | ||
], | ||
); | ||
|
||
metrics::histogram!(key.to_string(), duration); | ||
} | ||
|
||
pub fn set_rpc_request_total( | ||
&self, | ||
method: &str, | ||
client_version: &str, | ||
rpc_request_total: u64, | ||
) { | ||
let key = Key::from_parts( | ||
"eigen_rpc_request_total", | ||
vec![ | ||
Label::new("method", method.to_string()), | ||
Label::new("client_version", client_version.to_string()), | ||
], | ||
); | ||
|
||
metrics::counter!(key.to_string(), rpc_request_total); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[package] | ||
name = "eigen-metrics-derive" | ||
version.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
repository.workspace = true | ||
|
||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
|
||
#prometheus | ||
prometheus = "0.13.4" | ||
|
||
proc-macro2 = "1.0" | ||
|
||
syn = { workspace = true, features = ["extra-traits"] } | ||
quote.workspace = true | ||
regex = "1.6.0" | ||
once_cell.workspace = true | ||
|
||
[dev-dependencies] | ||
metrics.workspace = true | ||
trybuild = "1.0" |
Oops, something went wrong.