Summary ======= libstatgrab[1] is a library that provides cross platform access to statistics about the system on which it is run. It is written in C and presents a selection of useful interfaces which can be used to access key system statistics including Linux and BSD sysctl-style and MRTG output format. The current list of statistics includes CPU usage, memory utilisation, disk usage, process counts, network traffic, disk I/O, and more. The package also includes a couple of useful tools. The first, saidar, provides a curses-based interface to viewing the current state of the system. The second, statgrab, gives a sysctl-style interface to the statistics gathered by libstatgrab. Libstatgrab version 0.16 will be delivered as part of this proposal in the SUNWlibstatgrab package. A minor release binding is requested. Dependencies ============ SUNWcsu SUNWcsl SUNWcslx Interfaces ========== Exported Interfaces Classification Comment ------------------- -------------- -------------------- SUNWlibstatgrab Uncommitted Package /usr/bin/saidar Uncommitted Command /usr/bin/statgrab Uncommitted Command /usr/bin/statgrab-make-mrtg-config Uncommitted Config Script /usr/bin/statgrab-make-mrtg-index Uncommitted Config Script /usr/include/* Uncommitted Header Files /usr/lib/libstatgrab.so.6.2.2 Uncommitted 32-bit Library /usr/lib/libstatgrab.so.6 Uncommitted Symbolic Link /usr/lib/libstatgrab.so Uncommitted Symbolic Link /usr/lib/pkgconfig/libstatgrab.pc Uncommitted Pkg Config Script /usr/lib/64/libstatgrab.so.6.2.2 Uncommitted 64-bit Library /usr/lib/64/libstatgrab.so Uncommitted Symbolic Link /usr/lib/64/libstatgrab.so.6 Uncommitted Symbolic Link /usr/lib/64/pkgconfig/libstatgrab.pc Uncommitted Pkg Config Script *64 = sparcv9 and amd64 Here is the primary libstatgrab interface as given in the statgrab(3) man page. Each function has it's own man page. sg_cpu_stats *sg_get_cpu_stats(void); sg_cpu_stats *sg_get_cpu_stats_diff(void); sg_cpu_percents *sg_get_cpu_percents(void); sg_disk_io_stats *sg_get_disk_io_stats(int *entries); sg_disk_io_stats *sg_get_disk_io_stats_diff(int *entries); sg_fs_stats *sg_get_fs_stats(void); sg_host_info *sg_get_host_info(void); sg_load_stats *sg_get_load_stats(void); sg_mem_stats *sg_get_mem_stats(void); sg_swap_stats *sg_get_swap_stats(void); sg_network_io_stats *sg_get_network_io_stats(int *entries); sg_network_io_stats *sg_get_network_io_stats_diff(int *entries); sg_network_iface_stats *sg_get_network_iface_stats(int *entries); sg_page_stats *sg_get_page_stats(void); sg_page_stats *sg_get_page_stats_diff(void); sg_process_stats *sg_get_process_stats(int *entries); sg_user_stats *sg_get_user_stats(void); Here are the remaining exported interfaces: int sg_init(void); int sg_drop_privileges(void); sg_error sg_get_error(void); const char *sg_get_error_arg(void); int sg_get_error_errno(void); const char *sg_str_error(sg_error code) sg_process_count *sg_get_process_count(void); int sg_process_compare_name(const void *va, const void *vb); int sg_process_compare_pid(const void *va, const void *vb); int sg_process_compare_uid(const void *va, const void *vb); int sg_process_compare_gid(const void *va, const void *vb); int sg_process_compare_size(const void *va, const void *vb); int sg_process_compare_res(const void *va, const void *vb); int sg_process_compare_cpu(const void *va, const void *vb); int sg_process_compare_time(const void *va, const void *vb); libstatgrab works with root and non-root privileges. If root privileges are given, then libstatgrab can return more information. The sg_init() function performs all the one-time initialization including operations that use setuid/setgid privileges if root privilege is used. Afterwards, sg_drop_privileges() is used to discard setuid/setgid privileges. The following code is common in commands using libstatgrab. [2] On Solaris, root privileges are not needed (ie. user and root privileges produce the same results). sg_init(); if(sg_drop_privileges() != 0) { fprintf(stderr, "Failed to drop setuid/setgid privileges\n"); return 1; } Imported Interfaces Classification Comment ---------------------- -------------- ---------------------------- procfs(4) Committed SUNWcsu kstat(3KSTAT) uname(1) kstat(9S) Uncommitted SUNWcsu libdevinfo(3LIB) Committed SUNWcsl, SUNWcslx (64-bit) getloadavg(3C) sysconf(3C) swapctl(2) getutxent(3C) Reference Documents =================== [1] http://www.i-scream.org/libstatgrab/ [2] results showing no difference between user and root privileges. ../materials/statgrab.root.out ../materials/statgrab.user.out ../materials/statgrab.user.root.diff Appendix A. =========== Here's some additional exported interface usage detail: fs_stats (sg_init()) libdevinfo kstat_open() kstat_read() kstat_close() di_init() di_drv_first_node() di_minor_next() di_instance() di_devfs_path() di_minor_name() di_devfs_path_free() di_drv_next_node() di_fini() kstat.ks_name; di_* (device dependent values) cpu_stats kstat_open() kstat_read() kstat_close() cpu_sysinfo.cpu[CPU_USER]; cpu_sysinfo.cpu[CPU_KERNEL]; cpu_sysinfo.cpu[CPU_IDLE]; cpu_sysinfo.wait[W_IO]; cpu_sysinfo.wait[W_PIO]; cpu_sysinfo.wait[W_SWAP]; disk_stats kstat_open() kstat_read() kstat_close() kstat_io.nread; kstat_io.nwritten; kstat.ks_name; load_stats getloadavg() loadavg[LOADAVG_1MIN]; loadavg[LOADAVG_5MIN]; loadavg[LOADAVG_15MIN]; mem_stats kstat_open() kstat_read() kstat_close() kstat_lookup() kstat_data_lookup() sysconf() sysconf(_SC_PAGESIZE); sysconf(_SC_PHYS_PAGES); system_pages_kstat.freemem.value.ul; network_stats kstat_open() kstat_read() kstat_close() kstat_lookup() kstat_data_lookup() kstat.ks_name; kstat.np->rbytes; kstat.np->obytes; kstat.np->ipackets; kstat.np->opackets; kstat.np->ierrors; kstat.np->oerrors; kstat.np->collisions; kstat.np->link_up; kstat.np->ifspeed; kstat.np->link_duplex; host_info uname() kstat_open() kstat_read() kstat_close() kstat_lookup() kstat_data_lookup() utsname.sysname; utsname.release; utsname.version; utsname.machine; utsname.nodename; kstat.np->boot_time; page_stats kstat_open() kstat_read() kstat_close() cpu_vminfo.pgpgin; cpu_vminfo.pgpgout; process_stats procfs process_info.pr_pid; process_info.pr_ppid; process_info.pr_pgid; process_info.pr_uid; process_info.pr_euid; process_info.pr_gid; process_info.pr_egid; process_info.pr_size; process_info.pr_rssize; process_info.pr_time.tv_sec; process_info.pr_pctcpu; process_info.pr_lwp.pr_nice; process_info.pr_fname; process_info.pr_psargs; process_info.pr_state; swap_stats sysconf() swapctl() sysconf(_SC_PAGESIZE); anoninfo.ani_max; anoninfo.ani_resv; user_stats utmpx setutent() getutent() utmp.ut_user;