Skip to content

Commit

Permalink
feat(dashboard): add cpu temp
Browse files Browse the repository at this point in the history
NOT YET WORKING! See heim-rs/heim#354.
  • Loading branch information
ravenclaw900 committed Nov 27, 2021
1 parent 592cdfd commit 0b82f47
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ lazy_static = "1.4.0"
futures = "0.3.18"
nanoserde = "0.1.29"
pty-process = "0.1.1"
heim = { git = "https://github.com/heim-rs/heim", features = ["cpu", "disk", "host", "memory", "net", "process"] }
heim = { git = "https://github.com/heim-rs/heim", features = ["cpu", "disk", "host", "memory", "net", "process", "sensors"] }
infer = { version = "0.5.0", default-features = false }
jwts = "0.2.3"
sha2 = "0.9.8"
Expand Down
10 changes: 9 additions & 1 deletion src/backend/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct SysData {
pub swap: UsageData,
pub disk: UsageData,
pub network: NetData,
pub temp: CPUTemp,
}

#[derive(SerJson)]
Expand Down Expand Up @@ -124,7 +125,7 @@ pub struct GlobalData {
pub login: bool,
}

#[derive(SerJson, Debug)]
#[derive(SerJson)]
pub struct BrowserDirData {
pub path: String,
pub name: String,
Expand All @@ -148,3 +149,10 @@ pub struct BrowserList {
pub struct TokenError {
pub error: bool,
}

#[derive(SerJson)]
pub struct CPUTemp {
pub available: bool,
pub celsius: f32,
pub fahrenheit: f32,
}
1 change: 1 addition & 0 deletions src/backend/src/sockets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ async fn main_handler(
swap: systemdata::swap().await,
disk: systemdata::disk().await,
network: systemdata::network().await,
temp: systemdata::temperature().await,
})))
.await;
}
Expand Down
34 changes: 33 additions & 1 deletion src/backend/src/systemdata.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use futures::StreamExt;
use heim::{
cpu, disk, host, memory, net, process,
cpu, disk, host, memory, net, process, sensors,
units::{
information::{byte, mebibyte},
ratio::percent,
thermodynamic_temperature::{degree_celsius, degree_fahrenheit},
time::minute,
},
};
Expand Down Expand Up @@ -503,3 +504,34 @@ pub fn browser_dir(path: &std::path::Path) -> Vec<shared::BrowserDirData> {
}
file_list
}

pub async fn temperature() -> shared::CPUTemp {
let temps = sensors::temperatures()
.collect::<Vec<Result<sensors::TemperatureSensor, heim::Error>>>()
.await;
for temp_wrapped in &*temps {
let temp;
match temp_wrapped {
Err(_) => {
return shared::CPUTemp {
available: false,
celsius: 0.0,
fahrenheit: 0.0,
};
}
Ok(unwrapped_temp) => temp = unwrapped_temp,
};
if temp.unit() == "cpu_thermal" {
return shared::CPUTemp {
available: true,
celsius: temp.current().get::<degree_celsius>(),
fahrenheit: temp.current().get::<degree_fahrenheit>(),
};
}
}
shared::CPUTemp {
available: false,
celsius: 0.0,
fahrenheit: 0.0,
}
}
Binary file modified src/frontend/.yarn/install-state.gz
Binary file not shown.
6 changes: 6 additions & 0 deletions src/frontend/src/pages/Home.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@
</Card>
{#if ramData != undefined}
<Card header="System Stats">
{#if socketData.temp.available}
CPU Temp: <span class="float-right"
>{socketData.temp.celsius}'C, {socketData.temp
.fahrenheit}'F</span
>
{/if}
CPU:<span class="float-right">{socketData.cpu}/100%</span>
<div class="bg-gray-200 dark:bg-gray-800 w-full h-3 my-1">
<div class="bg-green-500 h-3" style="width:{$cpuAnimate}%" />
Expand Down

0 comments on commit 0b82f47

Please sign in to comment.