hubcio commented on code in PR #4318:
URL: https://github.com/apache/iggy/pull/4318#discussion_r4136718752


##########
core/server/src/sysinfo_printer.rs:
##########
@@ -0,0 +1,205 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Periodic one-line log of process and host usage.
+//!
+//! Spawned on shard 0 only: the numbers describe the whole process, so one
+//! line per node is enough, and the client count is already a cross-shard
+//! gather.
+
+use crate::responses::{StatsTotals, stats_totals};
+use crate::shell::ServerShard;
+use crate::sysinfo_probe::{SystemStats, publish_open_files_count, 
stats_disk_space};
+use iggy_common::IggyByteSize;
+use shard::Receiver;
+use std::fmt;
+use std::rc::Rc;
+use std::time::Duration;
+use sysinfo::System as SysinfoSystem;
+use tracing::level_filters::LevelFilter;
+use tracing::{error, info, trace};
+
+/// Run the printer until `stop` fires, logging one line every `interval`.
+pub async fn run_sysinfo_printer(shard: Rc<ServerShard>, stop: Receiver<()>, 
interval: Duration) {
+    info!("System info logger is enabled, OS info will be printed every: 
{interval:?}");
+    // Not the shared `GetStats` sampler: a tick would reset its CPU window, 
and
+    // a `GetStats` on shard 0 right after a tick would show CPU near zero.
+    // Sampled once now, so the first line covers a full interval.
+    let mut system = SysinfoSystem::new();
+    SystemStats::capture(&mut system);
+    loop {
+        // `Ok(_)`: stop signalled -> exit. `Err(_)`: interval elapsed -> 
print.
+        match compio::time::timeout(interval, stop.recv()).await {
+            Ok(_) => break,
+            Err(_) => print_sysinfo(&shard, &mut system).await,
+        }
+    }
+    trace!(shard = shard.id, "sysinfo printer exited");
+}
+
+async fn print_sysinfo(shard: &Rc<ServerShard>, system: &mut SysinfoSystem) {
+    // `GetStats` reads this count where the kernel keeps none, so it is
+    // published also while the line itself is filtered out.
+    publish_open_files_count();

Review Comment:
   about this: please figure out something async so that its nonblocking.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to