mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2025-12-25 23:49:58 +00:00
chore: add heartbeat metrics (#5929)
This commit is contained in:
@@ -142,6 +142,43 @@ impl Stat {
|
||||
self.wcus = self.region_stats.iter().map(|s| s.wcus).sum();
|
||||
self.region_num = self.region_stats.len() as u64;
|
||||
}
|
||||
|
||||
pub fn memory_size(&self) -> usize {
|
||||
// timestamp_millis, rcus, wcus
|
||||
std::mem::size_of::<i64>() * 3 +
|
||||
// id, region_num, node_epoch
|
||||
std::mem::size_of::<u64>() * 3 +
|
||||
// addr
|
||||
std::mem::size_of::<String>() + self.addr.capacity() +
|
||||
// region_stats
|
||||
self.region_stats.iter().map(|s| s.memory_size()).sum::<usize>()
|
||||
}
|
||||
}
|
||||
|
||||
impl RegionStat {
|
||||
pub fn memory_size(&self) -> usize {
|
||||
// role
|
||||
std::mem::size_of::<RegionRole>() +
|
||||
// id
|
||||
std::mem::size_of::<RegionId>() +
|
||||
// rcus, wcus, approximate_bytes, num_rows
|
||||
std::mem::size_of::<i64>() * 4 +
|
||||
// memtable_size, manifest_size, sst_size, index_size
|
||||
std::mem::size_of::<u64>() * 4 +
|
||||
// engine
|
||||
std::mem::size_of::<String>() + self.engine.capacity() +
|
||||
// region_manifest
|
||||
self.region_manifest.memory_size()
|
||||
}
|
||||
}
|
||||
|
||||
impl RegionManifestInfo {
|
||||
pub fn memory_size(&self) -> usize {
|
||||
match self {
|
||||
RegionManifestInfo::Mito { .. } => std::mem::size_of::<u64>() * 2,
|
||||
RegionManifestInfo::Metric { .. } => std::mem::size_of::<u64>() * 4,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&HeartbeatRequest> for Stat {
|
||||
|
||||
@@ -19,6 +19,7 @@ use common_telemetry::{info, warn};
|
||||
use crate::error::Result;
|
||||
use crate::handler::{HandleControl, HeartbeatAccumulator, HeartbeatHandler};
|
||||
use crate::metasrv::Context;
|
||||
use crate::metrics::{METRIC_META_HEARTBEAT_RATE, METRIC_META_HEARTBEAT_STAT_MEMORY_SIZE};
|
||||
|
||||
pub struct ExtractStatHandler;
|
||||
|
||||
@@ -42,6 +43,8 @@ impl HeartbeatHandler for ExtractStatHandler {
|
||||
|
||||
match Stat::try_from(req) {
|
||||
Ok(stat) => {
|
||||
METRIC_META_HEARTBEAT_RATE.inc();
|
||||
METRIC_META_HEARTBEAT_STAT_MEMORY_SIZE.observe(stat.memory_size() as f64);
|
||||
let _ = acc.stat.insert(stat);
|
||||
}
|
||||
Err(Some(header)) => {
|
||||
|
||||
@@ -60,10 +60,10 @@ lazy_static! {
|
||||
/// The migration fail counter.
|
||||
pub static ref METRIC_META_REGION_MIGRATION_FAIL: IntCounter =
|
||||
register_int_counter!("greptime_meta_region_migration_fail", "meta region migration fail").unwrap();
|
||||
/// The add region follower execute histogram.
|
||||
pub static ref METRIC_META_ADD_REGION_FOLLOWER_EXECUTE: HistogramVec =
|
||||
register_histogram_vec!("greptime_meta_add_region_follower_execute", "meta add region follower execute", &["state"]).unwrap();
|
||||
/// The remove region follower execute histogram.
|
||||
pub static ref METRIC_META_REMOVE_REGION_FOLLOWER_EXECUTE: HistogramVec =
|
||||
register_histogram_vec!("greptime_meta_remove_region_follower_execute", "meta remove region follower execute", &["state"]).unwrap();
|
||||
// The heartbeat stat memory size histogram.
|
||||
pub static ref METRIC_META_HEARTBEAT_STAT_MEMORY_SIZE: Histogram =
|
||||
register_histogram!("greptime_meta_heartbeat_stat_memory_size", "meta heartbeat stat memory size").unwrap();
|
||||
// The heartbeat rate counter.
|
||||
pub static ref METRIC_META_HEARTBEAT_RATE: IntCounter =
|
||||
register_int_counter!("greptime_meta_heartbeat_rate", "meta heartbeat arrival rate").unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user