0.0.2 • Published 8 months ago

monitor-resource v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

monitor-resource

A middleware for Express.js to monitor system resources, including disk and memory usage.

Installation

npm install monitor-resource

Usage

First, import the middleware:

const monitorResource = require('monitor-resource');

Then, use it in your Express application:

const express = require('express');
const app = express();

const monitorOptions = {
  endpoint: '/resource-status',  // Optional: default is '/monitor'
  diskPath: '/',                 // Optional: default is '/'
  diskLimit: 90,                 // Optional: default is 90
  memoryLimit: 90                // Optional: default is 90
};

app.use(monitorResource(monitorOptions));

app.listen(3000, () => {
  console.log('Server running on http://localhost:3000');
});

API

monitorResource(monitorOptions)

Creates a new middleware instance.

Parameters:

  • monitorOptions (Object):
    • endpoint (String): The endpoint where resource monitoring data can be fetched. Default is /monitor.
    • diskPath (String): The path of the disk to monitor. Default is /.
    • diskLimit (Number): Disk usage threshold in percentage. Default is 90.
    • memoryLimit (Number): Memory usage threshold in percentage. Default is 90.

Returns:

An Express router.

Response Format

When you make a GET request to the configured endpoint (default /monitor), you'll receive a JSON response with the following structure:

{
  "diskPath": "/",
  "diskUsage": 85,
  "diskExceeded": false,
  "memoryUsage": 2048000000,
  "memoryExceeded": false
}

License

MIT

0.0.2

8 months ago

0.0.1

8 months ago