Giter Site home page Giter Site logo

szaydel / node-kstat Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tritondatacenter/node-kstat

0.0 3.0 0.0 65 KB

A node.js addon for reading Solaris kstats

License: MIT License

Makefile 4.06% C 45.31% JavaScript 25.12% C++ 24.08% Python 1.43%

node-kstat's Introduction

node-kstat

This repository is part of the Triton Data Center project. See the contribution guidelines and general documentation at the main Triton project page.

A node.js binding to the illumos kstat interface. This allows one to read kernel statistics via the kstat framework. It is likely to work unmodified on Solaris too.

Usage

The kstat module exports a single class, Reader that has the following methods:

Reader():  Takes an optional object specifying the kstats to read.  This
           object may have the following members:

           class    =>  optional string denoting class of kstat(s) to read
           module   =>  optional string denoting module of kstat(s) to read
           name     =>  optional string denoting name of kstat(s) to read
           instance =>  optional integer denoting instance of kstat(s) to read

           Together, these members form a specification of kstats to read.

read():    Returns an array of kstats that match the specification with
           which the reader instance was constructed *and* an optional
           specification passed to this function.  Each element of the
           array is an object that contains the following members:

           class    =>  string denoting class of kstat
           module   =>  string denoting module of kstat
           name     =>  string denoting name of kstat
           instance =>  integer denoting instance of kstat
           snaptime =>  nanoseconds since boot of this snapshot
           data     =>  an object containing the named kstat data itself

Examples

Here is a simple program that dumps the kstats of class mib2:

var kstat = require('kstat');
var util = require('util');
var reader = new kstat.Reader({ 'class': 'mib2' } );
console.log(util.inspect(reader.read()));

Here is a the same program that reads only the mib2 class kstats from the icmp module:

var kstat = require('kstat');
var util = require('util');
var reader = new kstat.Reader({ 'class': 'mib2', module: 'icmp' } );
console.log(util.inspect(reader.read()));

Finally, here is a simple program that prints the number of ICMP datagrams received per second:

var kstat = require('kstat');
var reader = new kstat.Reader({ 'class': 'mib2', module: 'icmp' } );

var data = [];
var gen = 0;

setInterval(function() {
	data[gen] = reader.read()[0];
	gen ^= 1;

	if (!(data[0] && data[1]))
		return;

	console.log(data[gen ^ 1].data.inDatagrams - data[gen].data.inDatagrams);
}, 1000);

You can find further example programs in the examples directory.

License

MIT.

node-kstat's People

Contributors

bcantrill avatar davepacheco avatar tylerflint avatar bahamat avatar danmcd avatar jperkin avatar mcavage avatar tootallnate avatar richardkiene avatar rmustacc avatar trentm avatar khalfella avatar

Watchers

Sam Zaydel avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.