aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCalvin Morrison <cmorrison@holts.com>2016-02-11 10:56:30 -0500
committerCalvin Morrison <cmorrison@holts.com>2016-02-11 10:58:49 -0500
commit67d67ff739e4aebcca94d3c1f2676ac2a598dcca (patch)
tree4858a3395c03be441885fbe0eee81aa7085cfba6
parent38787b9c3111712d92b5b388b71e44900142ffa4 (diff)
FSBM 1.1
added -i flag for specific interfaces added -r flag for raw byte counts update usage
-rw-r--r--README.md9
-rw-r--r--fsbm.c32
2 files changed, 33 insertions, 8 deletions
diff --git a/README.md b/README.md
index 934e916..90f3eff 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,8 @@
-well cbm, the console-bandwidth-monitor was a bit bloated. I don't want ncurses, so what we have here is a stripped down version
+well cbm, the console-bandwidth-monitor was a bit bloated. I don't want
+ncurses, so what we have here is a stripped down version
+
+
+fsbm 1.1
+
+- added -i option so user can specify a single interface
+- added -r option to output raw byte countst
diff --git a/fsbm.c b/fsbm.c
index ada40b8..18fa55c 100644
--- a/fsbm.c
+++ b/fsbm.c
@@ -22,8 +22,12 @@ struct iface {
};
+bool raw = false;
+bool request_name_enabled = false;
volatile bool q = false;
bool use_bits = false;
+char *request_name;
+
struct iface *interfaces = NULL;
size_t no_iface = 0;
@@ -32,11 +36,18 @@ void endHandler(int signum) {
}
void print_bps(double bytesPerSecond) {
- const char* prefixes[] = { "b", "k", "M", "G", "T", "P", "E", "Z", "Y" };
+ const char* prefixes[] = { "", "k", "M", "G", "T", "P", "E", "Z", "Y" };
double value;
const char* unit;
unsigned prefix = 0;
+ if(raw) {
+ if(use_bits)
+ bytesPerSecond *= 8;
+ printf("%.2f", bytesPerSecond);
+ return;
+ }
+
// Calculate the value
if(use_bits) {
value = bytesPerSecond * 8;
@@ -97,15 +108,16 @@ void print_stats() {
}
len = name - buf;
+ if(request_name_enabled && strcmp(name, request_name) != 0) {
+ continue;
+ }
+
// Parse the statistics, alls well, then get this shit going, otherwise f it.
if(sscanf(stats, "%Lu %*u %*u %*u %*u %*u %*u %*u %Lu",
&rx_bytes, &tx_bytes) == 2) {
size_t i = 0;
bool found = false;
- if(interfaces == NULL) {
- goto skip;
- }
for(i = 0; i < no_iface; i++) {
// if it exists in our interfaces, great. reuse the iface struct
if(strcmp(name, interfaces[i].interface) == 0) {
@@ -113,7 +125,6 @@ void print_stats() {
break;
}
}
- skip:
if(found) {
double timeDelta, rx_speed, tx_speed = 0;
@@ -163,7 +174,7 @@ int main(int argc, char **argv) {
int c;
unsigned long long interval = 10 * 100000;
- while ((c = getopt (argc, argv, "bd:hv")) != -1)
+ while ((c = getopt (argc, argv, "rbi:d:hv")) != -1)
switch (c)
{
case 'b':
@@ -175,9 +186,16 @@ int main(int argc, char **argv) {
interval = interval * 100000;
break;
case 'h':
- printf("USAGE: fsbm, -b specifies bits, -d sets interval in 10ths of seconds, 1 sec default\n");
+ printf("USAGE: fsbm, -i shows only matching interface, -r gives raw counts, -b specifies bits, -d sets interval in 10ths of seconds, 1 sec default\n");
exit(EXIT_SUCCESS);
break;
+ case 'i':
+ request_name_enabled = true;
+ request_name = strdup(optarg);
+ break;
+ case 'r':
+ raw = true;
+ break;
case 'v':
printf("Version 1\n");
exit(EXIT_SUCCESS);