Skip to content

Commit

Permalink
Add comprehensive testing and improve command-line options handling
Browse files Browse the repository at this point in the history
- Added comprehensive tests for headers, stats, and command-line options
- Corrected handling of positional arguments for delay and count
- Improved formatting of network interface statistics output
- Enhanced test coverage to ensure accurate difference and unit conversion
  • Loading branch information
spezifisch committed Jul 27, 2024
1 parent 6f84862 commit 9b40541
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ifstat-rs

`ifstat-rs` is a simple Rust tool to parse and display network I/O statistics from `/proc/net/dev` once a second.
`ifstat-rs` is a simple Rust tool to parse and display network I/O statistics from `/proc/net/dev` once a second.

*"This project has been generated with the assistance of ChatGPT. Please be aware that ChatGPT can make mistakes. It is important to review and verify all information provided by the tool." is what it says. Don't use this tool.*

Expand All @@ -10,6 +10,7 @@
- Displays RX and TX bytes for each interface every second
- Supports monitoring specific interfaces, all interfaces, or loopback interfaces
- Allows setting delay between updates and limiting the number of updates
- Displays detailed build information including commit hash and build timestamp

## Installation

Expand All @@ -32,33 +33,34 @@ cargo run --release
- `-a`: Monitor all interfaces
- `-l`: Include loopback interfaces
- `-i <interfaces>`: Specify interfaces to monitor, separated by commas (e.g., `-i eth0,lo`)
- `--delay <seconds>`: Set delay between updates (default is 1 second)
- `--first-measurement <seconds>`: Set delay before the first measurement (default is same as --delay)
- `<delay>`: Delay between updates in seconds (default is 1 second)
- `<count>`: Number of updates before stopping (default is unlimited)

### Examples

Monitor specific interfaces:

```sh
cargo run --release -- -i eth0,lo
cargo run --release -- -i eth0,lo 1 10
```

Monitor all interfaces:

```sh
cargo run --release -- -a
cargo run --release -- -a 1 10
```

Include loopback interfaces:

```sh
cargo run --release -- -l
cargo run --release -- -l 1 10
```

Specify delay and count:

```sh
cargo run --release -- -a --delay 0.5 10
cargo run --release -- -a --first-measurement 0.5 1 10
```

## Contributing
Expand Down
6 changes: 3 additions & 3 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ fn test_command_line_options() {
"lo,eth0",
"--first-measurement",
"0.5",
"--delay=1.0",
"--count=10",
"1.0",
"10",
]).unwrap();
assert_eq!(opts.interfaces.unwrap(), "lo,eth0");
assert_eq!(opts.first_measurement.unwrap(), 0.5);
assert_eq!(opts.delay, 1.0);
assert_eq!(opts.count.unwrap(), 10);
}
}

0 comments on commit 9b40541

Please sign in to comment.