projects
/
valheim_web.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Replace cpu usage by load average
[valheim_web.git]
/
backend
/
src
/
valheim_controller.rs
diff --git
a/backend/src/valheim_controller.rs
b/backend/src/valheim_controller.rs
index
cf18e08
..
fd6dcc4
100644
(file)
--- a/
backend/src/valheim_controller.rs
+++ b/
backend/src/valheim_controller.rs
@@
-1,11
+1,9
@@
-use std::cmp::min;
\r
-
\r
use sysinfo::{ ProcessExt, SystemExt };
\r
\r
#[derive(Debug)]
\r
pub struct ValheimExe {
\r
memory: u64, // [kB].
\r
use sysinfo::{ ProcessExt, SystemExt };
\r
\r
#[derive(Debug)]
\r
pub struct ValheimExe {
\r
memory: u64, // [kB].
\r
-
cpu_usage: f32
, // [%].
\r
+
load_average_5min: f64
, // [%].
\r
uptime: u64, // [s].
\r
}
\r
\r
uptime: u64, // [s].
\r
}
\r
\r
@@
-13,8
+11,8
@@
impl ValheimExe {
pub fn format_memory(&self) -> String {
\r
format_byte_size(self.memory * 1024, 2)
\r
}
\r
pub fn format_memory(&self) -> String {
\r
format_byte_size(self.memory * 1024, 2)
\r
}
\r
- pub fn format_
cpu_us
age(&self) -> String {
\r
- format!("{:.2} %", self.
cpu_usage
)
\r
+ pub fn format_
load_aver
age(&self) -> String {
\r
+ format!("{:.2} %", self.
load_average_5min
)
\r
}
\r
pub fn format_uptime(&self) -> String {
\r
let mins = self.uptime / 60;
\r
}
\r
pub fn format_uptime(&self) -> String {
\r
let mins = self.uptime / 60;
\r
@@
-44,7
+42,7
@@
fn format_byte_size(bytes: u64, precision: usize) -> String {
String::from("")
\r
}
\r
\r
String::from("")
\r
}
\r
\r
-const VALHEIM_PROCESS_NAME: &str = "valheim_server";
\r
+const VALHEIM_PROCESS_NAME: &str = "
firefox"; //
valheim_server";
\r
\r
pub fn get_valheim_executable_information() -> Option<ValheimExe> {
\r
let mut system = sysinfo::System::new_all();
\r
\r
pub fn get_valheim_executable_information() -> Option<ValheimExe> {
\r
let mut system = sysinfo::System::new_all();
\r
@@
-57,11
+55,11
@@
pub fn get_valheim_executable_information() -> Option<ValheimExe> {
Some(
\r
ValheimExe {
\r
memory: process.memory(),
\r
Some(
\r
ValheimExe {
\r
memory: process.memory(),
\r
-
cpu_usage: process.cpu_usage()
,
\r
+
load_average_5min: system.get_load_average().five
,
\r
uptime: std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs() - process.start_time()
\r
}
\r
)
\r
} else {
\r
None
\r
}
\r
uptime: std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs() - process.start_time()
\r
}
\r
)
\r
} else {
\r
None
\r
}
\r
-}
\ No newline at end of file
+}
\r