Add metrics
Change dashboards to load an index.html file compiled otherwise
This commit is contained in:
@ -1 +0,0 @@
|
||||
|
@ -1,9 +1,13 @@
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
|
||||
use chrono::{naive::NaiveDateTime, Utc};
|
||||
use rand::{rngs::OsRng, seq::IteratorRandom};
|
||||
use rocket::{http::CookieJar, response::Redirect, serde::json::json};
|
||||
use rocket_dyn_templates::Template;
|
||||
use rocket::{
|
||||
fs::{relative, NamedFile},
|
||||
http::CookieJar,
|
||||
response::Redirect,
|
||||
serde::json::json,
|
||||
};
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
use serenity::{
|
||||
client::Context,
|
||||
@ -27,7 +31,6 @@ use crate::{
|
||||
|
||||
pub mod api;
|
||||
pub mod export;
|
||||
pub mod guild;
|
||||
|
||||
type Unset<T> = Option<T>;
|
||||
|
||||
@ -657,22 +660,26 @@ async fn create_database_channel(
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
pub async fn dashboard_home(cookies: &CookieJar<'_>) -> Result<Template, Redirect> {
|
||||
pub async fn dashboard_home(cookies: &CookieJar<'_>) -> Result<NamedFile, Redirect> {
|
||||
if cookies.get_private("userid").is_some() {
|
||||
let mut map = HashMap::new();
|
||||
map.insert("version", env!("CARGO_PKG_VERSION"));
|
||||
Ok(Template::render("dashboard", &map))
|
||||
NamedFile::open(Path::new(relative!("static/index.html"))).await.map_err(|e| {
|
||||
warn!("Couldn't render dashboard: {:?}", e);
|
||||
|
||||
Redirect::to("/login/discord")
|
||||
})
|
||||
} else {
|
||||
Err(Redirect::to("/login/discord"))
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/<_..>")]
|
||||
pub async fn dashboard(cookies: &CookieJar<'_>) -> Result<Template, Redirect> {
|
||||
pub async fn dashboard(cookies: &CookieJar<'_>) -> Result<NamedFile, Redirect> {
|
||||
if cookies.get_private("userid").is_some() {
|
||||
let mut map = HashMap::new();
|
||||
map.insert("version", env!("CARGO_PKG_VERSION"));
|
||||
Ok(Template::render("dashboard", &map))
|
||||
NamedFile::open(Path::new(relative!("static/index.html"))).await.map_err(|e| {
|
||||
warn!("Couldn't render dashboard: {:?}", e);
|
||||
|
||||
Redirect::to("/login/discord")
|
||||
})
|
||||
} else {
|
||||
Err(Redirect::to("/login/discord"))
|
||||
}
|
||||
|
18
web/src/routes/metrics.rs
Normal file
18
web/src/routes/metrics.rs
Normal file
@ -0,0 +1,18 @@
|
||||
use prometheus;
|
||||
|
||||
use crate::metrics::REGISTRY;
|
||||
|
||||
#[get("/metrics")]
|
||||
pub async fn metrics() -> String {
|
||||
let encoder = prometheus::TextEncoder::new();
|
||||
let res_custom = encoder.encode_to_string(®ISTRY.gather());
|
||||
|
||||
match res_custom {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
warn!("Error encoding metrics: {:?}", e);
|
||||
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
pub mod admin;
|
||||
pub mod dashboard;
|
||||
pub mod login;
|
||||
pub mod metrics;
|
||||
pub mod report;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
Reference in New Issue
Block a user