Skip to content

Commit

Permalink
ssh versions check
Browse files Browse the repository at this point in the history
  • Loading branch information
maksimryndin committed Jul 20, 2024
1 parent fab42b1 commit 5c6aa2c
Show file tree
Hide file tree
Showing 6 changed files with 344 additions and 62 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* 0.1.9
* reorder system logs fields for charts
* ssh versions checks

* 0.1.8
* fix ssh logs parsing

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ serde = "^1.0"
serde_derive = "^1.0"
serde_json = "^1.0"
serde_valid = { version = "0.16.3", features = ["toml"] }
sysinfo = { version = "0.30", default_features = false }
sysinfo = { version = "0.30", default-features = false }
tokio = { version = "^1.0", features = ["sync", "signal", "io-std", "process", "net"] }
tonic = { version = "^0.10", features = ["transport", "prost"]}
tonic-health = "0.10.2"
Expand Down
16 changes: 7 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ use services::healthcheck::{HealthcheckService, HEALTHCHECK_SERVICE_NAME};
use services::kv::{KvService, KV_SERVICE_NAME};
use services::logs::{LogsService, LOGS_SERVICE_NAME};
use services::metrics::{MetricsService, METRICS_SERVICE_NAME};
use services::system::{SystemService, SYSTEM_SERVICE_NAME};
use services::system::{collector::system_info, SystemService, SYSTEM_SERVICE_NAME};
pub use services::*;
use std::collections::HashMap;
use std::fmt::{self, Debug};
use std::sync::Arc;
use std::time::Duration;
pub use storage::*;
use sysinfo::System;
use tokio::sync::mpsc::Receiver;

pub(crate) type HyperConnector = HttpsConnector<HttpConnector>;
Expand Down Expand Up @@ -227,19 +226,18 @@ pub async fn welcome(
truncation_check: Result<(), String>,
) {
let sys = tokio::task::spawn_blocking(|| {
sysinfo::set_open_files_limit(0);
let sys = System::new_all();
let mem = sys.total_memory() / 1000 / 1000;
let sys = system_info();
let mem = sys.total_memory / 1000 / 1000;
let mem = if mem > 1000 {
format!("{}G", mem / 1000)
} else {
format!("{mem}M")
};
match (
System::name(),
System::long_os_version(),
System::kernel_version(),
System::host_name(),
sys.name.as_ref(),
sys.long_os_version.as_ref(),
sys.kernel_version.as_ref(),
sys.host_name.as_ref(),
) {
(Some(name), Some(os_version), Some(kernel_version), Some(host_name)) => format!(
"{name} {os_version}(kernel {kernel_version}); hostname: {host_name}, RAM {mem}"
Expand Down
19 changes: 19 additions & 0 deletions src/services/system/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,25 @@ pub(super) fn initialize() -> System {
sys
}

pub(crate) struct SystemInfo {
pub(crate) name: Option<String>,
pub(crate) long_os_version: Option<String>,
pub(crate) kernel_version: Option<String>,
pub(crate) host_name: Option<String>,
pub(crate) total_memory: u64,
}

pub(crate) fn system_info() -> SystemInfo {
let sys = initialize();
SystemInfo {
name: System::name(),
long_os_version: System::long_os_version(),
kernel_version: System::kernel_version(),
host_name: System::host_name(),
total_memory: sys.total_memory(),
}
}

pub(super) fn collect(
sys: &mut System,
mounts: &[String],
Expand Down
Loading

0 comments on commit 5c6aa2c

Please sign in to comment.