Looking for kstat equivalents in Linux
I have a program that collects various kstat information on our Solaris systems and, now that we've introduced Linux into our data center, I'd like to do the same for Linux.
I'm having trouble, however, finding equivalents for many of the kstats. I was wondering if there is a library or utility that mimics kstats for the Linux environment. Even a partial implementation would be helpful.
As of r开发者_JAVA技巧ight now, I've been parsing files in /proc but finding the right information has been hit or miss. For example, kstat has the following data:
unix::vminfo swap_alloc swap_avail swap_free swap_resv
In Linux, you have the entries "SwapTotal" and "SwapFree" but a) It appears that swap_free actually corresponds to "SwapTotal" and swap_avail corresponds to "SwapFree" b) I can't find values for swap_avail (Maybe SwapTotal minus SwapFree?) now swap_resv
Any ideas?
I'm not aware of a Linux kstat implementation but anyway, you are first facing a terminology issue here.
The Solaris kstats swap statistics you are referencing are using "swap" to mean the whole virtual memory, i.e. the swap areas plus a large part of the RAM.
On the other hand, the Linux SwapTotal and SwapFree statistics are only related to the swap area (i.e. on disk).
Another issue is Linux overcommit memory allocation so a memory reservation counter might not be maintained and wouldn't be useful anyway.
There is this meminfo documentation take 2 article on LWN which describes all fields from /proc/meminfo and says the following about SwapTotal and SwapFree:
SwapTotal: total amount of swap space available
SwapFree: Memory which has been evicted from RAM, and is temporarily
on the disk
There is also some discussion at http://kerneltrap.org/node/4097.
Perl version:
https://github.com/zfsonlinux/linux-kstat
"This is an implementation of the Sun::Solaris::Kstat Perl module for Linux ZFS. It should behave identically to the Solaris version."
Ruby version:
https://www.rubydoc.info/gems/linux-kstat/Linux/Kstat
"The Kstat class encapsulates Linux kernel statistics derived from /proc/stat."
精彩评论