Originally posted by: dimir
I need to create a C program to get network interface statistics (e. g. in/out packets/bytes/errors). I used examples of using libperfstat here:
http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.prftools/doc/prftools/prftools07.htm It works well but for some reason the results I get totally differ from what entstat command shows. And it happens on 2 different machines (5.3 and 6.1). Does anybody know why is the difference and should I make any adjustments to my program in order to get proper results?
Below are details on the subject.
###################
-
My program code #
###################
$ cat perfstat-net.c
#include <stdio.h>
#include <stdlib.h>
#include <libperfstat.h>
#include <string.h>
int main(int argc, char *argv[])
{
perfstat_netinterface_t ps_if;
perfstat_id_t ps_id;
if (argc != 2) {
fprintf(stderr, "usage: %s <device>\n", argv[0]);
exit(EXIT_FAILURE);
}
strcpy(ps_id.name, argv[1]);
if (perfstat_netinterface(&ps_id, &ps_if, sizeof(perfstat_netinterface_t), 1) != 1) {
fprintf(stderr, "perfstat_netinterface() failed\n");
exit(EXIT_FAILURE);
}
printf("Statistics for interface : %s\n", ps_if.name);
printf("------------------------\n");
printf("\ninput statistics:\n");
printf("number of packets : %llu\n", ps_if.ipackets);
printf("number of bytes : %llu\n", ps_if.ibytes);
printf("number of errors : %llu\n", ps_if.ierrors);
printf("\noutput statistics:\n");
printf("number of packets : %llu\n", ps_if.opackets);
printf("number of bytes : %llu\n", ps_if.obytes);
printf("number of errors : %llu\n", ps_if.oerrors);
exit(EXIT_SUCCESS);
}
#####################
-
My program output #
#####################
$ gcc -o perfstat-net perfstat-net.c -lperfstat -Wall && ./perfstat-net en1
Statistics for interface : en1
input statistics:
number of packets : 508180206 <--- in packets
number of bytes : 3914575317 <--- in bytes
number of errors : 0 <--- in errors
output statistics:
number of packets : 899241 <--- out packets
number of bytes : 66302139 <--- out bytes
number of errors : 0 <--- out errors
##################
-
entstat output #
##################
$ entstat en1
ETHERNET STATISTICS (en1) :
Device Type: Host Ethernet Adapter (l-hea)
Hardware Address: 00:1a:64:f0:3a:31
Elapsed Time: 25 days 22 hours 24 minutes 24 seconds
Transmit Statistics: Receive Statistics:
Packets: 183463 Packets: 49625506 <--- out/in packets
Bytes: 13869163 Bytes: 4238405514 <--- out/in bytes
Interrupts: 0 Interrupts: 49147441
Transmit Errors: 1498 Receive Errors: 0 <--- out/in errors
http://... ##############
-
OS version #
##############
$ oslevel -s
6100-01-01-0823
#AIX-Forum