projects
/
valheim_web.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
f5ee5c4
)
Adding information about backup (WIP)
author
Greg Burri
<greg.burri@gmail.com>
Tue, 16 Mar 2021 18:13:02 +0000
(19:13 +0100)
committer
Greg Burri
<greg.burri@gmail.com>
Tue, 16 Mar 2021 18:13:02 +0000
(19:13 +0100)
Cargo.lock
patch
|
blob
|
history
backend/Cargo.toml
patch
|
blob
|
history
backend/src/main.rs
patch
|
blob
|
history
backend/src/valheim_controller.rs
patch
|
blob
|
history
backend/style.scss
patch
|
blob
|
history
backend/templates/main.html
patch
|
blob
|
history
diff --git
a/Cargo.lock
b/Cargo.lock
index
0f9f90f
..
d013294
100644
(file)
--- a/
Cargo.lock
+++ b/
Cargo.lock
@@
-2035,6
+2035,7
@@
dependencies = [
"actix-web",
"askama",
"cached",
"actix-web",
"askama",
"cached",
+ "chrono",
"common",
"futures",
"itertools",
"common",
"futures",
"itertools",
diff --git
a/backend/Cargo.toml
b/backend/Cargo.toml
index
351f710
..
2dbae9f
100644
(file)
--- a/
backend/Cargo.toml
+++ b/
backend/Cargo.toml
@@
-13,6
+13,8
@@
serde = { version = "1.0", features = ["derive"] }
ron = "0.6" # Rust object notation, to load configuration files.
itertools = "0.10"
ron = "0.6" # Rust object notation, to load configuration files.
itertools = "0.10"
+chrono = "0.4"
+
sysinfo = "0.16"
cached = "0.23"
sysinfo = "0.16"
cached = "0.23"
diff --git
a/backend/src/main.rs
b/backend/src/main.rs
index
03963c1
..
a2201d4
100644
(file)
--- a/
backend/src/main.rs
+++ b/
backend/src/main.rs
@@
-22,6
+22,7
@@
struct MainTemplate {
uptime: String,
world_size: String,
nb_of_players: u32,
uptime: String,
world_size: String,
nb_of_players: u32,
+ last_backup: String,
}
const VALUE_UNKNOWN: &str = "-";
}
const VALUE_UNKNOWN: &str = "-";
@@
-43,11
+44,12
@@
async fn main_page(config_shared: web::Data<Mutex<Config>>) -> impl Responder {
load_average: info.format_load_average(),
uptime: info.format_uptime(),
world_size: info.format_world_size(),
load_average: info.format_load_average(),
uptime: info.format_uptime(),
world_size: info.format_world_size(),
- nb_of_players: info.get_nb_of_player()
+ nb_of_players: info.get_nb_of_player(),
+ last_backup: info.format_last_backup()
},
None => {
let value_unknown = String::from(VALUE_UNKNOWN);
},
None => {
let value_unknown = String::from(VALUE_UNKNOWN);
- MainTemplate { text_status: String::from("Valheim server is down :("), memory: value_unknown.clone(), load_average: value_unknown.clone(), uptime: value_unknown.clone(), world_size: value_unknown.clone(), nb_of_players: 0 }
+ MainTemplate { text_status: String::from("Valheim server is down :("), memory: value_unknown.clone(), load_average: value_unknown.clone(), uptime: value_unknown.clone(), world_size: value_unknown.clone(), nb_of_players: 0
, last_backup: value_unknown.clone()
}
}
}
}
}
}
}
@@
-55,15
+57,19
@@
async fn main_page(config_shared: web::Data<Mutex<Config>>) -> impl Responder {
#[derive(Debug, Deserialize, Serialize)]
struct Config {
port: u16,
#[derive(Debug, Deserialize, Serialize)]
struct Config {
port: u16,
+
#[serde(default = "empty_string")]
world_path: String,
#[serde(default = "empty_string")]
world_path: String,
+
+ #[serde(default = "empty_string")]
+ backup_path: String,
}
fn empty_string() -> String { "".to_owned() }
impl Config {
fn default() -> Self {
}
fn empty_string() -> String { "".to_owned() }
impl Config {
fn default() -> Self {
- Config { port: 8082, world_path: String::from("") }
+ Config { port: 8082, world_path: String::from("")
, backup_path: String::from("")
}
}
}
}
}
@@
-128,7
+134,7
@@
fn process_args(config: &Config) -> bool {
print_usage();
return true
} else if args.iter().any(|arg| arg == "--status") {
print_usage();
return true
} else if args.iter().any(|arg| arg == "--status") {
- println!("{:?}", valheim_controller::get_valheim_executable_information(&config.world_path));
+ println!("{:?}", valheim_controller::get_valheim_executable_information(&config.world_path
, &config.backup_path
));
return true
}
return true
}
diff --git
a/backend/src/valheim_controller.rs
b/backend/src/valheim_controller.rs
index
3c2bab6
..
3d99033
100644
(file)
--- a/
backend/src/valheim_controller.rs
+++ b/
backend/src/valheim_controller.rs
@@
-1,4
+1,5
@@
use sysinfo::{ ProcessExt, SystemExt };
\r
use sysinfo::{ ProcessExt, SystemExt };
\r
+use chrono::{ DateTime, Datelike, Timelike, Utc };
\r
\r
#[cfg(target_os = "unix")]
\r
use systemd::journal;
\r
\r
#[cfg(target_os = "unix")]
\r
use systemd::journal;
\r
@@
-10,6
+11,7
@@
pub struct ValheimExe {
uptime: u64, // [s].
\r
world_size: u64, // [B].
\r
nb_of_players: u32,
\r
uptime: u64, // [s].
\r
world_size: u64, // [B].
\r
nb_of_players: u32,
\r
+ last_backup: DateTime,
\r
}
\r
\r
impl ValheimExe {
\r
}
\r
\r
impl ValheimExe {
\r
@@
-35,6
+37,10
@@
impl ValheimExe {
pub fn get_nb_of_player(&self) -> u32 {
\r
self.nb_of_players
\r
}
\r
pub fn get_nb_of_player(&self) -> u32 {
\r
self.nb_of_players
\r
}
\r
+
\r
+ pub fn format_last_backup(&self) -> String {
\r
+ string::from("")
\r
+ }
\r
}
\r
\r
const BINARY_PREFIXES: [&str; 8] = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB"];
\r
}
\r
\r
const BINARY_PREFIXES: [&str; 8] = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB"];
\r
@@
-90,7
+96,11
@@
fn get_number_of_players() -> u32 {
0
\r
}
\r
\r
0
\r
}
\r
\r
-pub fn get_valheim_executable_information(world_path : &str) -> Option<ValheimExe> {
\r
+fn get_last_backup_datetime(backup_path: &str) -> DateTime {
\r
+
\r
+}
\r
+
\r
+pub fn get_valheim_executable_information(world_path: &str, backup_path: &str) -> Option<ValheimExe> {
\r
let mut system = sysinfo::System::new_all();
\r
system.refresh_system();
\r
let processes = system.get_process_by_name(VALHEIM_PROCESS_NAME);
\r
let mut system = sysinfo::System::new_all();
\r
system.refresh_system();
\r
let processes = system.get_process_by_name(VALHEIM_PROCESS_NAME);
\r
@@
-106,7
+116,8
@@
pub fn get_valheim_executable_information(world_path : &str) -> Option<ValheimEx
load_average_5min: system.get_load_average().five / system.get_processors().len() as f64 * 100.,
\r
uptime: std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs() - process.start_time(),
\r
world_size,
\r
load_average_5min: system.get_load_average().five / system.get_processors().len() as f64 * 100.,
\r
uptime: std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs() - process.start_time(),
\r
world_size,
\r
- nb_of_players: get_number_of_players()
\r
+ nb_of_players: get_number_of_players(),
\r
+ last_backup: get_last_backup_datetime(backup_path)
\r
}
\r
)
\r
} else {
\r
}
\r
)
\r
} else {
\r
diff --git
a/backend/style.scss
b/backend/style.scss
index
91d74e2
..
1ae90bd
100644
(file)
--- a/
backend/style.scss
+++ b/
backend/style.scss
@@
-7,8
+7,8
@@
body {
font-family: Fira Code, Helvetica Neue, Helvetica, Arial, sans-serif;
text-shadow: 2px 2px 2px #DDD;
text-align: center;
font-family: Fira Code, Helvetica Neue, Helvetica, Arial, sans-serif;
text-shadow: 2px 2px 2px #DDD;
text-align: center;
- color: #
5b5b5b
;
- background-color: #
ededed
;
+ color: #
ededed
;
+ background-color: #
5b5b5b
;
}
h1 {
}
h1 {
diff --git
a/backend/templates/main.html
b/backend/templates/main.html
index
588cfae
..
f33887e
100644
(file)
--- a/
backend/templates/main.html
+++ b/
backend/templates/main.html
@@
-15,6
+15,7
@@
<p>Memory used: {{ memory }}</p>
\r
<p>Load average (5 min): {{ load_average }}</p>
\r
<p>Uptime: {{ uptime }}</p>
\r
<p>Memory used: {{ memory }}</p>
\r
<p>Load average (5 min): {{ load_average }}</p>
\r
<p>Uptime: {{ uptime }}</p>
\r
+ <p>Last backup: {{ last_backup }}</p>
\r
</div>
\r
</body>
\r
</html>
\ No newline at end of file
</div>
\r
</body>
\r
</html>
\ No newline at end of file