Adding metric support

This commit is contained in:
jude
2023-10-21 21:33:50 +01:00
parent 6cfdc10a6a
commit 6615e05196
6 changed files with 40 additions and 4 deletions

View File

@@ -5,6 +5,8 @@ use poise::serenity_prelude::{
ReactionType,
};
#[cfg(feature = "prometheus")]
use crate::metrics::PLAY_COUNTER;
use crate::{
cmds::autocomplete_sound,
models::{guild_data::CtxGuildData, sound::SoundCtx},
@@ -27,6 +29,9 @@ pub async fn play(
let guild = ctx.guild().unwrap();
#[cfg(feature = "prometheus")]
PLAY_COUNTER.inc();
ctx.say(
play_from_query(
&ctx.serenity_context(),

View File

@@ -105,10 +105,9 @@ pub async fn listener(ctx: &Context, event: &poise::Event<'_>, data: &Data) -> R
let mut sound = sqlx::query_as_unchecked!(
Sound,
"
SELECT name, id, public, server_id, uploader_id
FROM sounds
WHERE id = ?
",
SELECT name, id, public, server_id, uploader_id
FROM sounds
WHERE id = ?",
join_id
)
.fetch_one(&data.database)

View File

@@ -5,6 +5,8 @@ mod cmds;
mod consts;
mod error;
mod event_handlers;
#[cfg(feature = "prometheus")]
mod metrics;
mod models;
mod utils;

7
src/metrics.rs Normal file
View File

@@ -0,0 +1,7 @@
use lazy_static;
use prometheus::{register_int_counter, IntCounter};
lazy_static! {
pub static ref PLAY_COUNTER: IntCounter =
register_int_counter!("play", "Number of calls to /play").unwrap();
}