mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-12 16:50:10 +00:00
feat(scheduled_tasks): update for k8s (#734)
This commit is contained in:
parent
94a3276979
commit
7cff9abee3
2 changed files with 14 additions and 8 deletions
|
|
@ -88,6 +88,7 @@ pub struct ScheduledTasksConfig {
|
||||||
pub set_guild_count: bool,
|
pub set_guild_count: bool,
|
||||||
pub expected_gateway_count: usize,
|
pub expected_gateway_count: usize,
|
||||||
pub gateway_url: String,
|
pub gateway_url: String,
|
||||||
|
pub prometheus_url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _metrics_default() -> bool {
|
fn _metrics_default() -> bool {
|
||||||
|
|
|
||||||
|
|
@ -92,12 +92,14 @@ pub async fn update_discord_stats(ctx: AppCtx) -> anyhow::Result<()> {
|
||||||
|
|
||||||
let mut guild_count = 0;
|
let mut guild_count = 0;
|
||||||
let mut channel_count = 0;
|
let mut channel_count = 0;
|
||||||
|
let mut url = cfg.gateway_url.clone();
|
||||||
|
|
||||||
for idx in 0..cfg.expected_gateway_count {
|
for idx in 0..cfg.expected_gateway_count {
|
||||||
let res = client
|
if url.contains("{clusterid}") {
|
||||||
.get(format!("http://cluster{idx}.{}/stats", cfg.gateway_url))
|
url = url.replace("{clusterid}", &idx.to_string());
|
||||||
.send()
|
}
|
||||||
.await?;
|
|
||||||
|
let res = client.get(&url).send().await?;
|
||||||
|
|
||||||
let stat: GatewayStatus = res.json().await?;
|
let stat: GatewayStatus = res.json().await?;
|
||||||
|
|
||||||
|
|
@ -163,6 +165,11 @@ pub async fn update_stats_api(ctx: AppCtx) -> anyhow::Result<()> {
|
||||||
.build()
|
.build()
|
||||||
.expect("error making client");
|
.expect("error making client");
|
||||||
|
|
||||||
|
let cfg = config
|
||||||
|
.scheduled_tasks
|
||||||
|
.as_ref()
|
||||||
|
.expect("missing scheduled_tasks config");
|
||||||
|
|
||||||
#[derive(serde::Deserialize, Debug)]
|
#[derive(serde::Deserialize, Debug)]
|
||||||
struct PrometheusResult {
|
struct PrometheusResult {
|
||||||
data: PrometheusResultData,
|
data: PrometheusResultData,
|
||||||
|
|
@ -178,11 +185,9 @@ pub async fn update_stats_api(ctx: AppCtx) -> anyhow::Result<()> {
|
||||||
|
|
||||||
macro_rules! prom_instant_query {
|
macro_rules! prom_instant_query {
|
||||||
($t:ty, $q:expr) => {{
|
($t:ty, $q:expr) => {{
|
||||||
|
tracing::info!("Query: {}", $q);
|
||||||
let resp = client
|
let resp = client
|
||||||
.get(format!(
|
.get(format!("{}/api/v1/query?query={}", cfg.prometheus_url, $q))
|
||||||
"http://vm.svc.pluralkit.net/select/0/prometheus/api/v1/query?query={}",
|
|
||||||
$q
|
|
||||||
))
|
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue