Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
The pidusage npm package is a cross-platform process and system monitoring library. It provides statistics such as CPU usage, memory usage, running time, and more for a given process ID (PID). It's particularly useful for monitoring the resource consumption of processes in Node.js applications.
Process Statistics
This feature allows you to monitor the resource usage of a specific process. The code sample demonstrates how to get statistics such as CPU and memory usage for the current process.
const pidusage = require('pidusage');
pidusage(process.pid, function (err, stats) {
console.log(stats);
});
Monitoring Multiple PIDs
Pidusage also supports monitoring multiple processes at once. This code sample shows how to get statistics for multiple PIDs simultaneously.
const pidusage = require('pidusage');
pidusage([1234, 5678], function (err, stats) {
console.log(stats);
});
A library for looking up processes running on the system. While ps-node focuses more on finding and interacting with processes, pidusage specializes in monitoring their resource usage.
This package provides a broad set of system and OS metrics, including process monitoring. Compared to pidusage, systeminformation offers a wider range of system-related information but might be more complex to use for simple process monitoring tasks.
Cross-platform process cpu % and memory usage of a PID.
Ideas from https://github.com/arunoda/node-usage but with no C-bindings.
Please note that if you need to check a Node.JS script process cpu and memory usage, you can use process.cpuUsage
and process.memoryUsage
since node v6.1.0. This script remain useful when you have no control over the remote script, or if the process is not a Node.JS process.
var pidusage = require('pidusage')
// Compute statistics every second:
setInterval(function () {
pidusage(process.pid, function (err, stats) {
console.log(stats)
// => {
// cpu: 10.0, // percentage (0-100%)
// memory: 357306368, // bytes
// ppid: 312, // PPID
// pid: 727, // PID
// ctime: 867000, // ms user + system time
// elapsed: 6650000, // ms since the start of the process
// timestamp: 864000000 // ms since epoch
// }
})
}, 1000)
// It supports also multiple pids
pidusage([727, 1234], function (err, stats) {
console.log(stats)
// => {
// 727: {
// cpu: 10.0, // percentage (0-100%)
// memory: 357306368, // bytes
// ppid: 312, // PPID
// pid: 727, // PID
// ctime: 867000, // ms user + system time
// elapsed: 6650000, // ms since the start of the process
// timestamp: 864000000 // ms since epoch
// },
// 1234: {
// cpu: 0.1, // percentage (0-100%)
// memory: 3846144, // bytes
// ppid: 727, // PPID
// pid: 1234, // PID
// ctime: 0, // ms user + system time
// elapsed: 20000, // ms since the start of the process
// timestamp: 864000000 // ms since epoch
// }
// }
})
// If no callback is given it returns a promise instead
const stats = await pidusage(process.pid)
console.log(stats)
// => {
// cpu: 10.0, // percentage (0-100%)
// memory: 357306368, // bytes
// ppid: 312, // PPID
// pid: 727, // PID
// ctime: 867000, // ms user + system time
// elapsed: 6650000, // ms since the start of the process
// timestamp: 864000000 // ms since epoch
// }
Property | Linux | FreeBSD | NetBSD | SunOS | macOS | Win | AIX | Alpine |
---|---|---|---|---|---|---|---|---|
cpu | ✅ | ❓ | ❓ | ❓ | ✅ | ℹ️ | ❓ | ✅ |
memory | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |
pid | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |
ctime | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |
elapsed | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |
timestamp | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |
✅ = Working ℹ️ = Not Accurate ❓ = Should Work ❌ = Not Working
Please if your platform is not supported or if you have reported wrong readings file an issue.
[Promise.<Object>]
Get pid informations.
Kind: global function
Returns: Promise.<Object>
- Only when the callback is not provided.
Access: public
Param | Type | Description |
---|---|---|
pids | Number | Array.<Number> | String | Array.<String> | A pid or a list of pids. |
[callback] | function | Called when the statistics are ready. If not provided a promise is returned instead. |
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE file for details.
2.0.8
FAQs
Cross-platform process cpu % and memory usage of a PID
The npm package pidusage receives a total of 1,813,936 weekly downloads. As such, pidusage popularity was classified as popular.
We found that pidusage demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.