monitor-resource
v0.0.2
Published
An Express.js middleware for monitoring system resources like memory usage and disk space.
Downloads
2
Readme
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 is90
.memoryLimit
(Number): Memory usage threshold in percentage. Default is90
.
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