Added option for lin/log scale (not yet accessible)
Added ability to specify fixed maximum for bandwidth scale.
This commit is contained in:
2
iftop.h
2
iftop.h
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
/* 60 / 3 */
|
/* 40 / 2 */
|
||||||
#define HISTORY_LENGTH 20
|
#define HISTORY_LENGTH 20
|
||||||
#define RESOLUTION 2
|
#define RESOLUTION 2
|
||||||
|
|
||||||
|
|||||||
38
options.c
38
options.c
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
options_t options;
|
options_t options;
|
||||||
|
|
||||||
char optstr[] = "+i:f:nN:hpbBP";
|
char optstr[] = "+i:f:nN:hpbBPm:";
|
||||||
|
|
||||||
/* Global options. */
|
/* Global options. */
|
||||||
|
|
||||||
@@ -112,6 +112,8 @@ static void set_defaults() {
|
|||||||
options.linedisplay = OPTION_LINEDISPLAY_TWO_LINE;
|
options.linedisplay = OPTION_LINEDISPLAY_TWO_LINE;
|
||||||
options.screen_offset = 0;
|
options.screen_offset = 0;
|
||||||
options.show_totals = 0;
|
options.show_totals = 0;
|
||||||
|
options.max_bandwidth = 0; /* auto */
|
||||||
|
options.log_scale = 1; /* auto */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void die(char *msg) {
|
static void die(char *msg) {
|
||||||
@@ -119,6 +121,32 @@ static void die(char *msg) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void set_max_bandwidth(char* arg) {
|
||||||
|
char* units;
|
||||||
|
long long mult = 1;
|
||||||
|
long long value;
|
||||||
|
units = arg + strspn(arg, "0123456789");
|
||||||
|
if(strlen(units) > 1) {
|
||||||
|
die("Invalid units\n");
|
||||||
|
}
|
||||||
|
if(strlen(units) == 1) {
|
||||||
|
if(*units == 'k' || *units == 'K') {
|
||||||
|
mult = 1024;
|
||||||
|
}
|
||||||
|
else if(*units == 'm' || *units == 'M') {
|
||||||
|
mult = 1024 * 1024;
|
||||||
|
}
|
||||||
|
else if(*units == 'g' || *units == 'G') {
|
||||||
|
mult = 1024 * 1024 * 1024;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*units = '\0';
|
||||||
|
if(sscanf(arg, "%lld", &value) != 1) {
|
||||||
|
die("Error reading max bandwidth\n");
|
||||||
|
}
|
||||||
|
options.max_bandwidth = value * mult;
|
||||||
|
}
|
||||||
|
|
||||||
static void set_net_filter(char* arg) {
|
static void set_net_filter(char* arg) {
|
||||||
char* mask;
|
char* mask;
|
||||||
|
|
||||||
@@ -180,6 +208,7 @@ static void usage(FILE *fp) {
|
|||||||
" (default: none, but only IP packets are counted)\n"
|
" (default: none, but only IP packets are counted)\n"
|
||||||
" -N net/mask show traffic flows in/out of network\n"
|
" -N net/mask show traffic flows in/out of network\n"
|
||||||
" -P show ports as well as hosts\n"
|
" -P show ports as well as hosts\n"
|
||||||
|
" -m limit sets the upper limit for the bandwidth scale\n"
|
||||||
"\n"
|
"\n"
|
||||||
"iftop, version " IFTOP_VERSION "\n"
|
"iftop, version " IFTOP_VERSION "\n"
|
||||||
"copyright (c) 2002 Paul Warren <pdw@ex-parrot.com> and contributors\n"
|
"copyright (c) 2002 Paul Warren <pdw@ex-parrot.com> and contributors\n"
|
||||||
@@ -212,7 +241,7 @@ void options_read(int argc, char **argv) {
|
|||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
options.promiscuous = 1;
|
options.promiscuous = 1;
|
||||||
options.promiscuous_but_choosy = 0;
|
options.promiscuous_but_choosy = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'P':
|
case 'P':
|
||||||
@@ -222,6 +251,11 @@ void options_read(int argc, char **argv) {
|
|||||||
case 'N':
|
case 'N':
|
||||||
set_net_filter(optarg);
|
set_net_filter(optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'm':
|
||||||
|
set_max_bandwidth(optarg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
case 'b':
|
case 'b':
|
||||||
options.showbars = 0;
|
options.showbars = 0;
|
||||||
|
|||||||
@@ -66,6 +66,9 @@ typedef struct {
|
|||||||
|
|
||||||
int show_totals;
|
int show_totals;
|
||||||
|
|
||||||
|
long long max_bandwidth;
|
||||||
|
int log_scale;
|
||||||
|
|
||||||
} options_t;
|
} options_t;
|
||||||
|
|
||||||
#endif /* __OPTIONS_H_ */
|
#endif /* __OPTIONS_H_ */
|
||||||
|
|||||||
65
ui.c
65
ui.c
@@ -202,6 +202,25 @@ static struct {
|
|||||||
};
|
};
|
||||||
static int rateidx = 0, wantbiggerrate;
|
static int rateidx = 0, wantbiggerrate;
|
||||||
|
|
||||||
|
static int get_bar_interval(float bandwidth) {
|
||||||
|
int i = 10;
|
||||||
|
if(bandwidth > 100000000) {
|
||||||
|
i = 100;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
static float get_max_bandwidth() {
|
||||||
|
float max;
|
||||||
|
if(options.max_bandwidth > 0) {
|
||||||
|
max = options.max_bandwidth;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
max = scale[rateidx].max;
|
||||||
|
}
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
/* rate in bits */
|
/* rate in bits */
|
||||||
static int get_bar_length(const int rate) {
|
static int get_bar_length(const int rate) {
|
||||||
float l;
|
float l;
|
||||||
@@ -209,28 +228,56 @@ static int get_bar_length(const int rate) {
|
|||||||
return 0;
|
return 0;
|
||||||
if (rate > scale[rateidx].max)
|
if (rate > scale[rateidx].max)
|
||||||
wantbiggerrate = 1;
|
wantbiggerrate = 1;
|
||||||
l = log(rate) / log(scale[rateidx].max);
|
if(options.log_scale) {
|
||||||
|
l = log(rate) / log(get_max_bandwidth());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
l = rate / get_max_bandwidth();
|
||||||
|
}
|
||||||
return (l * COLS);
|
return (l * COLS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw_bar_scale(int* y) {
|
static void draw_bar_scale(int* y) {
|
||||||
float i;
|
float i;
|
||||||
|
float max,interval;
|
||||||
|
max = get_max_bandwidth();
|
||||||
|
interval = get_bar_interval(max);
|
||||||
if(options.showbars) {
|
if(options.showbars) {
|
||||||
|
float stop;
|
||||||
/* Draw bar graph scale on top of the window. */
|
/* Draw bar graph scale on top of the window. */
|
||||||
move(*y, 0);
|
move(*y, 0);
|
||||||
clrtoeol();
|
clrtoeol();
|
||||||
mvhline(*y + 1, 0, 0, COLS);
|
mvhline(*y + 1, 0, 0, COLS);
|
||||||
/* i in bytes */
|
/* i in bytes */
|
||||||
for (i = 1.25; i * 8 <= scale[rateidx].max; i *= scale[rateidx].interval) {
|
|
||||||
|
if(options.log_scale) {
|
||||||
|
i = 1.25;
|
||||||
|
stop = max / 8;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
i = max / (5 * 8);
|
||||||
|
stop = max / 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* for (i = 1.25; i * 8 <= max; i *= interval) { */
|
||||||
|
while(i <= stop) {
|
||||||
char s[40], *p;
|
char s[40], *p;
|
||||||
int x;
|
int x;
|
||||||
readable_size(i, s, sizeof s, 1000, 0);
|
/* This 1024 vs 1000 stuff is just plain evil */
|
||||||
|
readable_size(i, s, sizeof s, options.log_scale ? 1000 : 1024, 0);
|
||||||
p = s + strspn(s, " ");
|
p = s + strspn(s, " ");
|
||||||
x = get_bar_length(i * 8);
|
x = get_bar_length(i * 8);
|
||||||
mvaddch(*y + 1, x, ACS_BTEE);
|
mvaddch(*y + 1, x, ACS_BTEE);
|
||||||
if (x + strlen(p) >= COLS)
|
if (x + strlen(p) >= COLS)
|
||||||
x = COLS - strlen(p);
|
x = COLS - strlen(p);
|
||||||
mvaddstr(*y, x, p);
|
mvaddstr(*y, x, p);
|
||||||
|
|
||||||
|
if(options.log_scale) {
|
||||||
|
i *= interval;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
i += max / (5 * 8);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mvaddch(*y + 1, 0, ACS_LLCORNER);
|
mvaddch(*y + 1, 0, ACS_LLCORNER);
|
||||||
*y += 2;
|
*y += 2;
|
||||||
@@ -273,11 +320,11 @@ void draw_line_total(float sent, float recv, int y, int x, option_linedisplay_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
void draw_bar(float n, int y) {
|
void draw_bar(float n, int y) {
|
||||||
int L;
|
int L;
|
||||||
mvchgat(y, 0, -1, A_NORMAL, 0, NULL);
|
mvchgat(y, 0, -1, A_NORMAL, 0, NULL);
|
||||||
L = get_bar_length(8 * n);
|
L = get_bar_length(8 * n);
|
||||||
if (L > 0)
|
if (L > 0)
|
||||||
mvchgat(y, 0, L + 1, A_REVERSE, 0, NULL);
|
mvchgat(y, 0, L + 1, A_REVERSE, 0, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_line_totals(int y, host_pair_line* line, option_linedisplay_t linedisplay) {
|
void draw_line_totals(int y, host_pair_line* line, option_linedisplay_t linedisplay) {
|
||||||
@@ -677,7 +724,7 @@ void ui_print() {
|
|||||||
refresh();
|
refresh();
|
||||||
|
|
||||||
/* Bar chart auto scale */
|
/* Bar chart auto scale */
|
||||||
if (wantbiggerrate) {
|
if (wantbiggerrate && options.max_bandwidth == 0) {
|
||||||
++rateidx;
|
++rateidx;
|
||||||
wantbiggerrate = 0;
|
wantbiggerrate = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user