mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-27 10:59:53 +00:00
Start adding metrics to collab
server
This commit is contained in:
parent
b51a53addb
commit
6734793069
2 changed files with 44 additions and 1 deletions
|
@ -218,7 +218,7 @@ impl Server {
|
|||
let receipt = envelope.receipt();
|
||||
let handler = handler.clone();
|
||||
async move {
|
||||
let mut store = server.store.write().await;
|
||||
let mut store = server.state_mut().await;
|
||||
let response = (handler)(server.clone(), &mut *store, envelope);
|
||||
match response {
|
||||
Ok(response) => {
|
||||
|
@ -1094,6 +1094,15 @@ impl<'a> Drop for StoreWriteGuard<'a> {
|
|||
fn drop(&mut self) {
|
||||
#[cfg(test)]
|
||||
self.check_invariants();
|
||||
|
||||
let metrics = self.metrics();
|
||||
tracing::info!(
|
||||
connections = metrics.connections,
|
||||
registered_projects = metrics.registered_projects,
|
||||
shared_projects = metrics.shared_projects,
|
||||
collaborators_per_project = metrics.collaborators_per_project,
|
||||
"metrics"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,41 @@ pub struct LeftProject {
|
|||
pub authorized_user_ids: Vec<UserId>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct Metrics {
|
||||
pub connections: usize,
|
||||
pub registered_projects: usize,
|
||||
pub shared_projects: usize,
|
||||
pub collaborators_per_project: f32,
|
||||
}
|
||||
|
||||
impl Store {
|
||||
pub fn metrics(&self) -> Metrics {
|
||||
let connections = self.connections.len();
|
||||
let mut registered_projects = 0;
|
||||
let mut shared_projects = 0;
|
||||
let mut collaborators = 0;
|
||||
for project in self.projects.values() {
|
||||
registered_projects += 1;
|
||||
if let Some(share) = project.share.as_ref() {
|
||||
shared_projects += 1;
|
||||
collaborators += share.active_replica_ids.len();
|
||||
}
|
||||
}
|
||||
let collaborators_per_project = if shared_projects == 0 || collaborators == 0 {
|
||||
0.
|
||||
} else {
|
||||
collaborators as f32 / shared_projects as f32
|
||||
};
|
||||
|
||||
Metrics {
|
||||
connections,
|
||||
registered_projects,
|
||||
shared_projects,
|
||||
collaborators_per_project,
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(self))]
|
||||
pub fn add_connection(&mut self, connection_id: ConnectionId, user_id: UserId) {
|
||||
self.connections.insert(
|
||||
|
|
Loading…
Reference in a new issue