chore: add LAST_SENT_HEARTBEAT_ELAPSED metric (#4062)

This commit is contained in:
Weny Xu
2024-05-28 17:05:37 +09:00
committed by GitHub
parent 9dd6e033a7
commit d3860671a8
2 changed files with 11 additions and 0 deletions

View File

@@ -213,6 +213,7 @@ impl HeartbeatTask {
let epoch = self.region_alive_keeper.epoch();
self.region_alive_keeper.start(Some(event_receiver)).await?;
let mut last_sent = Instant::now();
common_runtime::spawn_bg(async move {
let sleep = tokio::time::sleep(Duration::from_millis(0));
@@ -271,6 +272,10 @@ impl HeartbeatTask {
}
};
if let Some(req) = req {
metrics::LAST_SENT_HEARTBEAT_ELAPSED
.set(last_sent.elapsed().as_millis() as i64);
// Resets the timer.
last_sent = Instant::now();
debug!("Sending heartbeat request: {:?}", req);
if let Err(e) = tx.send(req).await {
error!(e; "Failed to send heartbeat to metasrv");

View File

@@ -35,6 +35,12 @@ lazy_static! {
"last received heartbeat lease elapsed",
)
.unwrap();
/// The elapsed time since the last sent heartbeat.
pub static ref LAST_SENT_HEARTBEAT_ELAPSED: IntGauge = register_int_gauge!(
"greptime_last_sent_heartbeat_lease_elapsed",
"last sent heartbeat lease elapsed",
)
.unwrap();
pub static ref LEASE_EXPIRED_REGION: IntGaugeVec = register_int_gauge_vec!(
"greptime_lease_expired_region",
"lease expired region",