New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cputilization

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cputilization

sample your cpu utlization continously

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
decreased by-30%
Maintainers
1
Weekly downloads
 
Created
Source

CPUtilization

Build Status

NPM

NPM

Installation

npm install cputilization

Invocation

This modules sample the cpu utilization. The interface works via callback or event emitter.

callback interface

use the callback interface if the cpu usage should be sampled only once:

var cpuu = require('cputilization');

cpuu(function(error, sample) {
    //returns after 1000ms with the cpu usage of that time interval
    console.log( sample.percentageBusy() );
});

supply an options hash to specify the time interval:

var cpuu = require('cputilization');

cpuu({timeout: 2000}, function(error, sample) {
    //returns after 2000ms
    console.log( sample.percentageBusy() );
});

event emitter interface

if no callback is supplied the cpu utilization will be sampled continously.

a event emitter is returned than, emits a sample event every 1000ms

var cpuu = require('cputilization');

var sampler = cpuu();

sampler.on('sample', function(sample) {
    console.log( sample.percentageBusy() );
});

an additional options hash can be provided:

  • interval: the ticking interval, default: 1000ms
  • autoStart: automatically start the ticker, default: true
var cpuu = require('cputilization');

var sampler = cpuu({interval:100, autoStart: false});

sampler.on('sample', function(sample) {
    console.log( sample.percentageBusy() );
});
start sampling

if the sampler does not start automatically it can be started via the start command:

var cpuu = require('cputilization');

var sampler = cpuu({autoStart: false, interval:100});

sampler.on('sample', function(sample) {
    //gets executed every 100ms
    console.log( sample.percentageBusy() );
});

sampler.start();
stop sampling

the returned event emitter features a stop method, use that one to stop sampling:

var cpuu = require('cputilization');

var sampler = cpuu({interval:100});

sampler.on('sample', function(sample) {
    //gets executed every 100ms
    console.log(sample.percentageBusy());
});

sampler.stop();

CpuSample

An CpuSample object is emitted (EventEmitter interface) or returned via tha callback interface.
The following methods are available:

percentageBusy()

Returns the average CpuUtilization over the specified sampling interval.

percentageIdle()

Returns the average Cpu Idle percentage of the specified sampling interval.

Keywords

FAQs

Package last updated on 27 Sep 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc