add: server stats page
This commit is contained in:
parent
98d6f21e6e
commit
07f5ebf8e7
8 changed files with 97 additions and 1 deletions
|
@ -90,6 +90,7 @@ pub const MOD_FILE_REPORT: &str = include_str!("./public/html/mod/file_report.ht
|
||||||
pub const MOD_IP_BANS: &str = include_str!("./public/html/mod/ip_bans.html");
|
pub const MOD_IP_BANS: &str = include_str!("./public/html/mod/ip_bans.html");
|
||||||
pub const MOD_PROFILE: &str = include_str!("./public/html/mod/profile.html");
|
pub const MOD_PROFILE: &str = include_str!("./public/html/mod/profile.html");
|
||||||
pub const MOD_WARNINGS: &str = include_str!("./public/html/mod/warnings.html");
|
pub const MOD_WARNINGS: &str = include_str!("./public/html/mod/warnings.html");
|
||||||
|
pub const MOD_STATS: &str = include_str!("./public/html/mod/stats.html");
|
||||||
|
|
||||||
pub const CHATS_APP: &str = include_str!("./public/html/chats/app.html");
|
pub const CHATS_APP: &str = include_str!("./public/html/chats/app.html");
|
||||||
pub const CHATS_STREAM: &str = include_str!("./public/html/chats/stream.html");
|
pub const CHATS_STREAM: &str = include_str!("./public/html/chats/stream.html");
|
||||||
|
@ -258,6 +259,7 @@ pub(crate) async fn write_assets(config: &Config) -> PathBufD {
|
||||||
write_template!(html_path->"mod/ip_bans.html"(crate::assets::MOD_IP_BANS) --config=config);
|
write_template!(html_path->"mod/ip_bans.html"(crate::assets::MOD_IP_BANS) --config=config);
|
||||||
write_template!(html_path->"mod/profile.html"(crate::assets::MOD_PROFILE) --config=config);
|
write_template!(html_path->"mod/profile.html"(crate::assets::MOD_PROFILE) --config=config);
|
||||||
write_template!(html_path->"mod/warnings.html"(crate::assets::MOD_WARNINGS) --config=config);
|
write_template!(html_path->"mod/warnings.html"(crate::assets::MOD_WARNINGS) --config=config);
|
||||||
|
write_template!(html_path->"mod/stats.html"(crate::assets::MOD_STATS) --config=config);
|
||||||
|
|
||||||
write_template!(html_path->"chats/app.html"(crate::assets::CHATS_APP) -d "chats" --config=config);
|
write_template!(html_path->"chats/app.html"(crate::assets::CHATS_APP) -d "chats" --config=config);
|
||||||
write_template!(html_path->"chats/stream.html"(crate::assets::CHATS_STREAM) --config=config);
|
write_template!(html_path->"chats/stream.html"(crate::assets::CHATS_STREAM) --config=config);
|
||||||
|
|
|
@ -14,6 +14,7 @@ version = "1.0.0"
|
||||||
"general:link.audit_log" = "Audit log"
|
"general:link.audit_log" = "Audit log"
|
||||||
"general:link.reports" = "Reports"
|
"general:link.reports" = "Reports"
|
||||||
"general:link.ip_bans" = "IP bans"
|
"general:link.ip_bans" = "IP bans"
|
||||||
|
"general:link.stats" = "Stats"
|
||||||
"general:action.save" = "Save"
|
"general:action.save" = "Save"
|
||||||
"general:action.delete" = "Delete"
|
"general:action.delete" = "Delete"
|
||||||
"general:action.accept" = "Accept"
|
"general:action.accept" = "Accept"
|
||||||
|
|
|
@ -113,6 +113,11 @@
|
||||||
{{ icon "ban" }}
|
{{ icon "ban" }}
|
||||||
<span>{{ text "general:link.ip_bans" }}</span>
|
<span>{{ text "general:link.ip_bans" }}</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
<a href="/mod_panel/stats">
|
||||||
|
{{ icon "chart-line" }}
|
||||||
|
<span>{{ text "general:link.stats" }}</span>
|
||||||
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<b class="title">{{ config.name }}</b>
|
<b class="title">{{ config.name }}</b>
|
||||||
|
|
31
crates/app/src/public/html/mod/stats.html
Normal file
31
crates/app/src/public/html/mod/stats.html
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
{% extends "root.html" %} {% block head %}
|
||||||
|
<title>Audit log - {{ config.name }}</title>
|
||||||
|
{% endblock %} {% block body %} {{ macros::nav() }}
|
||||||
|
<main class="flex flex-col gap-2">
|
||||||
|
<div class="card-nest w-full">
|
||||||
|
<div class="card small flex items-center gap-2">
|
||||||
|
{{ icon "chart-line" }}
|
||||||
|
<span>{{ text "general:link.stats" }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card flex flex-col gap-2">
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<b>Active user streams:</b>
|
||||||
|
<span>{{ active_users }}</span>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
<b>Active chat subscriptions:</b>
|
||||||
|
<span>{{ active_users_chats }}</span>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
<b>Socket threads:</b>
|
||||||
|
<span>{{ (active_users_chats + active_users) * 3 }}</span>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
{% endblock %}
|
|
@ -524,12 +524,14 @@ pub async fn handle_socket(socket: WebSocket, db: DataManager, user_id: String,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
db.2.incr("atto.active_connections:user".to_string()).await;
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = (&mut recv_task) => redis_task.abort(),
|
_ = (&mut recv_task) => redis_task.abort(),
|
||||||
_ = (&mut redis_task) => recv_task.abort()
|
_ = (&mut redis_task) => recv_task.abort()
|
||||||
}
|
}
|
||||||
|
|
||||||
heartbeat_task.abort(); // kill
|
heartbeat_task.abort(); // kill
|
||||||
|
db.2.decr("atto.active_connections:user".to_string()).await;
|
||||||
tracing::info!("socket terminate");
|
tracing::info!("socket terminate");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -258,12 +258,15 @@ pub async fn handle_socket(socket: WebSocket, db: DataManager, community_id: Str
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
db.2.incr("atto.active_connections:chats".to_string()).await;
|
||||||
|
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = (&mut recv_task) => redis_task.abort(),
|
_ = (&mut recv_task) => redis_task.abort(),
|
||||||
_ = (&mut redis_task) => recv_task.abort()
|
_ = (&mut redis_task) => recv_task.abort()
|
||||||
}
|
}
|
||||||
|
|
||||||
heartbeat_task.abort(); // kill
|
heartbeat_task.abort(); // kill
|
||||||
|
db.2.decr("atto.active_connections:chats".to_string()).await;
|
||||||
tracing::info!("socket terminate");
|
tracing::info!("socket terminate");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,7 @@ pub fn routes() -> Router {
|
||||||
"/mod_panel/profile/{id}/warnings",
|
"/mod_panel/profile/{id}/warnings",
|
||||||
get(mod_panel::manage_profile_warnings_request),
|
get(mod_panel::manage_profile_warnings_request),
|
||||||
)
|
)
|
||||||
|
.route("/mod_panel/stats", get(mod_panel::stats_request))
|
||||||
// auth
|
// auth
|
||||||
.route("/auth/register", get(auth::register_request))
|
.route("/auth/register", get(auth::register_request))
|
||||||
.route("/auth/login", get(auth::login_request))
|
.route("/auth/login", get(auth::login_request))
|
||||||
|
|
|
@ -7,7 +7,10 @@ use axum::{
|
||||||
};
|
};
|
||||||
use axum_extra::extract::CookieJar;
|
use axum_extra::extract::CookieJar;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use tetratto_core::model::{Error, permissions::FinePermission, reactions::AssetType};
|
use tetratto_core::{
|
||||||
|
cache::Cache,
|
||||||
|
model::{permissions::FinePermission, reactions::AssetType, Error},
|
||||||
|
};
|
||||||
|
|
||||||
/// `/mod_panel/audit_log`
|
/// `/mod_panel/audit_log`
|
||||||
pub async fn audit_log_request(
|
pub async fn audit_log_request(
|
||||||
|
@ -232,3 +235,51 @@ pub async fn manage_profile_warnings_request(
|
||||||
// return
|
// return
|
||||||
Ok(Html(data.1.render("mod/warnings.html", &context).unwrap()))
|
Ok(Html(data.1.render("mod/warnings.html", &context).unwrap()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// `/mod_panel/stats`
|
||||||
|
pub async fn stats_request(jar: CookieJar, Extension(data): Extension<State>) -> impl IntoResponse {
|
||||||
|
let data = data.read().await;
|
||||||
|
let user = match get_user_from_token!(jar, data.0) {
|
||||||
|
Some(ua) => ua,
|
||||||
|
None => {
|
||||||
|
return Err(Html(
|
||||||
|
render_error(Error::NotAllowed, &jar, &data, &None).await,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if !user.permissions.check(FinePermission::VIEW_AUDIT_LOG) {
|
||||||
|
return Err(Html(
|
||||||
|
render_error(Error::NotAllowed, &jar, &data, &None).await,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
let lang = get_lang!(jar, data.0);
|
||||||
|
let mut context = initial_context(&data.0.0, lang, &Some(user)).await;
|
||||||
|
|
||||||
|
context.insert(
|
||||||
|
"active_users_chats",
|
||||||
|
&data
|
||||||
|
.0
|
||||||
|
.2
|
||||||
|
.get("atto.active_connections:chats".to_string())
|
||||||
|
.await
|
||||||
|
.unwrap_or("0".to_string())
|
||||||
|
.parse::<i64>()
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
context.insert(
|
||||||
|
"active_users",
|
||||||
|
&data
|
||||||
|
.0
|
||||||
|
.2
|
||||||
|
.get("atto.active_connections:users".to_string())
|
||||||
|
.await
|
||||||
|
.unwrap_or("0".to_string())
|
||||||
|
.parse::<i64>()
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// return
|
||||||
|
Ok(Html(data.1.render("mod/stats.html", &context).unwrap()))
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue