From 48b50f783d0847732cd62565a7471b11a76b85a7 Mon Sep 17 00:00:00 2001 From: jude Date: Sun, 22 Oct 2023 09:55:36 +0100 Subject: [PATCH] Add more counters --- src/cmds/manage.rs | 8 ++++++++ src/cmds/play.rs | 6 +++--- src/metrics.rs | 6 +++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/cmds/manage.rs b/src/cmds/manage.rs index 23485e4..3d459b6 100644 --- a/src/cmds/manage.rs +++ b/src/cmds/manage.rs @@ -1,6 +1,8 @@ use poise::serenity_prelude::{Attachment, GuildId, RoleId}; use tokio::fs::File; +#[cfg(feature = "metrics")] +use crate::metrics::{DELETE_COUNTER, UPLOAD_COUNTER}; use crate::{ cmds::autocomplete_sound, consts::{MAX_SOUNDS, PATREON_GUILD, PATREON_ROLE}, @@ -21,6 +23,9 @@ pub async fn upload_new_sound( #[description = "Name to upload sound to"] name: String, #[description = "Sound file (max. 2MB)"] file: Attachment, ) -> Result<(), Error> { + #[cfg(feature = "metrics")] + UPLOAD_COUNTER.inc(); + ctx.defer().await?; fn is_numeric(s: &String) -> bool { @@ -110,6 +115,9 @@ pub async fn delete_sound( #[autocomplete = "autocomplete_sound"] name: String, ) -> Result<(), Error> { + #[cfg(feature = "metrics")] + DELETE_COUNTER.inc(); + let pool = ctx.data().database.clone(); let uid = ctx.author().id.0; diff --git a/src/cmds/play.rs b/src/cmds/play.rs index 0555917..72bc4bc 100644 --- a/src/cmds/play.rs +++ b/src/cmds/play.rs @@ -25,13 +25,13 @@ pub async fn play( #[channel_types("Voice")] channel: Option, ) -> Result<(), Error> { + #[cfg(feature = "metrics")] + PLAY_COUNTER.inc(); + ctx.defer().await?; let guild = ctx.guild().unwrap(); - #[cfg(feature = "metrics")] - PLAY_COUNTER.inc(); - ctx.say( play_from_query( &ctx.serenity_context(), diff --git a/src/metrics.rs b/src/metrics.rs index e85a774..dc83f5b 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -8,7 +8,11 @@ use prometheus::{register_int_counter, IntCounter, Registry}; lazy_static! { static ref REGISTRY: Registry = Registry::new(); pub static ref PLAY_COUNTER: IntCounter = - register_int_counter!("play", "Number of calls to /play").unwrap(); + register_int_counter!("play_cmd", "Number of calls to /play").unwrap(); + pub static ref UPLOAD_COUNTER: IntCounter = + register_int_counter!("upload_cmd", "Number of calls to /upload").unwrap(); + pub static ref DELETE_COUNTER: IntCounter = + register_int_counter!("delete_cmd", "Number of calls to /delete").unwrap(); } pub fn init_metrics() {