Skip to content

Commit

Permalink
Merge pull request #3 from maksimryndin/charts
Browse files Browse the repository at this point in the history
Charts, ssh versions checks, system support check
  • Loading branch information
maksimryndin authored Jul 27, 2024
2 parents c817f88 + 930e857 commit 6c29180
Show file tree
Hide file tree
Showing 10 changed files with 494 additions and 78 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/BUG_REPORT.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ body:
label: Which version of Goral do you run (`goral --version`)?
multiple: false
options:
- 0.1.9
- 0.1.8
- 0.1.7
- 0.1.6
Expand Down
2 changes: 1 addition & 1 deletion .github/site/src/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ main() {

get_architecture || return 1
local _arch="$RETVAL"
local _version=${1:-'0.1.8'}
local _version=${1:-'0.1.9'}
assert_nz "$_arch" "arch"

local _file="goral-${_version}-${_arch}"
Expand Down
8 changes: 4 additions & 4 deletions .github/site/src/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ curl --proto '=https' --tlsv1.2 -sSf https://maksimryndin.github.io/goral/instal
</summary>

```sh
wget https://github.com/maksimryndin/goral/releases/download/0.1.8/goral-0.1.8-x86_64-unknown-linux-gnu.tar.gz
tar -xzf goral-0.1.8-x86_64-unknown-linux-gnu.tar.gz
cd goral-0.1.8-x86_64-unknown-linux-gnu/
wget https://github.com/maksimryndin/goral/releases/download/0.1.9/goral-0.1.9-x86_64-unknown-linux-gnu.tar.gz
tar -xzf goral-0.1.9-x86_64-unknown-linux-gnu.tar.gz
cd goral-0.1.9-x86_64-unknown-linux-gnu/
shasum -a 256 -c sha256_checksum.txt
```
</details>
Expand All @@ -23,7 +23,7 @@ shasum -a 256 -c sha256_checksum.txt

```sh
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
git clone --depth 1 --branch 0.1.8 https://github.com/maksimryndin/goral
git clone --depth 1 --branch 0.1.9 https://github.com/maksimryndin/goral
cd goral
RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --target <target triple>
```
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* 0.1.9
* reorder system logs fields for charts
* ssh versions checks (for ubuntu)
* system support check (for ubuntu)

* 0.1.8
* fix ssh logs parsing

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "goral"
version = "0.1.8"
version = "0.1.9"
edition = "2021"
author = "Maksim Ryndin"
license = "Apache-2.0"
Expand Down 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
39 changes: 29 additions & 10 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 All @@ -217,25 +236,25 @@ pub(super) fn collect(
)
.expect("assert: system boot time timestamp should be valid");
let basic = [
("boot_time".to_string(), Datavalue::Datetime(boot_time)),
(
"memory_available".to_string(),
Datavalue::Size(sys.available_memory()),
),
(
MEMORY_USE.to_string(),
// SAFE for percentage calculation to cast from u64 to f64
Datavalue::HeatmapPercent(100.0 * sys.used_memory() as f64 / total_memory as f64),
),
(
"swap_available".to_string(),
Datavalue::Size(sys.free_swap()),
),
(
SWAP_USE.to_string(),
// SAFE for percentage calculation to cast from u64 to f64
Datavalue::HeatmapPercent(100.0 * sys.used_swap() as f64 / sys.total_swap() as f64),
),
("boot_time".to_string(), Datavalue::Datetime(boot_time)),
(
"memory_available".to_string(),
Datavalue::Size(sys.available_memory()),
),
(
"swap_available".to_string(),
Datavalue::Size(sys.free_swap()),
),
(
"num_of_processes".to_string(),
Datavalue::Integer(
Expand All @@ -252,7 +271,7 @@ pub(super) fn collect(
)
});

let basic_values: Vec<(String, Datavalue)> = basic.into_iter().chain(cpus).collect();
let basic_values: Vec<(String, Datavalue)> = cpus.into_iter().chain(basic).collect();

// 1 for basic, 5 for top_ stats, 1 for network
let mut datarows = Vec::with_capacity(1 + mounts.len() + 5 + names.len() + 1);
Expand Down
Loading

0 comments on commit 6c29180

Please sign in to comment.