NetLoadD is dead and has been replaced by better tools - click here for info

Network Load Daemon (netloadd) @ p u r p l e p i x i e . o r g

Docs: INTERFACE-HOWTO

Home || Documentation || Downloads

Displaying Document: documentation/INTERFACE-HOWTO [ Download ]

/*--------------------------------------------------------------
 NetLoadD - Network Load Daemon                    Read The
 David Cutting (dcutting@purplepixie.org)       L I C E N C E
--------------------------------------------------------------*/

INTERFACE-HOWTO: Using the 1.5.1 TInterface API

The TInterface class is the class used by NetLoadD 1.5.1 to
monitor and record a number of samples from a single interface.

Everything in the TInterface class is currently developmental
and everything is public (see the general development notes).

The main class and code is contained in the netloadd.h file
with supplimental files needed listed as #includes as the top.

As a result of the lack of clarity of a total plan for analysis
the TInterface class itself has functionality built in to store
a linked list of samples (to a maximum, default 600) in FIFO pop
format (eg the 11th sample pushes the 1st off).

The TInterface class is constructed as follows:

class TInterface
 {
 public:
 char Device[12];
 int MaxCount;
 int Count;
 void Clean();
 TSample *First;
 TSample *Last;
 unsigned long LastReceive;
 unsigned long LastTransmit;
 unsigned long LastSampled;
 unsigned long RxDiff;
 unsigned long TxDiff;
 unsigned long TimeDiff;
 unsigned long RxAverage;
 unsigned long TxAverage;
 int Sample();
 void PrintListStat(int);
 void AddSample(TSample *);
 TInterface(const char *Name="eth0", int MaxSamples=600);
 ~TInterface();
 int WriteToFile(const char *filename, int level=2, const char *mode="w");
 }; 

Basically, the class is initialised with a line similar to:

TInterface *i=new TInterface("eth0",10);

which would start the system for interface eth0 and hold a maximum
of 10 samples in it's linked list.

Please always use the destructor for TInterfaces correctly eg:

delete i;

to ensure all files etc are closed and no memory leaks occur.

A sample is called with the Sample() function. This will return 1
upon success. List management of the samples is handled internally
by TInterface. Please see the further details for each member and
property below:

Properties

 char Device[12];

 Name of the device (real name as used by kernel)

 int MaxCount;

 Maximum number of items in the list. Changing this value
 while the list is below the Max to another value greater
 than the number of items is ok but don't change it otherwise.
 Generally best avoided, delete TInterface and start again.

 int Count;

 Number of items in the list. Do not write to this yourself.

 TSample *First;

 Pointer to the first sample in the list (or 0) for empty list.

 TSample *Last;
 
 Pointer to the last sample in the list (or 0) for empty list
 (though you should always use if First==0 to check for a null
 list).

 unsigned long LastReceive;

 Total bytes received recorded at last sample.

 unsigned long LastTransmit;

 Total bytes received recorded at last sample.

 unsigned long LastSampled;
 
 Seconds since EPOC of when last sample occured.

 unsigned long RxDiff;

 Difference in bytes between last sample and the one
 before (received).

 unsigned long TxDiff;

 Difference in bytes between last sample and the one
 before (transmitted).

 unsigned long TimeDiff;

 Time difference in seconds between last sample and
 the one before.

 unsigned long RxAverage;

 Average Received bytes/second over last sample period.

 unsigned long TxAverage;

 Average Transmitted bytes/second over last sample period.



Methods


 int Sample();

 Perform a sample on the interface. Will return a 0 in
 error or 1 with success.

 void Clean();

 Clear list and reset all data.

 void PrintListStat(int);

 Use printf to output current list statistics to the default
 output. The level signifies to what level data is displayed.
 Use a 1 for general use or look in the source for the other
 specifics.

 void AddSample(TSample *);

 Mainly used internally with Sample() to add a sample to the
 list.

 TInterface(const char *Name="eth0", int MaxSamples=600);

 The constructor. Note it is a default constructor, suitable
 for inheritance etc... You can, of course, manually change
 the Device name and MaxSamples after construction.

 ~TInterface();

 The destructor. Please call this properly!

 int WriteToFile(const char *filename, int level=2, const char *mode="w");

 The WriteToFile function writes details to a file passed as
 filename (such as /tmp/netloadd.DEV). The mode (use w or a obviously)
 can be used to append or write from scratch to the file. The level
 denotes a level of data to be written (see the code for more detail) in
 a system similar to the integer parameter used with PrintListStat()

NetLoadD is dead and has been replaced by better tools - click here for info