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

cpu-stat

v2.0.1

Published

CPU Statistics not provided by `os` module

Downloads

5,999

Readme

cpu-stat

  _______ _______ ___ ___ _______ _______ _______ _______
 |   _   |   _   |   Y   |   _   |       |   _   |       |
 |.  1___|.  1   |.  |   |   1___|.|   | |.  1   |.|   | |
 |.  |___|.  ____|.  |   |____   `-|.  |-|.  _   `-|.  |-'
 |:  1   |:  |   |:  1   |:  1   | |:  | |:  |   | |:  |
 |::.. . |::.|   |::.. . |::.. . | |::.| |::.|:. | |::.|
 `-------`---'   `-------`-------' `---' `--- ---' `---'

Note: This repo can be found on npm here: cpu-stat

Note: This repo can be found on github here: node-cpu-stat

Note: This module only relies on the os module, so it should be compatible on all OS's where Node.js runs.

Install

npm install cpu-stat

Example

var cpuStat = require('cpu-stat');
//by default returns cpu usage percent for all cores over a period of the next 1000ms
cpuStat.usagePercent(function(err, percent, seconds) {
    if (err) {
      return console.log(err);
    }

    //the percentage cpu usage over all cores
    console.log(percent);

    //the approximate number of seconds the sample was taken over
    console.log(seconds);
});
//get the cpu usage percent for core 0 over a sample period of 2000ms
cpuStat.usagePercent({
    coreIndex: 0,
    sampleMs: 2000,
  },
  function(err, percent, seconds) {
    if (err) {
      return console.log(err);
    }

    //the percentage cpu usage for core 0
    console.log(percent);

    //the approximate number of seconds the sample was taken over
    console.log(seconds);
});
//get the total number of cores
var totalCores = cpuStat.totalCores();
console.log(totalCores);
//get the average clock MHz over all cores
var avgClockMHz = cpuStat.avgClockMHz();
console.log(avgClockMHz);
//get the clock MHz for core with index 2
var avgClockMHzCore2 = cpuStat.clockMHz(2);
console.log(avgClockMHzCore2);

usagePercent(opts, cb)

Provides a callback cb(err, percent, seconds) giving the percent cpu usage and seconds the length of the sample time, or an error err

Option | Type | Default | Explanation -------------------- | -------------| ------------------ | ------------ opts | Object | see below | Options object, specify what you need the defaults will be filled in opts.coreIndex | Number | all cores | The index of the core to calculate the usage on. Can use any coreIndex such that 0 >= coreIndex < memStat.totalCores() opts.sampleMs | String | 1000 | sampleMs is the amount of time to take the measurement over cb | Function | none | Callback which has signature cb(err, percent, seconds)

totalCores()

Returns the total number of cores available on the cpu

clockMHz(coreIndex)

Returns the clock speed in MHz of core with index coreIndex

avgClockMHz()

Returns the average clock speed in MHz over all cores

Contributing

Just send a PR, or create an issue if you are not sure.

Areas ripe for contribution:

  • testing
  • performance
  • bugs

Other Stat Modules

Note: net-stat, disk-stat, mem-stat only work on nix platforms.

License

MIT