0.0.13 • Published 3 years ago

cpumon v0.0.13

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years 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

3 years ago

0.0.12

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago