feat: add metrics for number of editing users (#730)
This commit is contained in:
parent
15b2e81579
commit
045b6f09cb
|
|
@ -135,16 +135,29 @@ impl GroupManagementState {
|
|||
object_id: object_id.to_string(),
|
||||
};
|
||||
|
||||
self
|
||||
.editing_by_user
|
||||
.entry(user.clone())
|
||||
.or_default()
|
||||
.insert(editing);
|
||||
let entry = self.editing_by_user.entry(user.clone());
|
||||
match entry {
|
||||
dashmap::mapref::entry::Entry::Occupied(_) => {},
|
||||
dashmap::mapref::entry::Entry::Vacant(_) => {
|
||||
self
|
||||
.metrics_calculate
|
||||
.num_of_editing_users
|
||||
.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||
},
|
||||
}
|
||||
|
||||
entry.or_default().insert(editing);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn remove_user(&self, user: &RealtimeUser) {
|
||||
let entry = self.editing_by_user.remove(user);
|
||||
if entry.is_some() {
|
||||
self
|
||||
.metrics_calculate
|
||||
.num_of_editing_users
|
||||
.fetch_sub(1, std::sync::atomic::Ordering::Relaxed);
|
||||
}
|
||||
if let Some(editing_objects) = entry.map(|(_, e)| e) {
|
||||
for editing in editing_objects {
|
||||
match self.group_by_object_id.try_get(&editing.object_id) {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ pub struct CollabRealtimeMetrics {
|
|||
total_success_get_encode_collab_from_redis: Gauge,
|
||||
total_attempt_get_encode_collab_from_redis: Gauge,
|
||||
opening_collab_count: Gauge,
|
||||
num_of_editing_users: Gauge,
|
||||
/// The number of apply update
|
||||
apply_update_count: Gauge,
|
||||
/// The number of apply update failed
|
||||
|
|
@ -27,6 +28,7 @@ impl CollabRealtimeMetrics {
|
|||
total_success_get_encode_collab_from_redis: Gauge::default(),
|
||||
total_attempt_get_encode_collab_from_redis: Gauge::default(),
|
||||
opening_collab_count: Gauge::default(),
|
||||
num_of_editing_users: Gauge::default(),
|
||||
apply_update_count: Default::default(),
|
||||
apply_update_failed_count: Default::default(),
|
||||
acquire_collab_lock_count: Default::default(),
|
||||
|
|
@ -57,6 +59,11 @@ impl CollabRealtimeMetrics {
|
|||
"number of opening collabs",
|
||||
metrics.opening_collab_count.clone(),
|
||||
);
|
||||
realtime_registry.register(
|
||||
"editing_users_count",
|
||||
"number of editing users",
|
||||
metrics.num_of_editing_users.clone(),
|
||||
);
|
||||
realtime_registry.register(
|
||||
"apply_update_count",
|
||||
"number of apply update",
|
||||
|
|
@ -91,6 +98,7 @@ pub(crate) struct CollabMetricsCalculate {
|
|||
pub(crate) apply_update_count: Arc<AtomicI64>,
|
||||
pub(crate) apply_update_failed_count: Arc<AtomicI64>,
|
||||
pub(crate) num_of_active_collab: Arc<AtomicI64>,
|
||||
pub(crate) num_of_editing_users: Arc<AtomicI64>,
|
||||
}
|
||||
|
||||
pub(crate) fn spawn_metrics<S>(
|
||||
|
|
@ -115,6 +123,13 @@ pub(crate) fn spawn_metrics<S>(
|
|||
.load(std::sync::atomic::Ordering::Relaxed),
|
||||
);
|
||||
|
||||
// editing users
|
||||
metrics.num_of_editing_users.set(
|
||||
metrics_calculation
|
||||
.num_of_editing_users
|
||||
.load(std::sync::atomic::Ordering::Relaxed),
|
||||
);
|
||||
|
||||
// connect user
|
||||
metrics.connected_users.set(
|
||||
metrics_calculation
|
||||
|
|
|
|||
Loading…
Reference in New Issue