PyKstat 0.01 - Solaris kstat(3k) access

PyKstat 0.01 - Solaris kstat(3k) access

Post by William Anni » Thu, 10 Jun 1999 04:00:00

        I have finally decided to release PyKstat, a Python interface
to the Solaris kstat(3k) API.  The package can be found at

        Here is the README file which comes with the package...

This is the initial release of a Python interface to the Solaris kstat
API.  I recommend checking out the man pages for information on the C
API.  This will only work for Solaris, and has been tested on Solaris
2.5, 2.5.1, and 2.6 for SPARC Solaris, and 2.6 for the Intel version
of Solaris, using Python 1.5.1 and 1.5.2.

* Why did I do this?

    I am currently re-implementing a machine monitoring system.  The
original version, written in Perl, has to fork off and parse the
output from various system data tools, such as iostat, vmstat, uptime,
etc.  As it turns out, the vast majority of this data -- and a whole
lot more -- is available via the kstat(3k) interface.  I wanted to be
able to get all this data without forking.

* How did I do this?

    The PyKstat package has several parts, starting with a helper
library in C wrapping kstat into something more friendly.  The next
layer is the lowest Python layer, and is generated by SWIG.  I
distribute the SWIG generated wrappers, so you do not need SWIG
installed to use this package... unless you want to.  The SWIG layer
is little more than a Python version of my wrappers.

    The next layer is in  This provides an object oriented
interface, and nicely hides the chain-following you have to do if you
use the simplest interface. provides a single class, Kstat,
which does all the interesting work.  This interface does however
assume some familiarity with the kstat(3k) API.

    The final layer of PyKstat, and the interface I suspect most
people will want to use, is in  This interface is *not*
OOPy, but it does use the Kstat class as its engine.  I strongly
recommend looking at the doc strings in and playing with the
many functions provided to get a feel for the API.

    For the perversely curious, the dependencies are: kstat API <-
wkstat.c (my helpers) <- (SWIG generated interface to
wkstat.c) <- (OOPy interface to <-
(the most friendly interface).

* What about bugs?

    There are doubtless some bugs.  However, I don't believe there are
any major ones.  I have been using this software to check machine
statistics for a few months now, and in fact some single Python
programs have been running *continuously* for a month and reporting on
machine statistics.

    If you discover any bugs, certainly let me know, but try to
include as much information as possible, and a snippet of code which
causes the problem.

    The install process could be more elegant.

* Cool!  How do I install this.

    Take a look at the Makefile.  It's pretty simple.  You should only
need to change your CC, though I recommend using gcc, and the two
lines saying where your Python is installed.  Then run 'make', then
'make install'.  The install process is crude in the extreme, and
simply copies a few files into your Python library area.

    Check out the few examples in the examples directory to get an
idea of how this package can be used.  I've included the program netd
as an example.  It will *not* work for you, since it requires
libraries I've not made public yet.  It does, however, provide an
interesting example.

William S. Annis

William Annis - System Administrator - Biomedical Computing Group

Mi parolas Esperanton - La Internacia Lingvo


1. kvm_kread(3K) and kvm_read(3K)?

I am trying to create a really trimed system load average utility
which only reports average number of job in the run queue over the
last 1 minute, I prefer not to use top(1) and uptime(1) since both
have other mechanisms for features that I don't need.

A quick hack got the binary working (I admit that I "borrowed" some
codes from top/machine/m-sunos5.c :).  However, upon reviewing the man
page for kvm_read, I noticed that in the USAGE section, the following

     The  use  of  kvm_read()   and   kvm_write()   is   strongly
     discouraged.  On some platforms, there is considerable ambi-
     guity over which address space is to be  accessed  by  these
     functions,  possibly  leading  to  unexpected  results.  The
     kvm_kread(),  kvm_kwrite(),  kvm_uread(),  and  kvm_uwrite()
     functions are much more clearly defined in this respect.


SunOS 5.7           Last change: 22 Sep 1997

However, the API for both kvm_kread and kvm_read are the same:

     #include <kvm.h>

     ssize_t  kvm_read(kvm_t  *kd,  uintptr_t  addr,  void  *buf,
     size_t nbytes);


     ssize_t kvm_kread(kvm_t  *kd,  uintptr_t  addr,  void  *buf,
     size_t nbytes);

Since both need the kd pointer, so why the man page claims so is
puzzling to me?  Even calling kvm_kread, I have to provide the kd
pointer anyways.  To get that, I suppose I need to call kvm_open too.
In any case, I would appreciate any enlightening in this regard, or a
few pointers to the right documentation set.  I am very willing to dig


Chin Fang

2. regular expressions

3. Mail+Term Meta-HOWTO 0.01

4. Problem with Pentium II 233Mhz on Intel 440FX Motherboard

5. QTalk 0.01

6. D-Link DE-528, Old Driver? New one available???

7. Linux 0.01 disk lockup

8. JServ problem: no path_info/path_translated

9. Apple II+ emulator version 0.01 for Linux

10. xmp3player 0.01 - Qt fronted for splay MP3 player

11. Compile linux 0.01 failed ?

12. CMI8330 Mini-HOWTO Version 0.01

13. Announce: Hypershow 0.01