System Load info -Solaris: kstat?

System Load info -Solaris: kstat?

Post by Nataraj Nagaratn » Tue, 18 Jul 1995 04:00:00


I'm trying to gather the system load information (for  1, 5 and 15 mins prior).
As of my understanding, I should use the kstat related data/procedures.

So, a part of my code looks something like this:

---------  code starts

 if (!(ksp = kstat_lookup(kc, "unix", 0, "system_misc"))) return FAILURE;
 if (kstat_read(kc, ksp, NULL) == -1) return FAILURE;

 load_5   = (double) ((kstat_named_t *) kstat_data_lookup(ksp,"avenrun_1min"))->value.l \
                                                         / FSCALE;
 load_5   = (double) ((kstat_named_t *) kstat_data_lookup(ksp,"avenrun_5min"))->value.l \
                                                         / FSCALE;
 load_15  = (double) ((kstat_named_t *) kstat_data_lookup(ksp,"avenrun_15min"))->value.l \
                                                         / FSCALE;

------------- code end

Now, when I compile my code and run, I recv a segmentation fault in "kstat_data_lookup"
and debugging it I find that the 'data section' ( kstat->ks_data ) is NULL (0x0)
where as the ks_data_size is 432  (below is the "printed" info from gdb)

--------------------- debugged info starts

$1 = {ks_crtime = 0x0000000048c2a004, ks_next = 0x26490, ks_kid = 11,
  ks_module = "unix", '\000' <repeats 26 times>, ks_resv = 0 '\000',
  ks_instance = 0, ks_name = "system_misc", '\000' <repeats 19 times>,
  ks_type = 1 '\001', ks_class = "misc", '\000' <repeats 26 times>,
  ks_flags = 1 '\001', ks_data = 0x0, ks_ndata = 9, ks_data_size = 432,
  ks_snaptime = 0x00033c8bffdef718,
  ks_update = 0xf0096e48 <_elf_jbuf+9284392>, ks_private = 0x0,
  ks_snapshot = 0xf0096c10 <_elf_jbuf+9283824>, ks_lock = 0x0}
------------------------ debugged info ends --

I dont understand why the ks_data portion is NULL. Is there something I need to do
earlier? What should I do .... Is there a small specific routine to get the system load
information that I can access. (this metrics retrieval is a very MINOR part of
a big project i am working on ..and I am stuck here 8-(

Any help appreciated.

Pl let me know if I should post this somewhere else ...

thanks a ton,


1. looking for info on /dev/kstat and kernel symbols un Solaris 2.x

I'm trying to port an app from SUNOS 4.1.x to Solaris 2.2.
The application (sort of a vmstat/w type of program) looks
for kernel run queue and cpu utilisation info.

I found some sysinfo data structures in header files (sysinfo, cpu_sysinfo
in <sys/sysinfo.h> that seem  to have the info I need.  I found a sysinfo
structure in the kernel namelist bu no cpu_sysinfo.

Then I noticed that things like ps and w and programs looking for this
type of kernel info, use /dev/kstat.  There also seems to use some kstat
library routines (kstatopen(), kstat_lookup(), etc) to look at the
system_misc_kstat structure.  There is even a libstat.a hanging around
and a kstat.h header file..

However I can't find any documentation on the arguments to these kstat
calls or data structures.  Has anyone ever used these calls or can
the please point me to some documentation about this stuff?
Any help would be greatly appreciated.


David Perlin

2. Security Detection

3. /dev/kstat and load average on Solaris 2?

4. How: Clever IP-Routing on 2 ISDN-Cards

5. Problems with kstat, -m64, load average

6. Avoiding Win XP

7. SystemCall(s) for Obtaining System Load Info

8. Linux & HP Omnibook

9. System load problems; like some info

10. Solaris 10 kstat output of multicore machine

11. PyKstat 0.01 - Solaris kstat(3k) access

12. kstat library in Solaris

13. System Load average: How much load average is good for?