Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions anchor/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ logging = { workspace = true }
message_receiver = { workspace = true }
message_sender = { workspace = true }
message_validator = { workspace = true }
metrics = { workspace = true }
multiaddr = { workspace = true }
network = { workspace = true }
network_utils = { workspace = true }
Expand Down
5 changes: 5 additions & 0 deletions anchor/client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod cli;
pub mod config;
mod key;
mod metrics;
mod notifier;

use std::{
Expand Down Expand Up @@ -156,6 +157,10 @@ impl Client {
let metrics_future = http_metrics::serve(listener, shared_state.clone(), exit);

executor.spawn_without_exit(metrics_future, "metrics-http");

metrics::expose_anchor_version();
metrics::expose_process_start_time();

Some(shared_state)
} else {
info!("HTTP metrics server is disabled");
Expand Down
37 changes: 37 additions & 0 deletions anchor/client/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use std::{
sync::LazyLock,
time::{SystemTime, UNIX_EPOCH},
};

use metrics::*;
use tracing::error;
use version::VERSION;

pub static PROCESS_START_TIME_SECONDS: LazyLock<Result<IntGauge>> = LazyLock::new(|| {
try_create_int_gauge(
"process_start_time_seconds",
"The unix timestamp at which the process was started",
)
});

pub static ANCHOR_VERSION: LazyLock<Result<IntGaugeVec>> = LazyLock::new(|| {
try_create_int_gauge_vec(
"anchor_info",
"The build of Anchor running on the server",
&["version"],
)
});

pub fn expose_process_start_time() {
match SystemTime::now().duration_since(UNIX_EPOCH) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we just expose the process start time (Unix timestamp) and then Prometheus / Grafana calculates the actual uptime / other metrics?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume grafana has some way to integrate current time into queries, so yeah!

As mentioned, this is how LH does it, so I assume it is possible to do something useful with this :D

Ok(duration) => set_gauge(&PROCESS_START_TIME_SECONDS, duration.as_secs() as i64),
Err(e) => error!(
error = %e,
"Failed to read system time"
),
}
}

pub fn expose_anchor_version() {
set_gauge_vec(&ANCHOR_VERSION, &[VERSION], 1);
}