Merge patch by muszo
This commit is contained in:
10
Changelog
10
Changelog
@@ -1,5 +1,15 @@
|
|||||||
Changelog
|
Changelog
|
||||||
|
|
||||||
|
12/05/13 (muzso)
|
||||||
|
- added new command line switches:
|
||||||
|
-s Sorts output by the sent column.
|
||||||
|
-c Limits the number of updates (useful for tracemode and scripting the
|
||||||
|
output).
|
||||||
|
-v Sets view mode (0 = KB/s, 1 = total KB, 2 = total B, 3 = total MB)
|
||||||
|
- changed needrefresh default value from true to false
|
||||||
|
(upon startup there's no useful info on network usage, so displaying
|
||||||
|
any results has no use for the user)
|
||||||
|
|
||||||
31/08/10 (Arnout)
|
31/08/10 (Arnout)
|
||||||
- support for screens wider than 80 characters, thanks to Shock
|
- support for screens wider than 80 characters, thanks to Shock
|
||||||
at https://bugs.launchpad.net/ubuntu/+source/nethogs/+bug/627626
|
at https://bugs.launchpad.net/ubuntu/+source/nethogs/+bug/627626
|
||||||
|
|||||||
23
cui.cpp
23
cui.cpp
@@ -43,15 +43,12 @@ extern Process * unknowntcp;
|
|||||||
extern Process * unknownudp;
|
extern Process * unknownudp;
|
||||||
extern Process * unknownip;
|
extern Process * unknownip;
|
||||||
|
|
||||||
// sort on sent or received?
|
extern bool sortRecv;
|
||||||
bool sortRecv = true;
|
|
||||||
// viewMode: kb/s or total
|
extern int viewMode;
|
||||||
int VIEWMODE_KBPS = 0;
|
|
||||||
int VIEWMODE_TOTAL_KB = 1;
|
extern unsigned refreshlimit;
|
||||||
int VIEWMODE_TOTAL_B = 2;
|
extern unsigned refreshcount;
|
||||||
int VIEWMODE_TOTAL_MB = 3;
|
|
||||||
int viewMode = VIEWMODE_KBPS;
|
|
||||||
int nViewModes = 4;
|
|
||||||
|
|
||||||
class Line
|
class Line
|
||||||
{
|
{
|
||||||
@@ -233,7 +230,7 @@ void ui_tick ()
|
|||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
/* switch mode: total vs kb/s */
|
/* switch mode: total vs kb/s */
|
||||||
viewMode = (viewMode + 1) % nViewModes;
|
viewMode = (viewMode + 1) % VIEWMODE_COUNT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -357,6 +354,7 @@ void do_refresh()
|
|||||||
proglen = cols - 53;
|
proglen = cols - 53;
|
||||||
|
|
||||||
refreshconninode();
|
refreshconninode();
|
||||||
|
refreshcount++;
|
||||||
if (DEBUG || tracemode)
|
if (DEBUG || tracemode)
|
||||||
{
|
{
|
||||||
std::cout << "\nRefreshing:\n";
|
std::cout << "\nRefreshing:\n";
|
||||||
@@ -513,6 +511,7 @@ void do_refresh()
|
|||||||
mvprintw (totalrow+1, 0, "");
|
mvprintw (totalrow+1, 0, "");
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (refreshlimit != 0 && refreshcount >= refreshlimit)
|
||||||
|
quit_cb(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
22
main.cpp
22
main.cpp
@@ -8,13 +8,16 @@ static void versiondisplay(void)
|
|||||||
static void help(void)
|
static void help(void)
|
||||||
{
|
{
|
||||||
//std::cerr << "usage: nethogs [-V] [-b] [-d seconds] [-t] [-p] [-f (eth|ppp))] [device [device [device ...]]]\n";
|
//std::cerr << "usage: nethogs [-V] [-b] [-d seconds] [-t] [-p] [-f (eth|ppp))] [device [device [device ...]]]\n";
|
||||||
std::cerr << "usage: nethogs [-V] [-b] [-d seconds] [-t] [-p] [device [device [device ...]]]\n";
|
std::cerr << "usage: nethogs [-V] [-b] [-d seconds] [-v mode] [-c count] [-t] [-p] [-s] [device [device [device ...]]]\n";
|
||||||
std::cerr << " -V : prints version.\n";
|
std::cerr << " -V : prints version.\n";
|
||||||
|
std::cerr << " -b : bughunt mode - implies tracemode.\n";
|
||||||
std::cerr << " -d : delay for update refresh rate in seconds. default is 1.\n";
|
std::cerr << " -d : delay for update refresh rate in seconds. default is 1.\n";
|
||||||
|
std::cerr << " -v : view mode (0 = KB/s, 1 = total KB, 2 = total B, 3 = total MB). default is 0.\n";
|
||||||
|
std::cerr << " -c : number of updates. default is 0 (unlimited).\n";
|
||||||
std::cerr << " -t : tracemode.\n";
|
std::cerr << " -t : tracemode.\n";
|
||||||
//std::cerr << " -f : format of packets on interface, default is eth.\n";
|
//std::cerr << " -f : format of packets on interface, default is eth.\n";
|
||||||
std::cerr << " -b : bughunt mode - implies tracemode.\n";
|
|
||||||
std::cerr << " -p : sniff in promiscious mode (not recommended).\n";
|
std::cerr << " -p : sniff in promiscious mode (not recommended).\n";
|
||||||
|
std::cerr << " -s : sort output by sent column.\n";
|
||||||
std::cerr << " device : device(s) to monitor. default is eth0\n";
|
std::cerr << " device : device(s) to monitor. default is eth0\n";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
std::cerr << "When nethogs is running, press:\n";
|
std::cerr << "When nethogs is running, press:\n";
|
||||||
@@ -31,7 +34,7 @@ int main (int argc, char** argv)
|
|||||||
int promisc = 0;
|
int promisc = 0;
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
while ((opt = getopt(argc, argv, "Vhbtpd:")) != -1) {
|
while ((opt = getopt(argc, argv, "Vhbtpd:v:c:s")) != -1) {
|
||||||
switch(opt) {
|
switch(opt) {
|
||||||
case 'V':
|
case 'V':
|
||||||
versiondisplay();
|
versiondisplay();
|
||||||
@@ -49,8 +52,17 @@ int main (int argc, char** argv)
|
|||||||
case 'p':
|
case 'p':
|
||||||
promisc = 1;
|
promisc = 1;
|
||||||
break;
|
break;
|
||||||
|
case 's':
|
||||||
|
sortRecv = false;
|
||||||
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
refreshdelay=atoi(optarg);
|
refreshdelay = atoi(optarg);
|
||||||
|
break;
|
||||||
|
case 'v':
|
||||||
|
viewMode = atoi(optarg) % VIEWMODE_COUNT;
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
refreshlimit = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
/*
|
/*
|
||||||
case 'f':
|
case 'f':
|
||||||
@@ -81,7 +93,7 @@ int main (int argc, char** argv)
|
|||||||
init_ui();
|
init_ui();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NEEDROOT && (getuid() != 0))
|
if (NEEDROOT && (geteuid() != 0))
|
||||||
forceExit(false, "You need to be root to run NetHogs!");
|
forceExit(false, "You need to be root to run NetHogs!");
|
||||||
|
|
||||||
char errbuf[PCAP_ERRBUF_SIZE];
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
|||||||
26
nethogs.8
26
nethogs.8
@@ -6,22 +6,31 @@ nethogs \- Net top tool grouping bandwidth per process
|
|||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.ft B
|
.ft B
|
||||||
.B nethogs
|
.B nethogs
|
||||||
.RB [ "\-d" ]
|
|
||||||
.RB [ "\-h" ]
|
.RB [ "\-h" ]
|
||||||
.RB [ "\-p" ]
|
|
||||||
.RB [ "\-t" ]
|
|
||||||
.RB [ "\-V" ]
|
.RB [ "\-V" ]
|
||||||
|
.RB [ "\-d" ]
|
||||||
|
.RB [ "\-v" ]
|
||||||
|
.RB [ "\-t" ]
|
||||||
|
.RB [ "\-c" ]
|
||||||
|
.RB [ "\-p" ]
|
||||||
|
.RB [ "\-s" ]
|
||||||
.RI [device(s)]
|
.RI [device(s)]
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
NetHogs is a small 'net top' tool. Instead of breaking the traffic down per protocol or per subnet, like most such tools do, it groups bandwidth by process - and does not rely on a special kernel module to be loaded. So if there's suddenly a lot of network traffic, you can fire up NetHogs and immediately see which PID is causing this, and if it's some kind of spinning process, kill it.
|
NetHogs is a small 'net top' tool. Instead of breaking the traffic down per protocol or per subnet, like most such tools do, it groups bandwidth by process - and does not rely on a special kernel module to be loaded. So if there's suddenly a lot of network traffic, you can fire up NetHogs and immediately see which PID is causing this, and if it's some kind of spinning process, kill it.
|
||||||
|
|
||||||
.SS Options
|
.SS Options
|
||||||
.TP
|
.TP
|
||||||
|
\fB-h\fP
|
||||||
|
display available commands usage.
|
||||||
|
.TP
|
||||||
|
\fB-V\fP
|
||||||
|
prints Version info.
|
||||||
|
.TP
|
||||||
\fB-d\fP
|
\fB-d\fP
|
||||||
delay for refresh rate.
|
delay for refresh rate.
|
||||||
.TP
|
.TP
|
||||||
\fB-h\fP
|
\fB-v\fP
|
||||||
display available commands usage.
|
select view mode
|
||||||
.TP
|
.TP
|
||||||
\fB-p\fP
|
\fB-p\fP
|
||||||
sniff in promiscious mode (not recommended).
|
sniff in promiscious mode (not recommended).
|
||||||
@@ -29,8 +38,11 @@ sniff in promiscious mode (not recommended).
|
|||||||
\fB-t\fP
|
\fB-t\fP
|
||||||
tracemode.
|
tracemode.
|
||||||
.TP
|
.TP
|
||||||
\fB-V\fP
|
\fB-c\fP
|
||||||
prints Version info.
|
limit number of refreshes
|
||||||
|
.TP
|
||||||
|
\fB-s\fP
|
||||||
|
sort by traffic sent
|
||||||
.PP
|
.PP
|
||||||
.I device(s)
|
.I device(s)
|
||||||
to monitor. By default eth0 is being used.
|
to monitor. By default eth0 is being used.
|
||||||
|
|||||||
@@ -52,9 +52,16 @@ extern "C" {
|
|||||||
extern Process * unknownudp;
|
extern Process * unknownudp;
|
||||||
|
|
||||||
unsigned refreshdelay = 1;
|
unsigned refreshdelay = 1;
|
||||||
|
unsigned refreshlimit = 0;
|
||||||
|
unsigned refreshcount = 0;
|
||||||
|
unsigned processlimit = 0;
|
||||||
bool tracemode = false;
|
bool tracemode = false;
|
||||||
bool bughuntmode = false;
|
bool bughuntmode = false;
|
||||||
bool needrefresh = true;
|
bool needrefresh = false;
|
||||||
|
// sort on sent or received?
|
||||||
|
bool sortRecv = true;
|
||||||
|
// viewMode: kb/s or total
|
||||||
|
int viewMode = VIEWMODE_KBPS;
|
||||||
//packet_type packettype = packet_ethernet;
|
//packet_type packettype = packet_ethernet;
|
||||||
//dp_link_type linktype = dp_link_ethernet;
|
//dp_link_type linktype = dp_link_ethernet;
|
||||||
const char version[] = " version " VERSION "." SUBVERSION "." MINORVERSION;
|
const char version[] = " version " VERSION "." SUBVERSION "." MINORVERSION;
|
||||||
|
|||||||
@@ -63,6 +63,13 @@
|
|||||||
|
|
||||||
#define PROGNAME_WIDTH 512
|
#define PROGNAME_WIDTH 512
|
||||||
|
|
||||||
|
// viewMode: how to represent numbers
|
||||||
|
#define VIEWMODE_KBPS 0
|
||||||
|
#define VIEWMODE_TOTAL_KB 1
|
||||||
|
#define VIEWMODE_TOTAL_B 2
|
||||||
|
#define VIEWMODE_TOTAL_MB 3
|
||||||
|
#define VIEWMODE_COUNT 4
|
||||||
|
|
||||||
#define NORETURN __attribute__ ((__noreturn__))
|
#define NORETURN __attribute__ ((__noreturn__))
|
||||||
|
|
||||||
void forceExit(bool success, const char *msg, ...) NORETURN;
|
void forceExit(bool success, const char *msg, ...) NORETURN;
|
||||||
|
|||||||
Reference in New Issue
Block a user