aboutsummaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-17 10:16:42 +0000
committerFuwn <[email protected]>2021-05-17 10:16:42 +0000
commit1b482ab22031ab9a895b2567ba10a2e553752303 (patch)
treedb4874c46b25655ba7c94b0ab435fdb0d681af55 /src/api
parentrefactor(global): whirl_config modulized (diff)
downloadwhirl-1b482ab22031ab9a895b2567ba10a2e553752303.tar.xz
whirl-1b482ab22031ab9a895b2567ba10a2e553752303.zip
refactor(global): even more modules becoming crates
I did multiple checks and **yes**, everything still works perfectly fine.
Diffstat (limited to 'src/api')
-rw-r--r--src/api/mod.rs31
-rw-r--r--src/api/routes/mod.rs4
-rw-r--r--src/api/routes/stats/mod.rs35
-rw-r--r--src/api/routes/stats/structures.rs21
4 files changed, 0 insertions, 91 deletions
diff --git a/src/api/mod.rs b/src/api/mod.rs
deleted file mode 100644
index c744f3d..0000000
--- a/src/api/mod.rs
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
-// SPDX-License-Identifier: GPL-3.0-only
-
-use actix_web::web::resource;
-
-mod routes;
-
-pub struct Api;
-impl Api {
- pub async fn listen(
- tx: std::sync::mpsc::Sender<actix_web::dev::Server>,
- address: &str,
- ) -> std::io::Result<()> {
- let mut sys = actix_web::rt::System::new("api");
-
- let server = actix_web::HttpServer::new(|| {
- actix_web::App::new()
- .wrap(actix_cors::Cors::default().allow_any_origin())
- .service(resource("/").to(|| async { "Whirlsplash" }))
- .service(resource("/api/v1/statistics").to(routes::stats::statistics))
- })
- .bind(address)?
- .run();
-
- info!("http api now listening at {}", address);
-
- let _ = tx.send(server.clone());
-
- sys.block_on(server)
- }
-}
diff --git a/src/api/routes/mod.rs b/src/api/routes/mod.rs
deleted file mode 100644
index f5a2ff4..0000000
--- a/src/api/routes/mod.rs
+++ /dev/null
@@ -1,4 +0,0 @@
-// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
-// SPDX-License-Identifier: GPL-3.0-only
-
-pub mod stats;
diff --git a/src/api/routes/stats/mod.rs b/src/api/routes/stats/mod.rs
deleted file mode 100644
index 04ce5e6..0000000
--- a/src/api/routes/stats/mod.rs
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
-// SPDX-License-Identifier: GPL-3.0-only
-
-pub mod structures;
-
-use actix_web::HttpResponse;
-use sysinfo::{get_current_pid, ProcessExt, System, SystemExt};
-
-use crate::{
- api::routes::stats::structures::{Statistics, StatisticsProcess, StatisticsSystem},
- utils::system::seconds_to_hrtime,
-};
-
-// This is mostly for developmental testing, it consumes more CPU than it's
-// worth.
-pub fn statistics() -> HttpResponse {
- let mut sys = System::new_all();
- sys.refresh_all();
-
- let process = sys.get_process(get_current_pid().unwrap()).unwrap();
-
- HttpResponse::Ok().json(Statistics {
- system: StatisticsSystem {
- os_type: sys.get_name().unwrap(),
- release: sys.get_kernel_version().unwrap(),
- uptime: seconds_to_hrtime(sysinfo::System::new().get_uptime() as usize),
- },
- process: StatisticsProcess {
- // (process.cpu_usage() * 100.0).round() / 100.0
- memory_usage: (process.memory() / 1000).to_string(),
- cpu_usage: (process.cpu_usage() / sys.get_processors().len() as f32).to_string(),
- // uptime: seconds_to_hrtime((sys.get_uptime() - process.start_time()) as usize),
- },
- })
-}
diff --git a/src/api/routes/stats/structures.rs b/src/api/routes/stats/structures.rs
deleted file mode 100644
index 88fc852..0000000
--- a/src/api/routes/stats/structures.rs
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
-// SPDX-License-Identifier: GPL-3.0-only
-
-#[derive(Serialize)]
-pub struct Statistics {
- pub system: StatisticsSystem,
- pub process: StatisticsProcess,
-}
-#[derive(Serialize)]
-pub struct StatisticsSystem {
- #[serde(rename = "type")]
- pub os_type: String,
- pub release: String,
- pub uptime: String,
-}
-#[derive(Serialize)]
-pub struct StatisticsProcess {
- pub memory_usage: String,
- pub cpu_usage: String,
- // pub uptime: String,
-}