Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
doums committed Aug 19, 2024
1 parent d2d6825 commit 1b34a0c
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 24 deletions.
90 changes: 71 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -29,35 +37,35 @@ 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
```

Example:
```yaml
# Config example

format: '%m %f %c %t %b %i %s %w%e %a %d'
tick: 50
battery:
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions src/modules/temperature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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)
}
Expand All @@ -81,6 +82,7 @@ fn check_dir(path: &str) -> Result<bool, io::Error> {
Ok(meta.is_dir())
}

#[instrument]
fn get_inputs(core_inputs: &CoreInputs, temp_dir: &str) -> Option<Vec<u32>> {
let re = Regex::new(r"^(\d+)\.\.(\d+)$").unwrap();

Expand All @@ -97,15 +99,15 @@ fn get_inputs(core_inputs: &CoreInputs, temp_dir: &str) -> Option<Vec<u32>> {
let start = captured.get(1).unwrap().as_str().parse::<u32>().unwrap();
let end = captured.get(2).unwrap().as_str().parse::<u32>().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)
.filter(|i| check_input_file(temp_dir, *i))
.collect();
return Some(inputs);
}
// TODO log error wrong range format
warn!("invalid range format: expected \"start..end\"");
None
}
CoreInputs::List(list) => Some(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1b34a0c

Please sign in to comment.