From e2f8c15fa2d225654db29419143dc6d65b54c6ba Mon Sep 17 00:00:00 2001 From: pierre Date: Mon, 19 Aug 2024 01:39:21 +0200 Subject: [PATCH] update readme --- README.md | 90 ++++++++++++++++++++++++++++++-------- src/main.rs | 2 +- src/modules/temperature.rs | 11 +++-- 3 files changed, 79 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 405184c..1db3976 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,18 @@ ## baru -A system monitor written in Rust and C. +A simple system monitor for WM statusbars ![baru](https://raw.githubusercontent.com/doums/baru/master/public/baru.png) +Baru is a lightweight system monitor for WM status-bars.\ +It can be used as a provider with any status-bar that can read from `stdout`.\ +Like [xmobar](https://codeberg.org/xmobar/xmobar), +[lemonbar](https://github.com/LemonBoy/bar), +[dwm](https://dwm.suckless.org/status_monitor/) etc… + +--- + - [features](#features) - [prerequisite](#prerequisite) - [install](#install) @@ -29,34 +37,34 @@ A system monitor written in Rust and C. * customizable format output * configuration in YAML -Baru gathers the information from `/sys` and `/proc` filesystems (filled by the kernel). Except audio and network modules which use C libraries.\ -There is no memory leak over time. All modules are threaded. Thanks to this design (as well Rust and C), baru is lightweight and efficient. It can run at high refresh rate with a minimal processor footprint. - -The audio module communicates with the [PipeWire](https://pipewire.org/)/[PulseAudio](https://www.freedesktop.org/wiki/Software/PulseAudio/) server through [client API](https://freedesktop.org/software/pulseaudio/doxygen/) to retrieve its data.\ -Wireless and wired modules use the netlink interface with the help of [libnl](https://www.infradead.org/~tgr/libnl/) to talk directly to kernel and retrieve their data.\ -In addition, wireless module uses the [802.11](https://github.com/torvalds/linux/blob/master/include/uapi/linux/nl80211.h) API. - -Baru is modular. This means that only the modules you want to see are instantiated and executed. - ### prerequisite +The following system libraries are required: + - libnl (for wired and wireless modules) - libpulse (for sound and mic modules) ### install -Rust is a language that compiles to native code and by default statically links all dependencies.\ -Simply download the latest [release](https://github.com/doums/baru/releases) of the compiled binary and use it (do not forget to make it executable `chmod +x baru`). - -For Arch Linux users, baru is present as a [package](https://aur.archlinux.org/packages/baru) in the Arch User Repository. +- Arch Linux (AUR) [package](https://aur.archlinux.org/packages/baru) +- latest [release](https://github.com/doums/baru/releases) ### configuration -The binary looks for the config file `baru.yaml` located in `$XDG_CONFIG_HOME/baru/` (default to `$HOME/.config/baru/`).\ +The binary looks for the config file `baru.yaml` located +in `$XDG_CONFIG_HOME/baru/` (default to `$HOME/.config/baru/`).\ If the config file is not found, baru prints an error and exits.\ -All options are detailed [here](https://github.com/doums/baru/blob/master/baru.yaml). +All options are +detailed [here](https://github.com/doums/baru/blob/master/baru.yaml). + +TIPS: To test and debug your config run baru from the terminal like this: + +```shell +RUST_LOG=debug baru -l stdout +``` + +#### Config example -Example: ```yaml format: '%m %f %c %t %b %i %s %w%e %a %d' tick: 50 @@ -114,13 +122,57 @@ wireless: ``` ### usage + +```shell +baru -h +``` + +When spawning baru from your WM/status-bar you can pass the `-l file` flag\ +if you want baru to log into a file (useful for debugging).\ +Logs are written to the directory `$XDG_CACHE_HOME/baru/` (default to `$HOME/.cache/baru/`). + +```shell +baru -l file ``` -$ baru + +### implementation details + +Baru gathers the information from `/sys` and `/proc` filesystems\ +(filled by the kernel). Except audio and network modules which use C libraries.\ +All modules are threaded and loaded on-demand.\ +Thanks to this modular design (as well Rust and C), baru is lightweight and +efficient.\ +It can run at high refresh rate with a minimal cpu footprint. + +The audio module communicates with +the [PipeWire](https://pipewire.org/)/[PulseAudio](https://www.freedesktop.org/wiki/Software/PulseAudio/)\ +server +through [client API](https://freedesktop.org/software/pulseaudio/doxygen/) to +retrieve its data. Wireless and wired\ +modules use the netlink interface with the help +of [libnl](https://www.infradead.org/~tgr/libnl/) to talk directly\ +to kernel and retrieve their data.\ +In addition, wireless module uses +the [802.11](https://github.com/torvalds/linux/blob/master/include/uapi/linux/nl80211.h) +API. + +### dev + +#### prerequisites + +- [Rust](https://www.rust-lang.org/tools/install) +- CMake +- libnl and libpulse present on the system + +```shell +RUST_LOG=trace cargo run -- -l stdout ``` ### credits -Clément Dommerc for providing me with the C code for the lib `netlink`, wireless part. +Clément Dommerc for providing me with the C code for the lib `netlink`, wireless +part. ### license + Mozilla Public License 2.0 diff --git a/src/main.rs b/src/main.rs index dab2020..ef62d81 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ const TICK_RATE: Duration = Duration::from_millis(50); fn main() -> Result<()> { let cli = Cli::parse(); - trace::init(cli.logs).context("failed to init tracing")?; + let _g = trace::init(cli.logs).context("failed to init tracing")?; let home = env::var("HOME")?; let mut config_dir = env::var(XDG_CONFIG_HOME) diff --git a/src/modules/temperature.rs b/src/modules/temperature.rs index 88e9b15..2dd423c 100644 --- a/src/modules/temperature.rs +++ b/src/modules/temperature.rs @@ -13,7 +13,7 @@ use std::sync::mpsc::Sender; use std::thread; use std::time::{Duration, Instant}; use std::{fs, io}; -use tracing::{debug, instrument}; +use tracing::{debug, instrument, warn}; const PLACEHOLDER: &str = "-"; const CORETEMP: &str = "/sys/devices/platform/coretemp.0/hwmon"; @@ -67,11 +67,12 @@ impl<'a> Default for InternalConfig<'a> { } } +#[instrument] fn check_input_file(path: &str, n: u32) -> bool { fs::metadata(format!("{path}/temp{n}_input")) .map(|m| m.is_file()) .inspect_err(|_e| { - // TODO log error + warn!("input file not found: temp{n}_input"); }) .unwrap_or(false) } @@ -81,6 +82,7 @@ fn check_dir(path: &str) -> Result { Ok(meta.is_dir()) } +#[instrument] fn get_inputs(core_inputs: &CoreInputs, temp_dir: &str) -> Option> { let re = Regex::new(r"^(\d+)\.\.(\d+)$").unwrap(); @@ -97,7 +99,7 @@ fn get_inputs(core_inputs: &CoreInputs, temp_dir: &str) -> Option> { let start = captured.get(1).unwrap().as_str().parse::().unwrap(); let end = captured.get(2).unwrap().as_str().parse::().unwrap(); if (start..end).is_empty() { - // TODO log error on wrong range values + warn!("invalid range: start must be less than end"); return None; } let inputs = (start..end + 1) @@ -105,7 +107,7 @@ fn get_inputs(core_inputs: &CoreInputs, temp_dir: &str) -> Option> { .collect(); return Some(inputs); } - // TODO log error wrong range format + warn!("invalid range format: expected \"start..end\""); None } CoreInputs::List(list) => Some( @@ -139,6 +141,7 @@ impl<'a> TryFrom<&'a MainConfig> for InternalConfig<'a> { .and_then(|i| get_inputs(i, &temp_dir)) .map(|mut i| { if i.is_empty() { + warn!("no input files found, using default input {}", INPUT); i.push(INPUT); } i