Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature : Get CPU temperature over the RPC #139

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ leveldb-sys = "2.0.9"
async-trait = "0.1.77"
async-stream = "0.3.5"
sha3 = "0.10.8"
systemstat = "0.2.3"
readonly = "0.2.12"

[dev-dependencies]
Expand Down
26 changes: 26 additions & 0 deletions src/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::collections::HashMap;
use std::net::IpAddr;
use std::net::SocketAddr;
use std::str::FromStr;
use systemstat::{Platform, System};
use tarpc::context;
use tokio::sync::mpsc::error::SendError;
use tracing::{error, info};
Expand Down Expand Up @@ -223,6 +224,9 @@ pub trait RPC {

/// Gracious shutdown.
async fn shutdown() -> bool;

/// Get CPU temperature.
async fn cpu_temp() -> Option<f64>;
}

#[derive(Clone)]
Expand Down Expand Up @@ -747,6 +751,14 @@ impl RPC for NeptuneRPCServer {
.get_all_own_coins_with_possible_timelocks()
.await
}

async fn cpu_temp(self, _context: tarpc::context::Context) -> Option<f64> {
elielnfinic marked this conversation as resolved.
Show resolved Hide resolved
let current_system = System::new();
match current_system.cpu_temp() {
Ok(temp) => Some(temp.into()),
Err(_) => None,
}
}
}

#[cfg(test)]
Expand Down Expand Up @@ -1126,6 +1138,20 @@ mod rpc_server_tests {
Ok(())
}

#[traced_test]
#[tokio::test]
async fn test_can_get_server_temperature() {
let (rpc_server, _state_lock) =
test_rpc_server(Network::Alpha, WalletSecret::new_random(), 2).await;
let current_server_temperature = rpc_server.cpu_temp(context::current()).await;
// Silicon Macs do not provide CPU temperature using systemstat
if std::env::consts::OS == "macos" {
assert!(current_server_temperature.is_none());
} else {
assert!(current_server_temperature.is_some());
}
}

#[traced_test]
#[tokio::test]
async fn utxo_digest_test() {
Expand Down