diff --git a/src/db/mod.rs b/src/db/mod.rs index f46e7a48..7eed3bd7 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -104,7 +104,7 @@ pub async fn init_config() { }), site: Set(crate::config::site::Config { title: String::from("CdsCTF"), - description: String::from("CdsCTF is a CTF platform."), + description: String::from("Reality is an illusion, the universe is a hologram."), color: String::from("#0C4497"), favicon: String::from(""), }), diff --git a/src/metric/mod.rs b/src/metric/mod.rs index 36b4e878..83abd526 100644 --- a/src/metric/mod.rs +++ b/src/metric/mod.rs @@ -25,7 +25,7 @@ pub static MEMORY_USAGE: Lazy = Lazy::new(|| { }); pub static MEMORY_USAGE_RATIO: Lazy = Lazy::new(|| { - let opts = Opts::new("memory_usage_bytes", "Memory usage in bytes") + let opts = Opts::new("memory_usage_ratio", "Memory usage ratio") .namespace(crate::env::get_env().metric.namespace.clone()); let gauge = Gauge::with_opts(opts).expect("metric can be created"); METRICS_REGISTRY.register(Box::new(gauge.clone())).unwrap(); diff --git a/src/model/challenge/mod.rs b/src/model/challenge/mod.rs index 5b255d86..33b49f27 100644 --- a/src/model/challenge/mod.rs +++ b/src/model/challenge/mod.rs @@ -35,9 +35,9 @@ pub struct Model { #[sea_orm(default_value = 1800)] pub duration: i64, pub ports: Vec, - #[sea_orm(column_type = "Json")] + #[sea_orm(column_type = "JsonBinary")] pub envs: Vec, - #[sea_orm(column_type = "Json")] + #[sea_orm(column_type = "JsonBinary")] pub flags: Vec, pub created_at: i64, pub updated_at: i64, diff --git a/src/model/pod/mod.rs b/src/model/pod/mod.rs index be0d49d8..6ae7facf 100644 --- a/src/model/pod/mod.rs +++ b/src/model/pod/mod.rs @@ -19,7 +19,7 @@ pub struct Model { pub team_id: Option, pub game_id: Option, pub challenge_id: i64, - #[sea_orm(column_type = "Json")] + #[sea_orm(column_type = "JsonBinary")] pub nats: Vec, pub removed_at: i64, pub created_at: i64, diff --git a/src/web/router/metric/worker.rs b/src/web/router/metric/worker.rs index 49d3a59e..19d50ce9 100644 --- a/src/web/router/metric/worker.rs +++ b/src/web/router/metric/worker.rs @@ -1,10 +1,10 @@ use std::time::Duration; -use sysinfo::System; +use sysinfo::{Pid, System}; use tokio::time::interval; use tracing::info; -use crate::metric::{CPU_USAGE, MEMORY_USAGE}; +use crate::metric::{CPU_USAGE, MEMORY_USAGE, MEMORY_USAGE_RATIO}; pub async fn init() { tokio::spawn(async { @@ -14,14 +14,19 @@ pub async fn init() { loop { sys.refresh_all(); - let total_memory = sys.total_memory(); - let used_memory = sys.used_memory(); - let memory_usage = (used_memory as f64 / total_memory as f64 * 100.0) as i64; + let pid = std::process::id(); + if let Some(process) = sys.process(Pid::from_u32(pid)) { + let used_memory = process.memory(); + MEMORY_USAGE.set(used_memory as i64); - MEMORY_USAGE.set(memory_usage); + let total_memory = sys.total_memory(); + let memory_usage = used_memory as f64 / total_memory as f64 * 100.0; - let cpu_usage = sys.global_cpu_usage() as i64; - CPU_USAGE.set(cpu_usage); + MEMORY_USAGE_RATIO.set(memory_usage); + + let cpu_usage = process.cpu_usage() as i64; + CPU_USAGE.set(cpu_usage); + } tokio::time::sleep(interval).await; }