diff -u -urN xosview-1.7.3/linux/MeterMaker.cc xosview-1.7.3.sep.if/linux/MeterMaker.cc --- xosview-1.7.3/linux/MeterMaker.cc Thu Jun 7 22:32:07 2001 +++ xosview-1.7.3.sep.if/linux/MeterMaker.cc Thu Aug 21 18:54:01 2003 @@ -20,6 +20,7 @@ #endif #include "loadmeter.h" #include "btrymeter.h" +#include #include "diskmeter.h" #include "raidmeter.h" @@ -51,8 +52,16 @@ push(new PageMeter(_xos, atof(_xos->getResource("pageBandwidth")))); // check for the net meter - if (_xos->isResourceTrue("net")) - push(new NetMeter(_xos, atof(_xos->getResource("netBandwidth")))); +static const char _netfilename[] = "/proc/net/dev"; +ifstream stat( _netfilename ); +if ( stat ) { + if (_xos->isResourceTrue("net")){ + int ethCount = NetMeter::countdevices(); + int start = (ethCount == -1) ? -1 : 0; + if (ethCount != -1) { + for (int i = start ; i <= ethCount ; i++) + push(new NetMeter(_xos, atof(_xos->getResource("netBandwidth")), i, NetMeter::ethStr(i))); +} } } if (_xos->isResourceTrue("disk")) push(new DiskMeter(_xos, atof(_xos->getResource("diskBandwidth")))); diff -u -urN xosview-1.7.3/linux/netmeter.cc xosview-1.7.3.sep.if/linux/netmeter.cc --- xosview-1.7.3/linux/netmeter.cc Thu Jun 7 22:31:18 2001 +++ xosview-1.7.3.sep.if/linux/netmeter.cc Thu Aug 21 18:53:23 2003 @@ -27,7 +27,6 @@ #include "netmeter.h" -#include "xosview.h" #include #include @@ -42,9 +41,13 @@ #endif #include #include +#include +#include +#include +#include -NetMeter::NetMeter( XOSView *parent, float max ) - : FieldMeterGraph( parent, 3, "NET", "IN/OUT/IDLE" ){ +NetMeter::NetMeter( XOSView *parent, float max, int ID, const char *ethID) + : FieldMeterGraph( parent, 3, ethID, "IN/OUT/IDLE" ), _number(ID) { _timer.start(); maxpackets_ = max; _lastBytesIn = _lastBytesOut = 0; @@ -162,22 +165,40 @@ } else { - ifs.ignore(1024, '\n'); - ifs.ignore(1024, '\n'); - while (!ifs.eof()) - { + static char ethbuf[32]; + ostrstream eth(ethbuf, 32); + eth << "eth"; + eth << _number; + eth << ends; + +char newbuf[1024]; +int counter = 0; +int reached = 0; +while (!ifs.eof()) { +ifs >> newbuf; +if (strncmp(newbuf, ethbuf, strlen(ethbuf))) { +if ( reached != 1) { +counter++; }}else{ +counter++; +reached = 1; } +ifs.getline(newbuf, 1024); +} + +ifstream ifs(_netfilename); + +for (int i = 2 ; i < counter; i = i+1 ) { +ifs.getline(buf, 1024); } + + ifs.getline(buf, 1024); ifs.ignore(1024, ':'); ifs >> in >> ig >> ig >> ig >> ig >> ig >> ig >> ig >> out; - if (!ifs.eof()) { - totin += in; - totout += out; + totin = in; + totout = out; } - ifs.ignore(1024, '\n'); - } } float t = 1000000.0 / _timer.report(); @@ -302,3 +323,36 @@ } } +int NetMeter::countdevices(void){ + ifstream ethinfo( "/proc/net/dev" ); + + if ( !ethinfo ){ + cerr <<"Can not open file : " <<"/proc/net/dev" <> buf; +//if (!ethinfo.eof()){ +if (!strncmp(buf, "eth", 3)) + ethCount++; + } +//} + + return ethCount; +} + +const char *NetMeter::ethStr(int num){ + static char buffer[32]; + ostrstream str(buffer, 32); + + str << "eth"; + str << (num); + str << ends; + + return buffer; +} diff -u -urN xosview-1.7.3/linux/netmeter.h xosview-1.7.3.sep.if/linux/netmeter.h --- xosview-1.7.3/linux/netmeter.h Sun Nov 7 21:22:11 1999 +++ xosview-1.7.3.sep.if/linux/netmeter.h Thu Aug 21 18:53:23 2003 @@ -16,13 +16,17 @@ class NetMeter : public FieldMeterGraph { public: - NetMeter(XOSView *parent, float max); + NetMeter(XOSView *parent, float max, int ID = 0, const char *ethID = "eth"); ~NetMeter( void ); const char *name( void ) const { return "NetMeter"; } void checkevent( void ); void checkResources( void ); + static int countdevices(void); + static const char *ethStr(int num); + char ethID[256]; + protected: float maxpackets_; @@ -39,6 +43,10 @@ void checkeventOld(void); void checkeventNew(void); + int _number; + int eth; + int counter; + int reached; }; #endif