-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
155 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use once_cell::sync::Lazy; | ||
pub use prometheus::{ | ||
self, core::MetricVec, core::MetricVecBuilder, exponential_buckets, linear_buckets, Counter, | ||
Encoder, Gauge, GaugeVec, Histogram, HistogramOpts, HistogramVec, IntCounter, IntCounterVec, | ||
IntGauge, IntGaugeVec, Opts, Result, TextEncoder, | ||
}; | ||
|
||
pub(crate) static NODE_RUNNING: Lazy<IntGaugeVec> = Lazy::new(|| { | ||
try_create_int_gauge_vec( | ||
"multichain_node_is_up", | ||
"whether the multichain signer node is up and running", | ||
&["node_account_id"], | ||
) | ||
.unwrap() | ||
}); | ||
|
||
pub(crate) static NUM_SIGN_REQUESTS: Lazy<IntGaugeVec> = Lazy::new(|| { | ||
try_create_int_gauge_vec( | ||
"multichain_sign_requests_count", | ||
"number of multichain sign requests, marked by sign requests indexed", | ||
&["node_account_id"], | ||
) | ||
.unwrap() | ||
}); | ||
|
||
pub(crate) static NUM_SIGN_SUCCESS: Lazy<IntGaugeVec> = Lazy::new(|| { | ||
try_create_int_gauge_vec( | ||
"multichain_sign_requests_success", | ||
"number of successful multichain sign requests, marked by publish()", | ||
&["node_account_id"], | ||
) | ||
.unwrap() | ||
}); | ||
|
||
pub(crate) static SIGN_LATENCY: Lazy<HistogramVec> = Lazy::new(|| { | ||
try_create_histogram_vec( | ||
"multichain_sign_latency_sec", | ||
"Latency of multichain signing, start from indexing sign request, end when publish() called.", | ||
&["node_account_id"], | ||
Some(exponential_buckets(0.001, 2.0, 20).unwrap()), | ||
) | ||
.unwrap() | ||
}); | ||
|
||
pub fn try_create_int_gauge_vec(name: &str, help: &str, labels: &[&str]) -> Result<IntGaugeVec> { | ||
check_metric_multichain_prefix(name)?; | ||
let opts = Opts::new(name, help); | ||
let gauge = IntGaugeVec::new(opts, labels)?; | ||
prometheus::register(Box::new(gauge.clone()))?; | ||
Ok(gauge) | ||
} | ||
|
||
/// Attempts to create a `HistogramVector`, returning `Err` if the registry does not accept the counter | ||
/// (potentially due to naming conflict). | ||
pub fn try_create_histogram_vec( | ||
name: &str, | ||
help: &str, | ||
labels: &[&str], | ||
buckets: Option<Vec<f64>>, | ||
) -> Result<HistogramVec> { | ||
check_metric_multichain_prefix(name)?; | ||
let mut opts = HistogramOpts::new(name, help); | ||
if let Some(buckets) = buckets { | ||
opts = opts.buckets(buckets); | ||
} | ||
let histogram = HistogramVec::new(opts, labels)?; | ||
prometheus::register(Box::new(histogram.clone()))?; | ||
Ok(histogram) | ||
} | ||
|
||
fn check_metric_multichain_prefix(name: &str) -> Result<()> { | ||
if name.starts_with("multichain_") { | ||
Ok(()) | ||
} else { | ||
Err(prometheus::Error::Msg(format!( | ||
"Metrics are expected to start with 'multichain_', got {}", | ||
name | ||
))) | ||
} | ||
} |
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