Operating System - HP-UX
1752565 Members
5513 Online
108788 Solutions
New Discussion юеВ

Amount of network I/O from C++

 
SOLVED
Go to solution
Martin Jerabek
Occasional Advisor

Amount of network I/O from C++

Hi!

Is there a way to determine the amount of network I/O (number of bytes sent and received by each network interface) from a C/C++ program similar to what pstat_getlv returns for each logical volume? This information should not be process-specific but global for the entire machine.

There do not seem to be pstat functions which return information about network interfaces. Glance has the option "network by interface" to show this data but I have not found a way to get the data from a program.

netstat -i and netstat -s only show the packets but I do not see a way to calculate the number of bytes from this, even if I found out how netstat obtains this information.

Could the Data Link Provider Interface be useful for this purpose?

Regards
Martin Jerabek
12 REPLIES 12
Steven E. Protter
Exalted Contributor

Re: Amount of network I/O from C++

Shalom,

wireshark or creative grep of tcpdump output can in combination with netstat give you a clear picture.

If your distribution supports it glance/gpm from HP does have the ability to drill into a process and see how much network bandwidth is being used.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Steven E. Protter
Exalted Contributor

Re: Amount of network I/O from C++

Scratch the distribution part. My brain was stuck in Linux land.

HP-UX ships with a glance/gpm 60 day trial that will let you drill into a process and see how much band width it is using.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Martin Jerabek
Occasional Advisor

Re: Amount of network I/O from C++

Thanks but I need a way to collect the data from a C++ program. The program should be able to react to different load scenarios, so it needs to know how "busy" the network interfaces (and other resources) are.
Dennis Handly
Acclaimed Contributor

Re: Amount of network I/O from C++

>The program should be able to react to different load scenarios, so it needs to know how "busy" the network interfaces are.

Wouldn't using APA be better judge of load scenarios?
And lets your program handle the business logic and leave the networking and OS stuff to somebody smarter?
Martin Jerabek
Occasional Advisor

Re: Amount of network I/O from C++

Unfortunately our system should be able to play this role, too. It is a networked system running on many different platforms, so we want it to work automatically rather than having to rely on different platform-specific tools.

I managed to get the necessary information on Windows, Linux, Solaris, AIX, and Mac OS X. The network interface information on HP-UX is the only missing piece. Since Glance is able to get it (obviously via the midaemon) it must be available but I just do not see it from where.

I ran truss on netstat to see how it does it but I am not familiar enough with the ioctls and STREAMS messages to understand it. It seems to involve /dev/ip but I have not found any documentation about it.
Dennis Handly
Acclaimed Contributor

Re: Amount of network I/O from C++

What HP-UX version are you using?
Martin Jerabek
Occasional Advisor

Re: Amount of network I/O from C++

HP-UX 11.23. It only needs to work on Itanium, not on PA-RISC.

If the necessary interfaces are only available in later versions, this would also be acceptable but of course we would prefer it not to force our customers to update their machines.
rick jones
Honored Contributor
Solution

Re: Amount of network I/O from C++

If all else fails, I suppose there is system() and netstat the command and the joy of parsing its output.

Another possiblity would be SNMP queries of the MIB(s).

I seem to recall there being DLPI stats calls to retrieve link-level stats on a per-PPA basis, so yes, you might look into the DLPI manuals - at one time at least they would have been on docs.hp.com.
there is no rest for the wicked yet the virtuous have no pillows
Martin Jerabek
Occasional Advisor

Re: Amount of network I/O from C++

Thanks for pointing me in the right direction! With the DLPI Programmer's Guide from http://docs.hp.com/en/5992-0554/5992-0554.pdf I was able to piece together the following way to get the data:

- Open /dev/dlpi. All the following STREAMS messages use this file descriptor.

- Using putmsg/getmsg get the information about all network interfaces with DL_HP_PPA_REQ (I actually used DL_HP_EXT_PPA_REQ so that I can use the dl_hp_ext_ppa_info_t::dl_link_state member to check if an interface is up).

- Attach each interface (PPA) with DL_ATTACH_REQ using the dl_ppa of the DL_HP_PPA_ACK.

- Get its statistics with DL_GET_STATISTICS_REQ. The documentation is not clear about the returned data but it is obviously Ext_mib_t from .
BTW, DL_HP_GET_64BIT_STATS_REQ only returned DL_NOTSUPPORTED on my machine.

- Detach the PPA again with DL_DETACH_REQ and repeat with the next one (using dl_next_offset to find the next dl_hp_ppa_info_t).


Thanks again to all who replied!