Giter Club home page Giter Club logo

node-system-stats's Introduction

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.

node-system-stats's People

Contributors

joniii11 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.