Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-system-stats

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-system-stats

This package shows you the system statistics, with wonderful type declartions.

  • 1.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.5K
decreased by-26.82%
Maintainers
1
Weekly downloads
 
Created
Source

github actions

Node-System-Stats

Note: You can find documentation for all of the types and functions here.

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

Note: This package is a TS-rewrite of the old package cpu-stat. Also it comes with 1 more function to measure the ram usage. More functions will be added later.

Installing

npm install node-system-stats

Examples on how to use it

To measure the cpu Usage in percent, you can use this function below. Parameter Description can be found here

By default you can use it like that:

// TypeScript: import { usagePercent } from "node-system-stats";
const { usagePercent } = require("node-system-stats")

let result = { percent: 0 };

try {
    result = await usagePercent()
} catch (err) {
    console.log(err)
}

console.log(result); // Output: { percent: 1.5, seconds: 1}

Get the cpu usage percent for core 0 over a sample period of 2000ms:

// TypeScript: import { usagePercent } from "node-system-stats"
const { usagePercent } = require("node-system-stats");

let result = { percent: 0 };

try {
    result = await usagePercent({ coreIndex: 0, sampleMs: 2000 })
} catch (err) {
    console.log(err);
}

console.log(result);

To get all of the cores, you can use this function below. View here for more description.

// TypeScript: import { totalCores } from "node-system-stats"
const { totalCores } = require("node-system-stats");

console.log(totalCores); // Output: 8 
                           
// Note: Threads count as cores too! So if you want to only get the "real" cores use the code snippet below:
console.log(totalCores / 2); // Output: 4

If you want to get the Average CPU Clock speed, then use this function below. View here for more description.

// TypeScript: import { avgClockMHz } from "node-system-stats"
const { avgClockMHz } = require("node-system-stats");

console.log(avgClockMHz()); // Output: 3600

Note: To see every function, please take a look at the documentation.

Contributing

If you wish to contribute to the Node-System-Stats codebase or documentation, feel free to fork the repository and submit a pull request. We use ESLint to enforce a consistent coding style, so having that set up in your editor of choice is a great boon to your development process.

Keywords

FAQs

Package last updated on 18 Mar 2024

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