Skip to content

potatosalad/ekstat

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ekstat

ekstat is a read-only interface to the solaris/illumos libkstat(3lib).

Implementation

exports

The interface is rather simple it has 4 functions:

open/0

Simply returns a new kstat handle.

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

close/1

Clears the snapshot and closes the kstat handle.

ok = ekstat:close(Handle).

clear/1

Clears the snapshot for the handle.

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

update/1

Creates a new snapshot for the handle.

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

read/1,2,3,4,5,6

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}]},
 {"vm","unix",0,"vminfo",[{"freemem",257625338}]}].

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

Data = ekstat:read(H, '_', '_', '_', '_', "/freemem|updates/").
Data = [{"misc","unix",0,"pset",[{"updates",78926}]},
 {"misc","unix",0,"sysinfo",[{"updates",790}]},
 {"pages","unix",0,"system_pages",[{"freemem",296009}]},
 {"vm","unix",0,"vminfo",
  [{"freemem",257625338},{"updates",790}]}].

Invalid regular expressions will return an error:

Error = ekstat:read(Handle, "/*/").
Error = {error,{regerror,"repetition-operator operand invalid"}}.

About

erlang library for reading Solaris kstat data

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 86.7%
  • Erlang 10.6%
  • Makefile 2.7%