sg_get_disk_io_stats(3)
π
sg_get_disk_io_stats(3) β get disk io statistics π
Okay bestie, welcome to the manual page for sg_get_disk_io_stats(3) from libstatgrab. This is the whole vibe: disk I/O stats, one disk at a time, no cap. β¨
πΈ NAME πΈ
sg_get_disk_io_stats, sg_get_disk_io_stats_r, sg_get_disk_io_stats_diff, sg_get_disk_io_stats_diff_between, sg_free_disk_io_stats, sg_disk_io_compare_name, sg_disk_io_compare_traffic β all here to get disk io statistics. Periodt. π
β¨ SYNOPSIS β¨
#include <statgrab.h>
sg_disk_io_stats *sg_get_disk_io_stats (size_t *entries);
sg_disk_io_stats *sg_get_disk_io_stats_r (size_t *entries);
sg_disk_io_stats *sg_get_disk_io_stats_diff (size_t *entries);
sg_disk_io_stats *sg_get_disk_io_stats_diff_between (const
sg_disk_io_stats *cur, const sg_disk_io_stats *last,
size_t *entries);
sg_error sg_free_disk_io_stats (sg_disk_io_stats *data);
int sg_disk_io_compare_name (const void *va, const void *vb);
int sg_disk_io_compare_traffic (const void *va, const void *vb);
π DESCRIPTION π
The sg_get_disk_io_stats functions provide disk I/O statistics on a per disk basis. All get- and diff-functions take an optional entries parameter, which points (when given) to a size_t to take the number of returned vector entries. Like, if you hand over entries, it gets the count. π«Ά
sg_get_disk_io_stats()andsg_get_disk_io_stats_r()deliver the I/O-statistics since the disk has been attached to the system.sg_get_disk_io_stats_diff()andsg_get_disk_io_stats_diff_between()deliver the difference between two calls ofsg_get_disk_io_stats()orsg_get_disk_io_stats_r(), respectively. π₯
π¦ API Shortcut π¦
Here's the cheat sheet, bestie:
sg_get_disk_io_statsβ returnssg_disk_io_stats *; data owner:libstatgrab(thread local)sg_get_disk_io_stats_rβ returnssg_disk_io_stats *; data owner: callersg_get_disk_io_stats_diffβ returnssg_disk_io_stats *; data owner:libstatgrab(thread local)sg_get_disk_io_stats_diff_betweenβ returnssg_disk_io_stats *; data owner: caller
β οΈ Bestie, listen:sg_disk_io_statsvectors got fromsg_get_disk_io_stats_r()orsg_get_disk_io_stats_diff_between()must be freed usingsg_free_disk_io_stats()when not needed any more. The caller is responsible for doing it. Not optional, not "later maybe" β you own that cleanup. π
Additionally two support functions for qsort(3) are available: sg_disk_io_compare_name() and sg_disk_io_compare_traffic(). π
π Example π
size_t entries;
sg_disk_io_stats *io_stats = NULL;
while( NULL != ( io_stats = sg_get_disk_io_stats_diff(&entries) ) ) {
/* show disks with most traffic first */
qsort( io_stats, entries, sizeof(io_stats[0]), &sg_disk_io_compare_traffic );
show_disk_io_stats( io_stats );
}
On some platforms, such as Solaris 7, the kernel value is stored in a 32bit int, so wraps around when it reaches 4GB. Other platforms, such as Solaris 8 (and most other modern systems), hold the value in a 64bit int, which wraps somewhere near 17 million terabytes. The sg_get_disk_io_stats_diff() function and the sg_get_disk_io_stats_diff_between() function care about these overflows and try to detect overflows when the diff is calculated. π₯
On Solaris libstatgrab will attempt to get the cXtXdXsX representation for the disk_name string. If it fails it will use a name like sd0. On some systems programs calling libstatgrab will need elevated privileges to lookup some of the names. The mappings are built up when sg_init() is called for the first time. π§
π«Ά RETURN VALUES π«Ά
All diskio statistics return a pointer to a structure of type sg_disk_io_stats.
typedef struct {
char *disk_name;
unsigned long long read_bytes;
unsigned long long write_bytes;
time_t systime;
} sg_disk_io_stats;
disk_nameβ The name known to the operating system. (eg. on linux it might behda)read_bytesβ The number of bytes the disk has read.write_bytesβ The number of bytes the disk has written.systimeβ The time period over whichread_bytesandwrite_byteswere transferred.
π BUGS π
sg_get_disk_io_stats_diff and sg_get_disk_io_stats_diff_between compare two lists of disk (block device) related I/O statistics. Each entry occurring only in the second list is passed through to the resulting list as if it would have been compared to an entry with all statistic values set to 0. This implies, on the very first call sg_get_disk_io_stats_diff will return the same as sg_get_disk_io_stats. π
On operating systems that hold only 32bits of data there is a problem if the values wrap twice. For example, on Solaris 7 if 9GB is transferred and the operating system wraps at 4GB, the sg_get_disk_io_stats_diff() function will return 5GB. That's the whole "math is mathing" moment. π
The compare functions exists rather for backward compatibility than for functionality enhancements. Limited flexibility (e.g. reverse order) and lack of optimising opportunities for the compiler leads to the recommendation to implement the required compare routines locally. π
π SEE ALSO π
π WEBSITE π
β¨https://libstatgrab.org/β©
Signed, sealed, and serving looks: this page is from libstatgrab, dated 2019-03-08, and yes bestie, it's sg_get_disk_io_stats(3) all the way down. Mwah πβ¨
π¦ where this page comes from
- alpine 3.24: libstatgrab-doc 0.92.1-r1 Β· LGPL-2.0-or-later
- arch rolling: libstatgrab 0.92.1-2 Β· LGPL AND GPL
- fedora 43: libstatgrab-devel 1:0.92.1-14.fc43 Β· LGPL-2.1-or-later
- fedora 43: libstatgrab-devel 1:0.92.1-14.fc43 Β· LGPL-2.1-or-later
- fedora 44: libstatgrab-devel 1:0.92.1-15.fc44 Β· LGPL-2.1-or-later
- fedora 44: libstatgrab-devel 1:0.92.1-15.fc44 Β· LGPL-2.1-or-later
- nixos 26.05: libstatgrab 0.92.1
- nixpkgs unstable: libstatgrab 0.92.1
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms