1

I am trying to gather statistics via kstat which I currently use dtrace to gather.

It is not count based information but new data every single time.

The minimum interval on kstat print is 1 second.However ,the data that I need changes several times within a second.Is there a way(API) to get data from kstat whenever the kstat is updated that doesn't use dtrace ?

Iceman
  • 365
  • 1
  • 3
  • 13
  • I'm curious about what problem you're trying to solve here. One thing you should be aware of is that every time you read a kstat, the entire kstat chain for the system must be traversed to get the one that you want. The more often you do this, the greater the load you will be placing on the system, and the more perturbing your monitoring will be. – James McPherson Feb 29 '16 at 04:09
  • @JamesMcPherson spa sync stats – Iceman Feb 29 '16 at 15:54
  • I'm still unclear why you need to get that data more than once per second. – James McPherson Feb 29 '16 at 20:26
  • I am collecting data per spa_sync cycle.This may be less than a second. – Iceman Feb 29 '16 at 21:35

1 Answers1

1

Outside with dtrace, there is no way to get the statistics when they are updated however, the C libkstat API allows retrieving kstat statistics with an arbitrary sub second sampling rate.

There is also a perl api should you want to do it with scripting.

A very simple way to use it would be to create a customized kstat command (which happen to already be a perl script leveraging the kstat perl api) and modify it to use high resolution timers instead of the default one, e.g.:

$ sed '
s/sleep($interval);/Time::HiRes::usleep($interval*1000.);/
/use Sun::Solaris::Kstat/a\
use Time::HiRes;
' /usr/bin/kstat > /var/tmp/kstat_ms
$ chmod +x /var/tmp/kstat_ms
$ /var/tmp/kstat_ms -n lo0 500 3

module: lo                              instance: 0
name:   lo0                             class:    net
        crtime                          19.559031813
        ipackets                        532
        opackets                        532
        snaptime                        4309.506435597


module: lo                              instance: 0
name:   lo0                             class:    net
        crtime                          19.559031813
        ipackets                        534
        opackets                        534
        snaptime                        4310.008578348


module: lo                              instance: 0
name:   lo0                             class:    net
        crtime                          19.559031813
        ipackets                        536
        opackets                        536
        snaptime                        4310.511617682
jlliagre
  • 29,783
  • 6
  • 61
  • 72