sg_get_network_io_stats_r3
Get network statistics
Usage
FCsg_network_io_stats *sg_get_network_io_statsF
[0]
FC(size_t
*entries);F
[0]
FCsg_network_io_stats *sg_get_network_io_stats_rF
[0]
FC(size_t
*entries);F
[0]
FCsg_network_io_stats *sg_get_network_io_stats_diffF
[0]
FC(size_t
*entries);F
[0]
FCsg_network_io_stats *sg_get_network_io_stats_diff_betweenF
[0]
FC(const
sg_network_io_stats
*cur,
const
sg_network_io_stats
*last,
size_t
*entries);F
[0]
FCsg_error sg_free_network_io_statsF
[0]
FC(sg_network_iface_stats
*data);F
[0]
FCint sg_network_io_compare_nameF
[0]
FC(const
void
*va,
const
void
*vb);F
[0]
Overview
The FCsg_get_network_io_statsF[0] functions provide network interface I/O statistics on a per interface basis. All get- and diff-functions take an optional FCentriesF[0] parameter, which points (when given) to a size_t to take the number of returned vector entries.
The FCsg_get_network_io_statsF[0]() and FCsg_get_network_io_stats_rF[0]() functions deliver the I/O-statistics since the interface has been attached to the system. The FCsg_get_network_io_stats_diffF[0]() and FCsg_get_network_io_stats_diff_betweenF[0]() deliver the difference between two calls of FCsg_get_network_io_statsF[0]() or FCsg_get_network_io_stats_rF[0](), respectively.
API Shortcut
| function | returns | data owner |
| sg_get_network_io_stats | sg_network_io_stats * | libstatgrab (thread local) |
| sg_get_network_io_stats_r | sg_network_io_stats * | caller |
| sg_get_network_io_stats_diff | sg_network_io_stats * | libstatgrab (thread local) |
| sg_get_network_io_stats_diff_between | sg_network_io_stats * | caller |
FCsg_network_io_statsF[0] vectors received from FCsg_get_network_io_stats_rF[0]() or FCsg_get_network_io_stats_diff_betweenF[0]() must be freed using FCsg_free_network_io_statsF[0]() when not needed any more. The caller is responsible for doing it.
Additionally a support function for FCqsortF[0](3) are available: FCsg_network_io_compare_nameF[0]().
Example
FC
size_t entries;
sg_network_io_stats *network_stats = NULL;
while( NULL != ( network_stats = sg_get_network_io_stats_diff(&entries) ) ) {
/* sort interface by name */
qsort( network_stats, entries, sizeof(network_stats[0]), &sg_network_io_compare_name );
show_network_io_stats( network_stats );
}
F[0]
FCsg_get_network_io_statsF[0] returns the network traffic stored in the kernel which holds the amount of data transferred since device was attached. On some platforms, such as Solaris 7, this value is stored in a 32bit int, so wraps around when it reaches 4GB. Other platforms, such as Solaris 8, hold the value in a 64bit int, which wraps somewhere near 17 million terabytes. The FCsg_get_network_io_stats_diffF[0]() function and the FCsg_get_network_io_stats_diff_betweenF[0]() function care about these overflows and try to detect overflows when the diff is calculated.
Return values
All network statistics return a pointer to a structure of type FCsg_network_io_statsF[0].
FC
typedef struct {
char *interface_name;
unsigned long long tx;
unsigned long long rx;
unsigned long long ipackets;
unsigned long long opackets;
unsigned long long ierrors;
unsigned long long oerrors;
unsigned long long collisions;
time_t systime;
} sg_network_io_stats;
F[0]
- FCinterface_nameF[0]
-
The name known to the operating system. (eg. on linux it might be eth0, on AIX en0 and on FreeBSD fxp0)
- FCtxF[0]
-
The number of bytes transmitted.
- FCrxF[0]
-
The number of bytes received.
- FCipacketsF[0]
-
The number of packets received.
- FCopacketsF[0]
-
The number of packets transmitted.
- FCierrorsF[0]
-
The number of receive errors.
- FCoerrorsF[0]
-
The number of transmit errors.
- FCcollisionsF[0]
-
The number of collisions.
- FCsystimeF[0]
-
The timestamp when the above stats where collected in seconds since epoch or the time period over which FCtxF[0] and FCrxF[0] were transferred.
Website
⟨https://libstatgrab.org/⟩
History
- Arch Linux 2026-11-01: the text shown here
- Debian 13 (Trixie) to Debian 12 (Bookworm)
- Debian 11 (Bullseye)
- Debian 10 (Buster) to Debian 8 (Jessie)