npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cputilization

v1.0.0

Published

sample your cpu utlization continously

Downloads

44

Readme

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.