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 5 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
17 changes: 16 additions & 1 deletion 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"

[dev-dependencies]
test-strategy = "0.3"
Expand Down
27 changes: 27 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 @@ -222,6 +223,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 @@ -744,6 +748,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 @@ -1123,6 +1135,21 @@ mod rpc_server_tests {
Ok(())
}

#[allow(clippy::shadow_unrelated)]
elielnfinic marked this conversation as resolved.
Show resolved Hide resolved
#[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