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

os-profiler

v1.0.0

Published

os-profiler is a lightweight utility that provides a snapshot of system resource utilization, including CPU, memory, and disk usage. This package is ideal for profiling system utilization in real-time, enabling you to track resource consumption and ensure

Downloads

63

Readme

os-profiler

os-profiler is a lightweight utility that provides a snapshot of system resource utilization, including CPU, memory, and disk usage. This package is ideal for profiling system utilization in real-time, enabling you to track resource consumption and ensure that systems are running efficiently.

Features

  • Get CPU usage, including idle and active time.
  • Monitor memory usage, including total, used, free memory, and usage percentage.
  • Analyze disk utilization, including total, used, and free space on the root directory.

Installation

You can install this package via npm:

npm install os-profiler

Usage

Here’s an example of how to use os-profiler to retrieve a snapshot of system resource utilization:

import { SystemProfiler } from 'os-profiler';

const profiler = new SystemProfiler();

(async () => {
  const snapshot = await profiler.getSystemSnapshot();
  console.log(snapshot);
  const cpu = await profiler.getCpuUsage();
  console.log(cpu);
  const memory = await profiler.getMemoryUsage();
  console.log(memory);
  const disk = await profiler.getDiskUsage();
  console.log(disk);
})();

Output Example:

{
  "cpu": {
    "cpuCount": 4,
    "idlePercentage": 85.65,
    "totalPercentage": 14.35
  },
  "memory": {
    "total": 17179869184,
    "used": 8376545280,
    "free": 8794213888,
    "usagePercentage": 48.76
  },
  "disk": {
    "total": 499963174912,
    "used": 256789012480,
    "free": 243174162432,
    "usagePercentage": 51.37
  }
}

Methods

getSystemSnapshot()

Returns a promise that resolves to an object containing CPU, memory, and disk utilization data.

  • CPU Data:

    • cpuCount: Number of CPU cores.
    • idlePercentage: Percentage of time CPU cores are idle (string).
    • totalPercentage: Percentage of CPU usage (string).
  • Memory Data:

    • total: Total system memory in bytes.
    • used: Used memory in bytes.
    • free: Free memory in bytes.
    • usagePercentage: Memory usage as a percentage (string).
  • Disk Data:

    • total: Total disk space in bytes.
    • used: Used disk space in bytes.
    • free: Free disk space in bytes.
    • usagePercentage: Disk usage as a percentage (string).

Output Example:

{
  "cpu": {
    "cpuCount": 4,
    "idlePercentage": "85.65",
    "totalPercentage": "14.35"
  },
  "memory": {
    "total": 17179869184,
    "used": 8376545280,
    "free": 8794213888,
    "usagePercentage": "48.76"
  },
  "disk": {
    "total": 499963174912,
    "used": 256789012480,
    "free": 243174162432,
    "usagePercentage": "51.37"
  }
}

getCpuUsage()

Returns an object containing the CPU count, idle percentage, and total usage percentage.

  • Returns:
    • cpuCount: Number of CPU cores.
    • idlePercentage: Percentage of time CPU cores are idle (string).
    • totalPercentage: Percentage of CPU usage (string).

Output Example:

{
  "cpuCount": 4,
  "idlePercentage": "85.65",
  "totalPercentage": "14.35"
}

getMemoryUsage()

Returns an object containing total, used, free memory, and usage percentage.

  • Returns:
    • total: Total system memory in bytes.
    • used: Used memory in bytes.
    • free: Free memory in bytes.
    • usagePercentage: Memory usage as a percentage (string).

Output Example:

{
    "total": 17179869184,
    "used": 8376545280,
    "free": 8794213888,
    "usagePercentage": "48.76"
}

getDiskUsage()

Returns an object containing total, used, free disk space, and usage percentage.

  • Returns:
    • total: Total disk space in bytes.
    • used: Used disk space in bytes.
    • free: Free disk space in bytes.
    • usagePercentage: Disk usage as a percentage (string).

Output Example:

{
    "total": 499963174912,
    "used": 256789012480,
    "free": 243174162432,
    "usagePercentage": "51.37"
}

Setup on Your Local Machine

To set up the project on your local machine, follow these steps:

Clone the repository:

git clone [email protected]:evrentan/os-profiler.git

Navigate to the project directory:

cd os-profiler

Install the dependencies:

npm install

Build the project:

npm run build

Test the project:

npm test

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature/yourFeature).
  3. Commit your changes (git commit -m 'feat(Feature): Add some Feature').
  4. Push to the branch (git push origin feature/yourFeature).
  5. Open a pull request.

License

This project is licensed under the ISC License.

About

This library was created to help developers easily monitor system resource (CPU, memory, disk) utilization for profiling and optimization. If you have any questions or suggestions, feel free to reach out!

Sponsoring

If you enjoy this project and would like to support its development, please consider sponsoring. Your support helps me continue improving and maintaining the project.

You can sponsor me via:

GitHub Sponsors

Buy Me a Coffee

Thank you for your support!