From cd5651c7f69f27a2ceddfa72a88be6a99a899aa3 Mon Sep 17 00:00:00 2001 From: jude Date: Sun, 22 Oct 2023 12:40:17 +0100 Subject: [PATCH] Add more counters --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/event_handlers.rs | 5 +++++ src/metrics.rs | 5 +++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b010402..65aa533 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2215,7 +2215,7 @@ dependencies = [ [[package]] name = "soundfx-rs" -version = "1.5.13" +version = "1.5.15" dependencies = [ "axum", "dashmap", diff --git a/Cargo.toml b/Cargo.toml index 403ee13..6369472 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "soundfx-rs" description = "Discord bot for custom sound effects and soundboards" license = "AGPL-3.0-only" -version = "1.5.14" +version = "1.5.15" authors = ["jellywx "] edition = "2018" diff --git a/src/event_handlers.rs b/src/event_handlers.rs index bf04d49..0048496 100644 --- a/src/event_handlers.rs +++ b/src/event_handlers.rs @@ -6,6 +6,8 @@ use poise::serenity_prelude::{ ActionRowComponent, Activity, Context, CreateActionRow, CreateComponents, }; +#[cfg(feature = "metrics")] +use crate::metrics::GREET_COUNTER; use crate::{ cmds::search::SoundPager, models::{ @@ -73,6 +75,9 @@ pub async fn listener(ctx: &Context, event: &poise::Event<'_>, data: &Data) -> R let (handler, _) = join_channel(&ctx, guild, user_channel).await; + #[cfg(feature = "metrics")] + GREET_COUNTER.inc(); + play_audio( &mut sound, volume, diff --git a/src/metrics.rs b/src/metrics.rs index cca8a06..ad4acee 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -13,10 +13,15 @@ lazy_static! { 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 static ref GREET_COUNTER: IntCounter = + register_int_counter!("greet_invoke", "Number of greet sounds played").unwrap(); } pub fn init_metrics() { REGISTRY.register(Box::new(PLAY_COUNTER.clone())).unwrap(); + REGISTRY.register(Box::new(UPLOAD_COUNTER.clone())).unwrap(); + REGISTRY.register(Box::new(DELETE_COUNTER.clone())).unwrap(); + REGISTRY.register(Box::new(GREET_COUNTER.clone())).unwrap(); } pub async fn serve() {