mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
feat: add metric for remaining gateway sessions
This commit is contained in:
parent
c58eb274df
commit
b77390c0cd
4 changed files with 34 additions and 1 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -2929,6 +2929,7 @@ dependencies = [
|
||||||
"sqlx",
|
"sqlx",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
"twilight-http",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ serde_json = { workspace = true }
|
||||||
sqlx = { workspace = true }
|
sqlx = { workspace = true }
|
||||||
tokio = { workspace = true }
|
tokio = { workspace = true }
|
||||||
tracing = { workspace = true }
|
tracing = { workspace = true }
|
||||||
|
twilight-http = { workspace = true }
|
||||||
|
|
||||||
croner = "2.1.0"
|
croner = "2.1.0"
|
||||||
num-format = "0.4.4"
|
num-format = "0.4.4"
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use croner::Cron;
|
use croner::Cron;
|
||||||
use fred::prelude::RedisPool;
|
use fred::prelude::RedisPool;
|
||||||
|
|
@ -14,15 +16,38 @@ pub struct AppCtx {
|
||||||
pub messages: PgPool,
|
pub messages: PgPool,
|
||||||
pub stats: PgPool,
|
pub stats: PgPool,
|
||||||
pub redis: RedisPool,
|
pub redis: RedisPool,
|
||||||
|
|
||||||
|
pub discord: Arc<twilight_http::Client>,
|
||||||
}
|
}
|
||||||
|
|
||||||
libpk::main!("scheduled_tasks");
|
libpk::main!("scheduled_tasks");
|
||||||
async fn real_main() -> anyhow::Result<()> {
|
async fn real_main() -> anyhow::Result<()> {
|
||||||
|
let mut client_builder = twilight_http::Client::builder().token(
|
||||||
|
libpk::config
|
||||||
|
.discord
|
||||||
|
.as_ref()
|
||||||
|
.expect("missing discord config")
|
||||||
|
.bot_token
|
||||||
|
.clone(),
|
||||||
|
);
|
||||||
|
|
||||||
|
if let Some(base_url) = libpk::config
|
||||||
|
.discord
|
||||||
|
.as_ref()
|
||||||
|
.expect("missing discord config")
|
||||||
|
.api_base_url
|
||||||
|
.clone()
|
||||||
|
{
|
||||||
|
client_builder = client_builder.proxy(base_url, true);
|
||||||
|
}
|
||||||
|
|
||||||
let ctx = AppCtx {
|
let ctx = AppCtx {
|
||||||
data: libpk::db::init_data_db().await?,
|
data: libpk::db::init_data_db().await?,
|
||||||
messages: libpk::db::init_messages_db().await?,
|
messages: libpk::db::init_messages_db().await?,
|
||||||
stats: libpk::db::init_stats_db().await?,
|
stats: libpk::db::init_stats_db().await?,
|
||||||
redis: libpk::db::init_redis().await?,
|
redis: libpk::db::init_redis().await?,
|
||||||
|
|
||||||
|
discord: Arc::new(client_builder.build()),
|
||||||
};
|
};
|
||||||
|
|
||||||
info!("starting scheduled tasks runner");
|
info!("starting scheduled tasks runner");
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,13 @@ pub async fn update_prometheus(ctx: AppCtx) -> anyhow::Result<()> {
|
||||||
|
|
||||||
gauge!("pluralkit_image_cleanup_queue_length").set(count.count as f64);
|
gauge!("pluralkit_image_cleanup_queue_length").set(count.count as f64);
|
||||||
|
|
||||||
// todo: remaining shard session_start_limit
|
let gateway = ctx.discord.gateway().authed().await?.model().await?;
|
||||||
|
|
||||||
|
gauge!("pluralkit_gateway_sessions_remaining")
|
||||||
|
.set(gateway.session_start_limit.remaining as f64);
|
||||||
|
gauge!("pluralkit_gateway_sessions_reset_after")
|
||||||
|
.set(gateway.session_start_limit.reset_after as f64);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue