Search code examples
solarisopensolariskstat

print kstat when updated (multiple times in 1 second)


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 ?


Solution

  • 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