diff --git a/Cargo.lock b/Cargo.lock index b06abbf5b..4ab4beecb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -804,12 +804,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "doc-comment" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" - [[package]] name = "dtoa" version = "0.4.5" @@ -1059,15 +1053,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "getopts" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" -dependencies = [ - "unicode-width", -] - [[package]] name = "getrandom" version = "0.1.14" @@ -1574,7 +1559,6 @@ dependencies = [ "meilisearch-schema", "meilisearch-tokenizer", "mime", - "pretty-bytes", "rand 0.7.3", "regex", "rustls 0.16.0", @@ -1587,7 +1571,6 @@ dependencies = [ "siphasher", "slice-group-by", "structopt", - "sysinfo", "tempdir", "tokio", "ureq", @@ -1729,15 +1712,6 @@ dependencies = [ "void", ] -[[package]] -name = "ntapi" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a31937dea023539c72ddae0e3571deadc1414b300483fa7aaec176168cfa9d2" -dependencies = [ - "winapi 0.3.8", -] - [[package]] name = "num-integer" version = "0.1.42" @@ -1954,16 +1928,6 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" -[[package]] -name = "pretty-bytes" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "009d6edd2c1dbf2e1c0cd48a2f7766e03498d49ada7109a01c6911815c685316" -dependencies = [ - "atty", - "getopts", -] - [[package]] name = "proc-macro-error" version = "1.0.2" @@ -2621,21 +2585,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "sysinfo" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b796215da5a4b2a1a5db53ee55866c13b74a89acd259ab762eb10e28e937cb5" -dependencies = [ - "cfg-if", - "doc-comment", - "libc", - "ntapi", - "once_cell", - "rayon", - "winapi 0.3.8", -] - [[package]] name = "tempdir" version = "0.3.7" diff --git a/meilisearch-http/Cargo.toml b/meilisearch-http/Cargo.toml index 16de4ea38..266036497 100644 --- a/meilisearch-http/Cargo.toml +++ b/meilisearch-http/Cargo.toml @@ -37,7 +37,6 @@ meilisearch-error = { path = "../meilisearch-error", version = "0.12.0" } meilisearch-schema = { path = "../meilisearch-schema", version = "0.12.0" } meilisearch-tokenizer = {path = "../meilisearch-tokenizer", version = "0.12.0"} mime = "0.3.16" -pretty-bytes = "0.2.2" rand = "0.7.3" regex = "1.3.6" rustls = "0.16.0" @@ -48,7 +47,6 @@ sha2 = "0.8.1" siphasher = "0.3.2" slice-group-by = "0.2.6" structopt = "0.3.12" -sysinfo = "0.14.5" tokio = { version = "0.2.18", features = ["macros"] } ureq = { version = "0.12.0", features = ["tls"], default-features = false } walkdir = "2.3.1" diff --git a/meilisearch-http/src/data.rs b/meilisearch-http/src/data.rs index 3460b6bc1..f82f5649f 100644 --- a/meilisearch-http/src/data.rs +++ b/meilisearch-http/src/data.rs @@ -4,7 +4,6 @@ use std::sync::Arc; use meilisearch_core::{Database, DatabaseOptions}; use sha2::Digest; -use sysinfo::Pid; use crate::index_update_callback; use crate::option::Opt; @@ -27,7 +26,7 @@ pub struct DataInner { pub db: Arc, pub db_path: String, pub api_keys: ApiKeys, - pub server_pid: Pid, + pub server_pid: u32, pub http_payload_size_limit: usize, } @@ -58,7 +57,7 @@ impl ApiKeys { impl Data { pub fn new(opt: Opt) -> Result> { let db_path = opt.db_path.clone(); - let server_pid = sysinfo::get_current_pid().unwrap(); + let server_pid = std::process::id(); let db_opt = DatabaseOptions { main_map_size: opt.main_map_size, diff --git a/meilisearch-http/src/routes/stats.rs b/meilisearch-http/src/routes/stats.rs index fcbc8e453..8f43992a0 100644 --- a/meilisearch-http/src/routes/stats.rs +++ b/meilisearch-http/src/routes/stats.rs @@ -5,9 +5,7 @@ use actix_web::HttpResponse; use actix_web_macros::get; use chrono::{DateTime, Utc}; use log::error; -use pretty_bytes::converter::convert; use serde::Serialize; -use sysinfo::{NetworkExt, ProcessExt, ProcessorExt, System, SystemExt}; use walkdir::WalkDir; use crate::error::{Error, ResponseError}; @@ -18,9 +16,7 @@ use crate::Data; pub fn services(cfg: &mut web::ServiceConfig) { cfg.service(index_stats) .service(get_stats) - .service(get_version) - .service(get_sys_info) - .service(get_sys_info_pretty); + .service(get_version); } #[derive(Serialize)] @@ -136,204 +132,3 @@ async fn get_version() -> HttpResponse { pkg_version: env!("CARGO_PKG_VERSION").to_string(), }) } - -#[derive(Serialize)] -#[serde(rename_all = "camelCase")] -struct SysGlobal { - total_memory: u64, - used_memory: u64, - total_swap: u64, - used_swap: u64, - input_data: u64, - output_data: u64, -} - -impl SysGlobal { - fn new() -> SysGlobal { - SysGlobal { - total_memory: 0, - used_memory: 0, - total_swap: 0, - used_swap: 0, - input_data: 0, - output_data: 0, - } - } -} - -#[derive(Serialize)] -#[serde(rename_all = "camelCase")] -struct SysProcess { - memory: u64, - cpu: f32, -} - -impl SysProcess { - fn new() -> SysProcess { - SysProcess { - memory: 0, - cpu: 0.0, - } - } -} - -#[derive(Serialize)] -#[serde(rename_all = "camelCase")] -struct SysInfo { - memory_usage: f64, - processor_usage: Vec, - global: SysGlobal, - process: SysProcess, -} - -impl SysInfo { - fn new() -> SysInfo { - SysInfo { - memory_usage: 0.0, - processor_usage: Vec::new(), - global: SysGlobal::new(), - process: SysProcess::new(), - } - } -} - -#[get("/sys-info", wrap = "Authentication::Private")] -async fn get_sys_info(data: web::Data) -> HttpResponse { - let mut sys = System::new(); - let mut info = SysInfo::new(); - - // need to refresh twice for cpu usage - sys.refresh_all(); - sys.refresh_all(); - - for processor in sys.get_processors() { - info.processor_usage.push(processor.get_cpu_usage()); - } - - info.global.total_memory = sys.get_total_memory(); - info.global.used_memory = sys.get_used_memory(); - info.global.total_swap = sys.get_total_swap(); - info.global.used_swap = sys.get_used_swap(); - info.global.input_data = sys - .get_networks() - .into_iter() - .map(|(_, n)| n.get_received()) - .sum::(); - info.global.output_data = sys - .get_networks() - .into_iter() - .map(|(_, n)| n.get_transmitted()) - .sum::(); - - info.memory_usage = sys.get_used_memory() as f64 / sys.get_total_memory() as f64 * 100.0; - - if let Some(process) = sys.get_process(data.server_pid) { - info.process.memory = process.memory(); - println!("cpu usafe: {}", process.cpu_usage()); - info.process.cpu = process.cpu_usage(); - } - - HttpResponse::Ok().json(info) -} - -#[derive(Serialize)] -#[serde(rename_all = "camelCase")] -struct SysGlobalPretty { - total_memory: String, - used_memory: String, - total_swap: String, - used_swap: String, - input_data: String, - output_data: String, -} - -impl SysGlobalPretty { - fn new() -> SysGlobalPretty { - SysGlobalPretty { - total_memory: "None".to_owned(), - used_memory: "None".to_owned(), - total_swap: "None".to_owned(), - used_swap: "None".to_owned(), - input_data: "None".to_owned(), - output_data: "None".to_owned(), - } - } -} - -#[derive(Serialize)] -#[serde(rename_all = "camelCase")] -struct SysProcessPretty { - memory: String, - cpu: String, -} - -impl SysProcessPretty { - fn new() -> SysProcessPretty { - SysProcessPretty { - memory: "None".to_owned(), - cpu: "None".to_owned(), - } - } -} - -#[derive(Serialize)] -#[serde(rename_all = "camelCase")] -struct SysInfoPretty { - memory_usage: String, - processor_usage: Vec, - global: SysGlobalPretty, - process: SysProcessPretty, -} - -impl SysInfoPretty { - fn new() -> SysInfoPretty { - SysInfoPretty { - memory_usage: "None".to_owned(), - processor_usage: Vec::new(), - global: SysGlobalPretty::new(), - process: SysProcessPretty::new(), - } - } -} - -#[get("/sys-info/pretty", wrap = "Authentication::Private")] -async fn get_sys_info_pretty(data: web::Data) -> HttpResponse { - let mut sys = System::new(); - let mut info = SysInfoPretty::new(); - - sys.refresh_all(); - sys.refresh_all(); - info.memory_usage = format!( - "{:.1} %", - sys.get_used_memory() as f64 / sys.get_total_memory() as f64 * 100.0 - ); - - for processor in sys.get_processors() { - info.processor_usage - .push(format!("{:.1} %", processor.get_cpu_usage())); - } - - info.global.total_memory = convert(sys.get_total_memory() as f64 * 1024.0); - info.global.used_memory = convert(sys.get_used_memory() as f64 * 1024.0); - info.global.total_swap = convert(sys.get_total_swap() as f64 * 1024.0); - info.global.used_swap = convert(sys.get_used_swap() as f64 * 1024.0); - info.global.input_data = convert( - sys.get_networks() - .into_iter() - .map(|(_, n)| n.get_received()) - .sum::() as f64, - ); - info.global.output_data = convert( - sys.get_networks() - .into_iter() - .map(|(_, n)| n.get_transmitted()) - .sum::() as f64, - ); - - if let Some(process) = sys.get_process(data.server_pid) { - info.process.memory = convert(process.memory() as f64 * 1024.0); - info.process.cpu = format!("{:.1} %", process.cpu_usage()); - } - - HttpResponse::Ok().json(info) -}