Skip to content

Commit

Permalink
update clap
Browse files Browse the repository at this point in the history
  • Loading branch information
magiclen committed Nov 14, 2023
1 parent f89fdd7 commit a48b426
Show file tree
Hide file tree
Showing 26 changed files with 3,101 additions and 3,316 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
os:
- ubuntu-latest
toolchain:
- 1.69
- "1.70"
target:
- x86_64-unknown-linux-gnu
- x86_64-unknown-linux-musl
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
os:
- ubuntu-latest
toolchain:
- 1.69
- "1.70"
target:
- x86_64-unknown-linux-gnu
- x86_64-unknown-linux-musl
Expand Down
17 changes: 10 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "mprober"
version = "0.11.0-beta.14"
version = "0.11.0-beta.15"
authors = ["Magic Len <len@magiclen.org>"]
edition = "2021"
rust-version = "1.69"
rust-version = "1.70"
repository = "https://github.com/magiclen/m-prober"
homepage = "https://magiclen.org/m-prober"
keywords = ["probe", "mprober", "m-prober", "linux", "monitor"]
Expand All @@ -18,15 +18,18 @@ codegen-units = 1
strip = true

[dependencies]
mprober-lib = "0.1"

clap = "3.2.23"
clap = { version = "4", features = ["derive"] }
concat-with = "0.2"
terminal_size = "0.2"
terminal_size = "0.3"

anyhow = "1"

mprober-lib = "0.1"

byte-unit = "4"
termcolor = "1"
getch = "0.3"

byte-unit = "4"
once_cell = "1"

rand = "0.8"
Expand Down
155 changes: 77 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,84 +9,83 @@ This program aims to collect Linux system information including hostname, kernel

```
EXAMPLES:
mprober hostname # Show the hostname
mprober kernel # Show the kernel version
mprober uptime # Show the uptime
mprober uptime -m # Show the uptime and refresh every second
mprober uptime -p # Show the uptime without colors
mprober uptime -l # Show the uptime with darker colors (fitting in with light themes)
mprober uptime -s # Show the uptime in seconds
mprober time # Show the RTC (UTC) date and time
mprober time -m # Show the RTC (UTC) date and time and refresh every second
mprober time -p # Show the RTC (UTC) date and time without colors
mprober time -l # Show the RTC (UTC) date and time with darker colors (fitting in with light themes)
mprober cpu # Show load average and current CPU stats on average
mprober cpu -m 1000 # Show load average and CPU stats on average and refresh every 1000 milliseconds
mprober cpu -p # Show load average and current CPU stats on average without colors
mprober cpu -l # Show load average and current CPU stats on average with darker colors (fitting in with light themes)
mprober cpu -s # Show load average and current stats of CPU cores separately
mprober cpu -i # Only show CPU information
mprober memory # Show current memory stats
mprober memory -m 1000 # Show memory stats and refresh every 1000 milliseconds
mprober memory -p # Show current memory stats without colors
mprober memory -l # Show current memory stats with darker colors (fitting in with light themes)
mprober memory -u kb # Show current memory stats in KB
mprober network # Show current network stats
mprober network -m 1000 # Show network stats and refresh every 1000 milliseconds
mprober network -p # Show current network stats without colors
mprober network -l # Show current network stats with darker colors (fitting in with light themes)
mprober network -u kb # Show current network stats in KB
mprober volume # Show current volume stats
mprober volume -m 1000 # Show current volume stats and refresh every 1000 milliseconds
mprober volume -p # Show current volume stats without colors
mprober volume -l # Show current volume stats without colors
mprober volume -u kb # Show current volume stats in KB
mprober volume -i # Only show volume information without I/O rates
mprober volume --mounts # Show current volume stats including mount points
mprober process # Show a snapshot of the current processes
mprober process -m 1000 # Show a snapshot of the current processes and refresh every 1000 milliseconds
mprober process -p # Show a snapshot of the current processes without colors
mprober process -l # Show a snapshot of the current processes with darker colors (fitting in with light themes)
mprober process -i # Show a snapshot of the current processes but not including CPU usage
mprober process -u kb # Show a snapshot of the current processes. Information about memory size is in KB
mprober process --truncate 10 # Show a snapshot of the current processes with a specific truncation length to truncate user, group, program's names
mprober process --top 10 # Show a snapshot of current top-10 (ordered by CPU and memory usage) processes
mprober process -t # Show a snapshot of the current processes with the start time of each process
mprober process --pid-filter 3456 # Show a snapshot of the current processes which are related to a specific PID
mprober process --user-filter user1 # Show a snapshot of the current processes which are related to a specific user
mprober process --group-filter gp1 # Show a snapshot of the current processes which are related to a specific group
mprober process --tty-filter tty # Show a snapshot of the current processes which are related to specific tty names matched by a regex
mprober process --program-filter ab # Show a snapshot of the current processes which are related to specific program names or commands matched by a regex
mprober web # Start a HTTP service on port 8000 to monitor this computer. The default time interval is 3 seconds
mprober web -m 2 # Start a HTTP service on port 8000 to monitor this computer. The time interval is set to 2 seconds
mprober web -p 7777 # Start a HTTP service on port 7777 to monitor this computer
mprober web --addr 127.0.0.1 # Start a HTTP service on 127.0.0.1:8000 to monitor this computer
mprober web -a auth_key # Start a HTTP service on port 8000 to monitor this computer. APIs need to be invoked with an auth key
mprober web --only-api # Start a HTTP service on port 8000 to serve only HTTP APIs
mprober benchmark # Run benchmarks
mprober benchmark --disable-cpu # Run benchmarks except for benchmarking CPU
mprober benchmark --enable-memory # Benchmark the memory
USAGE:
mprober [SUBCOMMAND]
OPTIONS:
-h, --help Print help information
-V, --version Print version information
SUBCOMMANDS:
hostname Show the hostname
kernel Show the kernel version
uptime Show the uptime
time Show the RTC (UTC) date and time
cpu Show CPU stats
memory Show memory stats
network Show network stats
volume Show volume stats
process Show process stats
web Start a HTTP service to monitor this computer
benchmark Run benchmarks to measure the performance of this environment
help Print this message or the help of the given subcommand(s)
mprober hostname # Show the hostname
mprober kernel # Show the kernel version
mprober uptime # Show the uptime
mprober uptime -m # Show the uptime and refresh every second
mprober uptime -p # Show the uptime without colors
mprober uptime -l # Show the uptime with darker colors (fitting in with light themes)
mprober uptime -s # Show the uptime in seconds
mprober time # Show the RTC (UTC) date and time
mprober time -m # Show the RTC (UTC) date and time and refresh every second
mprober time -p # Show the RTC (UTC) date and time without colors
mprober time -l # Show the RTC (UTC) date and time with darker colors (fitting in with light themes)
mprober cpu # Show load average and current CPU stats on average
mprober cpu -m 1000 # Show load average and CPU stats on average and refresh every 1000 milliseconds
mprober cpu -p # Show load average and current CPU stats on average without colors
mprober cpu -l # Show load average and current CPU stats on average with darker colors (fitting in with light themes)
mprober cpu -s # Show load average and current stats of CPU cores separately
mprober cpu -i # Only show CPU information
mprober memory # Show current memory stats
mprober memory -m 1000 # Show memory stats and refresh every 1000 milliseconds
mprober memory -p # Show current memory stats without colors
mprober memory -l # Show current memory stats with darker colors (fitting in with light themes)
mprober memory -u kb # Show current memory stats in KB
mprober network # Show current network stats
mprober network -m 1000 # Show network stats and refresh every 1000 milliseconds
mprober network -p # Show current network stats without colors
mprober network -l # Show current network stats with darker colors (fitting in with light themes)
mprober network -u kb # Show current network stats in KB
mprober volume # Show current volume stats
mprober volume -m 1000 # Show current volume stats and refresh every 1000 milliseconds
mprober volume -p # Show current volume stats without colors
mprober volume -l # Show current volume stats without colors
mprober volume -u kb # Show current volume stats in KB
mprober volume -i # Only show volume information without I/O rates
mprober volume --mounts # Show current volume stats including mount points
mprober process # Show a snapshot of the current processes
mprober process -m 1000 # Show a snapshot of the current processes and refresh every 1000 milliseconds
mprober process -p # Show a snapshot of the current processes without colors
mprober process -l # Show a snapshot of the current processes with darker colors (fitting in with light themes)
mprober process -i # Show a snapshot of the current processes but not including CPU usage
mprober process -u kb # Show a snapshot of the current processes. Information about memory size is in KB
mprober process --truncate 10 # Show a snapshot of the current processes with a specific truncation length to truncate user, group, program's names
mprober process --top 10 # Show a snapshot of current top-10 (ordered by CPU and memory usage) processes
mprober process -t # Show a snapshot of the current processes with the start time of each process
mprober process --pid-filter 3456 # Show a snapshot of the current processes which are related to a specific PID
mprober process --user-filter user1 # Show a snapshot of the current processes which are related to a specific user
mprober process --group-filter gp1 # Show a snapshot of the current processes which are related to a specific group
mprober process --tty-filter tty # Show a snapshot of the current processes which are related to specific tty names matched by a regex
mprober process --program-filter ab # Show a snapshot of the current processes which are related to specific program names or commands matched by a regex
mprober web # Start a HTTP service on port 8000 to monitor this computer. The default time interval is 3 seconds
mprober web -m 2 # Start a HTTP service on port 8000 to monitor this computer. The time interval is set to 2 seconds
mprober web -p 7777 # Start a HTTP service on port 7777 to monitor this computer
mprober web --addr 127.0.0.1 # Start a HTTP service on 127.0.0.1:8000 to monitor this computer
mprober web -a auth_key # Start a HTTP service on port 8000 to monitor this computer. APIs need to be invoked with an auth key
mprober web --only-api # Start a HTTP service on port 8000 to serve only HTTP APIs
mprober benchmark # Run benchmarks
mprober benchmark --disable-cpu # Run benchmarks except for benchmarking CPU
mprober benchmark --enable-memory # Benchmark the memory
Usage: mprober <COMMAND>
Commands:
hostname Show the hostname
kernel Show the kernel version
uptime Show the uptime
time Show the RTC (UTC) date and time
cpu Show CPU stats
memory Show memory stats
network Show network stats
volume Show volume stats
process Show process stats
web Start a HTTP service to monitor this computer
benchmark Run benchmarks to measure the performance of this environment
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
```

## Requirements
Expand Down
10 changes: 6 additions & 4 deletions src/benchmark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use rand::{self, Rng};

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum BenchmarkLog {
#[allow(unused)]
None,
Normal,
Verbose,
Expand Down Expand Up @@ -46,6 +47,7 @@ impl BenchmarkLog {
#[derive(Debug)]
pub enum BenchmarkError {
ScannerError(ScannerError),
#[allow(clippy::enum_variant_names)]
BenchmarkError(benchmarking::BenchmarkError),
IOError(io::Error),
NoNeedBenchmark,
Expand Down Expand Up @@ -195,7 +197,7 @@ pub fn run_benchmark(config: &BenchmarkConfig) -> Result<BenchmarkResult, Benchm
cpu_multi_thread = Some(speed);

if config.print_out.has_stdout() {
println!("CPU (multi-thread) : {:.2} iterations/s", speed);
println!("CPU (multi-thread) : {speed:.2} iterations/s");

if config.print_out.has_stderr() {
eprintln!();
Expand Down Expand Up @@ -241,7 +243,7 @@ pub fn run_benchmark(config: &BenchmarkConfig) -> Result<BenchmarkResult, Benchm
cpu_single_thread = Some(speed);

if config.print_out.has_stdout() {
println!("CPU (single thread): {:.2} iterations/s", speed);
println!("CPU (single thread): {speed:.2} iterations/s");
}
}
}
Expand Down Expand Up @@ -298,7 +300,7 @@ pub fn run_benchmark(config: &BenchmarkConfig) -> Result<BenchmarkResult, Benchm
.get_appropriate_unit(true)
.to_string();

println!("Memory : {}/s", memory_result);
println!("Memory : {memory_result}/s");
}
}
}
Expand Down Expand Up @@ -538,7 +540,7 @@ pub fn run_benchmark(config: &BenchmarkConfig) -> Result<BenchmarkResult, Benchm
s.push(' ');
}

println!("{}: Read {}/s, Write {}/s", s, read_result_string, write_result_string);
println!("{s}: Read {read_result_string}/s, Write {write_result_string}/s");

unsafe {
s.as_mut_vec()
Expand Down
Loading

0 comments on commit a48b426

Please sign in to comment.