0.0.13 • Published 1 year ago

cpumon v0.0.13

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Library and a CLI tool to monitor CPU usage

The goal:

The goal is to provide simple API to monitor CPU usage accross all available CPU cores. You can provide sampling interval in ms to the constructor. The CpuMonitor class is based on standard NodeJS EventEmitter.

You can subscribe to cpudata events which would be generated according to the provided sampling interval. The event would also have the data of cpu usage percentage for each cpu core.

There is no CJS build provided. Only ESM is provided, so use import - not require.

Use CLI tool:

npx cpumon@latest

Install as dependency

npm i cpumon

Use in JS:

import { CpuMonitor } from 'cpumon';

const monitor = new CpuMonitor(1000);

monitor.on(
    'cpudata',
    (load) => console.log(load)
);

Use in TS

import { CpuInfo, CpuMonitor } from 'cpumon';

const monitor = new CpuMonitor(1000);

monitor.on(
    'cpudata',
    (load: CpuInfo[]) => console.log(load)
);

Stop Monitoring

You can stop monitoring cpu by calling .stopMonitor() method. For example, to stop monitoring after 5 min, you can use the following code:

setTimeout(() => monitor.stopMonitor(), 5*60*1000);

Data Types:

type CpuInfo = {
    model: string;
    idle: number;
    load: number;
    total: number;
    loadRatio?: number;
    loadPercentage?: number;
}
0.0.13

1 year ago

0.0.12

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago