mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 14:31:02 +00:00
Expose relay version metric (#1750)
* expose relay version metric * spelling * and clippy * clippy * typo * use version directly and determine git commit * typos and leftovers
This commit is contained in:
committed by
Bastian Köcher
parent
444dbe7173
commit
70eb076ab2
@@ -99,6 +99,39 @@ impl Default for MetricsAddress {
|
||||
}
|
||||
|
||||
impl MetricsParams {
|
||||
/// Creates metrics params from metrics address.
|
||||
pub fn new(
|
||||
address: Option<MetricsAddress>,
|
||||
relay_version: String,
|
||||
relay_commit: String,
|
||||
) -> Result<Self, PrometheusError> {
|
||||
const BUILD_INFO_METRIC: &str = "substrate_relay_build_info";
|
||||
|
||||
let registry = Registry::new();
|
||||
register(
|
||||
Gauge::<U64>::with_opts(
|
||||
Opts::new(
|
||||
BUILD_INFO_METRIC,
|
||||
"A metric with a constant '1' value labeled by version",
|
||||
)
|
||||
.const_label("version", &relay_version)
|
||||
.const_label("commit", &relay_commit),
|
||||
)?,
|
||||
®istry,
|
||||
)?
|
||||
.set(1);
|
||||
|
||||
log::info!(
|
||||
target: "bridge",
|
||||
"Exposed {} metric: version={} commit={}",
|
||||
BUILD_INFO_METRIC,
|
||||
relay_version,
|
||||
relay_commit,
|
||||
);
|
||||
|
||||
Ok(MetricsParams { address, registry })
|
||||
}
|
||||
|
||||
/// Creates metrics params so that metrics are not exposed.
|
||||
pub fn disabled() -> Self {
|
||||
MetricsParams { address: None, registry: Registry::new() }
|
||||
@@ -112,12 +145,6 @@ impl MetricsParams {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Option<MetricsAddress>> for MetricsParams {
|
||||
fn from(address: Option<MetricsAddress>) -> Self {
|
||||
MetricsParams { address, registry: Registry::new() }
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns metric name optionally prefixed with given prefix.
|
||||
pub fn metric_name(prefix: Option<&str>, name: &str) -> String {
|
||||
if let Some(prefix) = prefix {
|
||||
|
||||
Reference in New Issue
Block a user