Skip to content

Commit

Permalink
Minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user committed Sep 23, 2024
1 parent 0246acd commit 77af3d4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 40 deletions.
19 changes: 18 additions & 1 deletion src/resources/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ use inflector::cases::titlecase::to_title_case;
use sysinfo::{DiskExt, System, SystemExt};
use crate::{squire, resources};

/// Function to get total disk usage.
///
/// # Arguments
///
/// * `system` - A reference to the `System` struct.
///
/// # Returns
///
/// A `u64` value containing the total disk usage.
pub fn get_disk_usage(system: &System) -> u64 {
let mut disks_space = vec![];
for disk in system.disks() {
disks_space.push(disk.total_space());
}
disks_space.iter().sum()
}

/// Function to get system information
///
/// This function retrieves system information such as basic system information and memory/storage information.
Expand All @@ -21,7 +38,7 @@ pub fn get_sys_info() -> HashMap<&'static str, HashMap<&'static str, String>> {
let uptime = squire::util::convert_seconds(uptime_duration);

let total_memory = squire::util::size_converter(sys.total_memory()); // in bytes
let total_storage = squire::util::size_converter(sys.disks().iter().map(|disk| disk.total_space()).sum::<u64>());
let total_storage = squire::util::size_converter(get_disk_usage(&sys)); // in bytes

// Basic and Memory/Storage Info
let os_arch = resources::system::os_arch();
Expand Down
5 changes: 3 additions & 2 deletions src/resources/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ fn get_system_metrics() -> HashMap<String, serde_json::Value> {
system.refresh_all();

let load_avg = system.load_average();
let mem_total = system.total_memory();

// used_memory uses "mem_total - mem_free" but memory is set to available instead of free in macOS
let mut hash_vec = vec![
(
"memory_info".to_string(),
serde_json::json!({
"total": system.total_memory(),
"used": system.total_memory() - system.available_memory(),
"total": mem_total,
"used": mem_total - system.available_memory(),
}),
),
(
Expand Down
13 changes: 6 additions & 7 deletions src/squire/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ pub fn init_logger(debug: bool, utc: bool, crate_name: &String) {
));
std::env::set_var("RUST_BACKTRACE", "0");
}
let timestamp;
if utc {
timestamp = DateTime::<chrono::Utc>::from(Local::now())
let timestamp = if utc {
DateTime::<chrono::Utc>::from(Local::now())
.format("%Y-%m-%dT%H:%M:%SZ")
.to_string();
.to_string()
} else {
timestamp = Local::now()
Local::now()
.format("%Y-%m-%dT%H:%M:%SZ")
.to_string();
}
.to_string()
};
env_logger::Builder::from_default_env()
.format(move |buf, record| {
writeln!(
Expand Down
30 changes: 0 additions & 30 deletions src/templates/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,26 +149,6 @@ pub fn get_content() -> String {
align-content: center;
}
.docs {
position: absolute;
top: 3.8%;
right: 230px;
border: none;
padding: 10px 14px;
font-size: 16px;
cursor: pointer;
}
.redoc {
position: absolute;
top: 3.8%;
right: 130px;
border: none;
padding: 10px 14px;
font-size: 16px;
cursor: pointer;
}
.logout {
position: absolute;
top: 3.8%;
Expand Down Expand Up @@ -203,8 +183,6 @@ pub fn get_content() -> String {
</div>
<body translate="no">
<div class="toggler fa fa-moon-o"></div>
<button class="docs" onclick="goDocs()"><i class="fa fa-book"></i> Docs</button>
<button class="redoc" onclick="goReDoc()"><i class="fa fa-file"></i> ReDoc</button>
<button class="logout" onclick="logOut()"><i class="fa fa-sign-out"></i> Logout</button>
<h1>SysMonk - System Monitor</h1>
<div class="center-container">
Expand Down Expand Up @@ -570,14 +548,6 @@ pub fn get_content() -> String {
function logOut() {
window.location.href = window.location.origin + "{{ logout }}";
}
function goDocs() {
window.location.href = window.location.origin + "/docs";
}
function goReDoc() {
window.location.href = window.location.origin + "/redoc";
}
</script>
</body>
</html>
Expand Down

0 comments on commit 77af3d4

Please sign in to comment.