From 43a2158c1cb216dfacb52175e1a4ebc5eedf5c79 Mon Sep 17 00:00:00 2001 From: Anna Date: Mon, 18 Jul 2022 12:51:17 -0400 Subject: [PATCH] feat: add more influxdb measurements --- server/src/influx.rs | 66 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/server/src/influx.rs b/server/src/influx.rs index 872491e..e71279c 100644 --- a/server/src/influx.rs +++ b/server/src/influx.rs @@ -41,9 +41,41 @@ pub fn spawn(config: &Config, state: Arc>) { let clients = state.read().await.clients.len(); + let num_users = sqlx::query!( + // language=sqlite + "select count(*) as count from users" + ) + .fetch_one(&state.read().await.db) + .await + .ok(); + + let in_one = sqlx::query!( + // language=sqlite + "select count(distinct lodestone_id) as count from user_channels" + ) + .fetch_one(&state.read().await.db) + .await + .ok(); + + let num_linkshells = sqlx::query!( + // language=sqlite + "select count(*) as count from channels" + ) + .fetch_one(&state.read().await.db) + .await + .ok(); + + let outstanding_invites = sqlx::query!( + // language=sqlite + "select count(*) as count from channel_invites" + ) + .fetch_one(&state.read().await.db) + .await + .ok(); + let timestamp = Utc::now().timestamp_nanos(); - let line_format = format!( + let mut line_format = format!( "logged_in value={logged_in}u {timestamp}\nmessages_this_instance value={messages_this_instance}u {timestamp}\nmessages_new value={messages_new}u {timestamp}\n", logged_in = clients, messages_this_instance = messages, @@ -51,6 +83,38 @@ pub fn spawn(config: &Config, state: Arc>) { timestamp = timestamp, ); + if let Some(num_users) = num_users { + line_format.push_str(&format!( + "users value={users}u {timestamp}\n", + users = num_users.count, + timestamp = timestamp, + )); + } + + if let Some(in_one) = in_one { + line_format.push_str(&format!( + "users_in_at_least_one_linkshell value={in_one}u {timestamp}\n", + in_one = in_one.count, + timestamp = timestamp, + )); + } + + if let Some(num_linkshells) = num_linkshells { + line_format.push_str(&format!( + "linkshells value={linkshells}u {timestamp}\n", + linkshells = num_linkshells.count, + timestamp = timestamp, + )); + } + + if let Some(outstanding_invites) = outstanding_invites { + line_format.push_str(&format!( + "outstanding_invites value={outstanding_invites}u {timestamp}\n", + outstanding_invites = outstanding_invites.count, + timestamp = timestamp, + )); + } + debug!("line_format: {}", line_format); let res = client.post(url.clone())