1sg_get_network_io_stats(3) Library Functions Manual sg_get_network_io_stats(3)
2
3
4
6 sg_get_network_io_stats, sg_get_network_io_stats_diff - get network
7 statistics
8
10 #include <statgrab.h>
11
12
13 sg_network_io_stats *sg_get_network_io_stats(int *entries);
14
15 sg_network_io_stats *sg_get_network_io_stats_diff(int *entries);
16
18 Both calls take a pointer to an int, entries, which is filled with the
19 number of network interfaces the machine has. This is needed to know
20 how many sg_network_io_stats structures have been returned. A pointer
21 is returned to the first sg_network_io_stats.
22
23 sg_get_network_io_stats returns the network traffic stored in the ker‐
24 nel which holds the amount of data transferred since bootup. On some
25 platforms, such as Solaris 7, this value is stored in a 32bit int, so
26 wraps around when it reaches 4GB. Other platforms, such as Solaris 8,
27 hold the value in a 64bit int, which wraps somewhere near 17 million
28 terabytes.
29
30 sg_get_network_io_stats also returns the number of packets sent and
31 received, and the number of errors that have occured. It also makes the
32 number of collisions available.
33
34 sg_get_network_io_stats_diff is the same as sg_get_network_io_stats
35 except it will return the difference since the last call. So, for
36 instance a call to sg_get_network_io_stats_diff is made, and called
37 again 5 seconds later. Over that time, 20 bytes of traffic was trans‐
38 mitted and 10 bytes received. Tx will store 20, rx will store 10 and
39 systime will store 5. This function copes with wrap arounds by the O/S
40 so should be seemless to use.
41
43 All network statistics return a pointer to a structure of type sg_net‐
44 work_io_stats.
45
46 typedef struct{
47 char *interface_name;
48 long long tx;
49 long long rx;
50 long long ipackets;
51 long long opackets;
52 long long ierrors;
53 long long oerrors;
54 long long collisions;
55 time_t systime;
56 }sg_network_io_stats;
57
58
59 interface_name
60 The name known to the operating system. (eg. on linux it might
61 be eth0)
62
63 tx The number of bytes transmitted.
64
65 rx The number of bytes received.
66
67 ipackets
68 The number of packets received.
69
70 opackets
71 The number of packets transmitted.
72
73 ierrors
74 The number of receive errors.
75
76 oerrors
77 The number of transmit errors.
78
79 collisions
80 The number of collisions.
81
82 systime
83 The time period over which tx and rx were transferred.
84
86 On the very first call sg_get_network_io_stats_diff will return the
87 same as sg_get_network_io_stats. After the first call it will always
88 return the difference.
89
90 On operating system that hold only 32bits of data there is a problem if
91 the values wrap twice. For example, on Solaris 7 if 9GB is transferred
92 and the operating system wraps at 4GB, the sg_get_network_io_stats_diff
93 function will return 5GB.
94
96 statgrab(3)
97
99 http://www.i-scream.org/libstatgrab/
100
101
102
103i-scream $Date: 2005/04/25 11:25:45 $sg_get_network_io_stats(3)