Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
system-monitoring
Advanced tools
A lightweight and efficient Node.js library for real-time system monitoring. Track CPU, memory, disk usage, network I/O, and more with ease.
A Node.js package for monitoring system metrics like CPU usage, memory usage, disk usage, network interfaces, uptime, process information, and temperature. This package provides middleware for Express to gather and expose these system metrics in your web applications.
You can install this package using npm:
npm install system-monitoring
## Or yarn add system-monitoring
To use the system-monitoring functions in your project:
import { getCpuInfo, getMemoryUsage, getDiskUsage } from 'system-monitoring';
// Get CPU information
getCpuInfo().then(cpuInfo => {
console.log('CPU Information:', cpuInfo);
});
// Get memory usage
getMemoryUsage().then(memoryUsage => {
console.log('Memory Usage:', memoryUsage);
});
// Get disk usage
const diskUsage = getDiskUsage();
console.log('Disk Usage:', diskUsage);
You can retrieve the following system metrics using the provided functions:
This package provides an Express middleware to gather and expose system metrics.
import express from 'express';
import { systemMonitor, trackRequestResponseTime, createErrorTrackingMiddleware } from 'system-monitoring';
const errorTrackingMiddleware: ReturnType<typeof createErrorTrackingMiddleware> = createErrorTrackingMiddleware();
const app = express();
// Middleware to track response time
app.use(trackRequestResponseTime()); // the time will append on the response header X-Response-Time, you should have another middleware to get access the responseTime from request req.responseTime
// track error rate
app.use(errorTrackingMiddleware) // access information by req.errorResponse, you should have another middleware to get access the error rating from request
// System monitor middleware
app.use(systemMonitor({ cpu: true, memory: true, disk: true })); // access information by req.systemMetrics
app.get('/', (req, res) => {
res.send('System monitoring active.');
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
System Monitoring Functions
{
"totalUserTime": 123456,
"totalSystemTime": 654321,
"totalIdleTime": 789012,
"totalTime": 1567890,
"usedTime": 777777,
"idleTime": 789012,
"usagePercentage": 49.5,
"coreDetails": [
{
"coreId": 0,
"userTime": 12345,
"systemTime": 6543,
"idleTime": 7890,
"totalTime": 15678,
"usagePercentage": 51.4
}
// more cores...
]
}
{
"totalMemory": 16777216,
"freeMemory": 8388608,
"usedMemory": 8388608
}
{
"total": 104857600,
"used": 52428800,
"available": 52428800
}
The systemMonitor
middleware accepts an object with the following options:
Option | Type | Default | Description |
---|---|---|---|
cpu | boolean | true | Enable CPU usage monitoring. |
memory | boolean | true | Enable memory usage monitoring. |
disk | boolean | true | Enable disk usage monitoring. |
network | boolean | true | Enable network interface information monitoring. |
uptime | boolean | true | Enable system uptime monitoring. |
processInfo | boolean | true | Enable process CPU and memory usage monitoring. |
temperature | boolean | false | Enable system temperature monitoring (only on Linux/Windows). |
logs | { path: string, keyword?: string } | null | Fetch logs from a specified file, optionally filtered by keyword. |
responseTime | boolean | false | Track response time for each request. |
Contributions are welcome! If you have any bug reports, suggestions, or feature requests, please open an issue on GitHub.
To contribute:
git checkout -b feature/new-feature
)git commit -m 'Add new feature'
)git push origin feature/new-feature
)Make sure to follow the Contributor Covenant Code of Conduct when participating in the project.
FAQs
A zero-dependency server monitor package
The npm package system-monitoring receives a total of 2,172 weekly downloads. As such, system-monitoring popularity was classified as popular.
We found that system-monitoring demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.