Option to display packet counts - Frédéric Perrin <fperrin@brocade.com>

Add a "-u unit" CLI option, as well as a "bandwidth-unit" configuration
file option. With "-u packets", traffic is accounted using packets per
second; the other options are "-u bits" and "-u bytes".

"-B" is still recognized as synonym to "-u bytes".

The default is "-u bits", keeping the current behaviour of iftop
(everything is in bits/s, except the cumulative totals).
This commit is contained in:
Paul Warren
2017-01-04 23:03:34 +00:00
parent eb087b0c83
commit 9addd978c4
9 changed files with 112 additions and 47 deletions

16
tui.c
View File

@@ -87,7 +87,7 @@ void tui_print() {
/* Send rate per connection */
printf("%4d %s%s", l, host1, " =>");
for(j = 0; j < HISTORY_DIVISIONS; j++) {
readable_size(screen_line->sent[j], buf0_10, 10, 1024, options.bandwidth_in_bytes);
readable_size(screen_line->sent[j], buf0_10, 10, 1024, options.bandwidth_unit);
printf(" %10s", buf0_10);
}
/* Cumulative sent data per connection */
@@ -97,7 +97,7 @@ void tui_print() {
/* Receive rate per connection */
printf(" %s%s", host2, " <=");
for(j = 0; j < HISTORY_DIVISIONS; j++) {
readable_size(screen_line->recv[j], buf0_10, 10, 1024, options.bandwidth_in_bytes);
readable_size(screen_line->recv[j], buf0_10, 10, 1024, options.bandwidth_unit);
printf(" %10s", buf0_10);
}
/* Cumulative received data per connection */
@@ -115,21 +115,21 @@ void tui_print() {
snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Total send rate:");
printf("%s ", labellong);
for(j = 0; j < HISTORY_DIVISIONS; j++) {
readable_size((((host_pair_line *)&totals)->sent[j]) , buf0_10, 10, 1024, options.bandwidth_in_bytes);
readable_size(((host_pair_line *)&totals)->sent[j], buf0_10, 10, 1024, options.bandwidth_unit);
printf("%10s%c", buf0_10, j == HISTORY_DIVISIONS - 1 ? '\n' : ' ');
}
snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Total receive rate:");
printf("%s ", labellong);
for(j = 0; j < HISTORY_DIVISIONS; j++) {
readable_size((((host_pair_line *)&totals)->recv[j]) , buf0_10, 10, 1024, options.bandwidth_in_bytes);
readable_size(((host_pair_line *)&totals)->recv[j], buf0_10, 10, 1024, options.bandwidth_unit);
printf("%10s%c", buf0_10, j == HISTORY_DIVISIONS - 1 ? '\n' : ' ');
}
snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Total send and receive rate:");
printf("%s ", labellong);
for(j = 0; j < HISTORY_DIVISIONS; j++) {
readable_size((((host_pair_line *)&totals)->sent[j] + ((host_pair_line *)&totals)->recv[j]) , buf0_10, 10, 1024, options.bandwidth_in_bytes);
readable_size(((host_pair_line *)&totals)->sent[j] + ((host_pair_line *)&totals)->recv[j], buf0_10, 10, 1024, options.bandwidth_unit);
printf("%10s%c", buf0_10, j == HISTORY_DIVISIONS - 1 ? '\n' : ' ');
}
@@ -141,9 +141,9 @@ void tui_print() {
/* Peak traffic */
snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Peak rate (sent/received/total):");
readable_size(peaksent / RESOLUTION, buf0_10, 10, 1024, options.bandwidth_in_bytes);
readable_size(peakrecv / RESOLUTION, buf1_10, 10, 1024, options.bandwidth_in_bytes);
readable_size(peaktotal / RESOLUTION, buf2_10, 10, 1024, options.bandwidth_in_bytes);
readable_size(peaksent / RESOLUTION, buf0_10, 10, 1024, options.bandwidth_unit);
readable_size(peakrecv / RESOLUTION, buf1_10, 10, 1024, options.bandwidth_unit);
readable_size(peaktotal / RESOLUTION, buf2_10, 10, 1024, options.bandwidth_unit);
printf("%s %10s %10s %10s\n", labellong, buf0_10, buf1_10, buf2_10);
/* Cumulative totals */