Skip to content


Subversion checkout URL

You can clone with
Download ZIP
erlang library for reading Solaris kstat data
C C++ Erlang Makefile
Branch: master


ekstat is a interface to the solaris libkstat, it started out as a port of node-kstat and later was rewritten using parts of the C version of the kstat command line utility.


The interface is rather simple it has 4 functions:


Simply returns a new kstat handle.

{ok, Handle} = ekstat:open().


Creates a new snapshot for the handle.

{ok, NumberOfInstancesUpdated} = ekstat:update(Handle).


Clears the snapshot for the handle.

{ok, NumberOfInstancesCleared} = ekstat:clear(Handle).


read(Handle) -> Result
read(Handle, Class) -> Result
read(Handle, Class, Module) -> Result
read(Handle, Class, Module, Instance) -> Result
read(Handle, Class, Module, Instance, Name) -> Result
read(Handle, Class, Module, Instance, Name, Statistic) -> Result

  kstat_pattern = '_' | integer() | string()

  Handle = ekstat:kstat_handle()
  Class = kstat_pattern()
  Module = kstat_pattern()
  Instance = kstat_pattern()
  Name = kstat_pattern()
  Statistic = kstat_pattern()

  kstat_statistic = {Key::string(), Value::integer()} | {Key::string(), Value::string()}

  Result = [{Class::string(), Module::string(), Instance::integer(), Name::string(), [kstat_statistic()]}]

Reads data from the snapshot (possibly selectively) and returns it:

Class = "misc",
Module = "unix",
Instance = 1,
Name = "callout",
Statistic = "callout_timeouts",
Data = ekstat:read(Handle, Class, Module, Instance, Name, Statistic).
Data = [{"misc","unix",1,"callout",[{"callout_timeouts",21286}]}].

Atom '_' and list "*" are special types that will match anything in that column.

Simple glob matching can be done with *, for example:

Data = ekstat:read(H, '_', '_', '_', '_', "freem*").
Data = [{"pages","unix",0,"system_pages",[{"freemem",296009}]},

Regular expressions are also supported in each column, for example:

Data = ekstat:read(H, '_', '_', '_', '_', "/freemem|updates/").
Data = [{"misc","unix",0,"pset",[{"updates",78926}]},

Invalid regular expressions will return an error:

Error = ekstat:read(Handle, "/*/").
Error = {error,{kstat,"repetition-operator operand invalid"}}.
Something went wrong with that request. Please try again.