Fix remaining clippy warnings in socktop_agent
This commit is contained in:
parent
764c25846f
commit
eed04f1d5c
@ -74,12 +74,12 @@ fn cached_temp() -> Option<f32> {
|
||||
}
|
||||
|
||||
fn set_temp(v: Option<f32>) {
|
||||
if let Some(lock) = TEMP.get() {
|
||||
if let Ok(mut c) = lock.lock() {
|
||||
if let Some(lock) = TEMP.get()
|
||||
&& let Ok(mut c) = lock.lock()
|
||||
{
|
||||
c.v = v;
|
||||
c.at = Some(Instant::now());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn cached_gpus() -> Option<Vec<crate::gpu::GpuMetrics>> {
|
||||
@ -98,12 +98,12 @@ fn cached_gpus() -> Option<Vec<crate::gpu::GpuMetrics>> {
|
||||
}
|
||||
|
||||
fn set_gpus(v: Option<Vec<crate::gpu::GpuMetrics>>) {
|
||||
if let Some(lock) = GPUC.get() {
|
||||
if let Ok(mut c) = lock.lock() {
|
||||
if let Some(lock) = GPUC.get()
|
||||
&& let Ok(mut c) = lock.lock()
|
||||
{
|
||||
c.v = v.clone();
|
||||
c.at = Some(Instant::now());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Collect only fast-changing metrics (CPU/mem/net + optional temps/gpus).
|
||||
@ -116,12 +116,12 @@ pub async fn collect_fast_metrics(state: &AppState) -> Metrics {
|
||||
let ttl = StdDuration::from_millis(ttl_ms);
|
||||
{
|
||||
let cache = state.cache_metrics.lock().await;
|
||||
if cache.is_fresh(ttl) {
|
||||
if let Some(c) = cache.get() {
|
||||
if cache.is_fresh(ttl)
|
||||
&& let Some(c) = cache.get()
|
||||
{
|
||||
return c.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut sys = state.sys.lock().await;
|
||||
if let Err(e) = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
||||
sys.refresh_cpu_usage();
|
||||
@ -278,12 +278,12 @@ pub async fn collect_disks(state: &AppState) -> Vec<DiskInfo> {
|
||||
let ttl = StdDuration::from_millis(ttl_ms);
|
||||
{
|
||||
let cache = state.cache_disks.lock().await;
|
||||
if cache.is_fresh(ttl) {
|
||||
if let Some(v) = cache.get() {
|
||||
if cache.is_fresh(ttl)
|
||||
&& let Some(v) = cache.get()
|
||||
{
|
||||
return v.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut disks_list = state.disks.lock().await;
|
||||
disks_list.refresh(false); // don't drop missing disks
|
||||
let disks: Vec<DiskInfo> = disks_list
|
||||
@ -347,12 +347,12 @@ pub async fn collect_processes_all(state: &AppState) -> ProcessesPayload {
|
||||
let ttl = StdDuration::from_millis(ttl_ms);
|
||||
{
|
||||
let cache = state.cache_processes.lock().await;
|
||||
if cache.is_fresh(ttl) {
|
||||
if let Some(c) = cache.get() {
|
||||
if cache.is_fresh(ttl)
|
||||
&& let Some(c) = cache.get()
|
||||
{
|
||||
return c.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Reuse shared System to avoid reallocation; refresh processes fully.
|
||||
let mut sys_guard = state.sys.lock().await;
|
||||
let sys = &mut *sys_guard;
|
||||
|
||||
@ -40,13 +40,13 @@ pub async fn ws_handler(
|
||||
Query(q): Query<HashMap<String, String>>,
|
||||
) -> Response {
|
||||
// optional auth
|
||||
if let Some(expected) = state.auth_token.as_ref() {
|
||||
if q.get("token") != Some(expected) {
|
||||
if let Some(expected) = state.auth_token.as_ref()
|
||||
&& q.get("token") != Some(expected)
|
||||
{
|
||||
return ws.on_upgrade(|socket| async move {
|
||||
let _ = socket.close().await;
|
||||
});
|
||||
}
|
||||
}
|
||||
ws.on_upgrade(move |socket| handle_socket(socket, state))
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user