Socket
Book a DemoInstallSign in
Socket

cpu-percent

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cpu-percent

use procfs to return % cpu use for the whole system

latest
Source
npmnpm
Version
2.0.1
Version published
Maintainers
1
Created
Source

cpu-percent

use procfs to return % cpu use for the whole system or a specific process


var percent = require('cpu-percent')

percent(function(err,percent){
  if(err) {
    // this will continue polling and percent will be undefined.
    // call stop if you want to stop on error.
  }

  console.log(percent,'%')
})

percent.pid(process.pid,function(err,percent){
  // percent is the % of the whole system that is being used by this process
})

API

  • var stop = module.exports(eventBack,sampleTime,windowSize)

    • eventBack, is a function that is called for each new sample

      • eventBack(Number percent), eventBack is called with one argument. the percent cpu used over the sample size
    • sampleTime, the time in ms to poll for cpu use. default 1000

    • windowSize, the number of samples to average for the percentage. default 5

    • returns a stop function. calling stop() stops the sampling interval.

  • var stop = cpuPercent.pid(pid,eventBack,sampleTime,windowSize)

    • pid the process id to watch

    • eventBack, is a function that is called for each new sample

      • eventBack(Number percent), eventBack is called with one argument. the percent cpu used over the sample size
    • sampleTime, the time in ms to poll for cpu use. default 1000

    • windowSize, the number of samples to average for the percentage. default 5

    • returns a stop function. calling stop() stops the sampling interval.

Keywords

cpu

FAQs

Package last updated on 20 Aug 2015

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