Allow setting interval with opts
This commit is contained in:
parent
b3aa5fe786
commit
4136d82aed
|
@ -8,8 +8,9 @@ It simply reads from `/proc/net/dev` to obtain byte-counts of the specified
|
|||
network interface and writes to four files, two of which keep track of the total
|
||||
byte count for sending and receiving, and the other two contain the "diffs" for
|
||||
each (configurable) interval (by default 5 seconds).
|
||||
rust_network_status_rate 0.1.0
|
||||
|
||||
rust_network_status_rate 0.1.0
|
||||
|
||||
USAGE:
|
||||
rust_network_status_rate [FLAGS] [OPTIONS] <net-dev>
|
||||
|
||||
|
@ -21,6 +22,8 @@ rust_network_status_rate 0.1.0
|
|||
|
||||
OPTIONS:
|
||||
-p, --prefix <alternate-prefix-dir> Prefix to use instead of XDG_RUNTIME_DIR if enabled [default: /tmp]
|
||||
-v, --interval-seconds <interval-seconds> Interval in seconds between checking network rate [default: 5]
|
||||
-i, --pid-filename <pid-filename> Filename to write pid to [default: rust_network_rate_pid]
|
||||
-r, --recv-interval <recv-interval-filename>
|
||||
Filename of interval bytes recieved (in prefix dir) [default: rust_recv_interval]
|
||||
|
||||
|
@ -35,4 +38,4 @@ rust_network_status_rate 0.1.0
|
|||
|
||||
|
||||
ARGS:
|
||||
<net-dev>
|
||||
<net-dev>
|
||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -7,8 +7,6 @@ use std::thread::sleep;
|
|||
use std::time::{Duration, Instant};
|
||||
use structopt::StructOpt;
|
||||
|
||||
const INTERVAL_SECONDS: u64 = 5;
|
||||
|
||||
const ALTERNATE_PREFIX_DIR: &str = "/tmp";
|
||||
|
||||
const DEFAULT_SEND_TOTAL_FILENAME: &str = "rust_send_total";
|
||||
|
@ -76,6 +74,14 @@ struct Opt {
|
|||
default_value = DEFAULT_PID_FILENAME
|
||||
)]
|
||||
pid_filename: String,
|
||||
|
||||
#[structopt(
|
||||
short = "v",
|
||||
long = "interval-seconds",
|
||||
help = "Interval in seconds between checking network rate",
|
||||
default_value = "5"
|
||||
)]
|
||||
interval_seconds: u64,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
|
@ -357,7 +363,7 @@ fn main() -> Result<(), String> {
|
|||
&recv_total_path,
|
||||
)
|
||||
},
|
||||
INTERVAL_SECONDS,
|
||||
opt.interval_seconds,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in New Issue