Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

system-monitoring

Package Overview
Dependencies
Maintainers
0
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

system-monitoring

A zero-dependency server monitor package

  • 0.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.5K
decreased by-67.23%
Maintainers
0
Weekly downloads
 
Created
Source

System Monitor Package

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.

Table of Contents

  • System Monitor Package
  • Available Metrics

Installation

You can install this package using npm:

npm install system-monitoring
## Or yarn add system-monitoring

Usage

Basic Usage

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);

Available Metrics

You can retrieve the following system metrics using the provided functions:

  1. CPU Information: Get detailed CPU usage information for each core, including user/system/idle times and percentages.
  2. Memory Usage: Get total, free, and used memory statistics.
  3. Disk Usage: Get total, used, and available disk space.
  4. Network Interfaces: Get details about the system’s network interfaces.
  5. Uptime: Get the system’s uptime in seconds.
  6. Process Info: Get the CPU and memory usage of the current Node.js process.
  7. System Temperature: Get the current temperature of the system (if supported).
  8. Logs: Fetch system logs from a specific file with optional keyword filtering.

Express Middleware

This package provides an Express middleware to gather and expose system metrics.

import express from 'express';
import { systemMonitor, trackRequestResponseTime } from 'your-package-name';

const app = express();

// Middleware to track response time
app.use(trackRequestResponseTime);

// System monitor middleware
app.use(systemMonitor({ cpu: true, memory: true, disk: true }));

app.get('/', (req, res) => {
  res.send('System monitoring active.');
});

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

API

System Monitoring Functions

  • getCpuInfo(): Returns CPU usage details for all cores and the system as a whole.
  • getMemoryUsage(): Retrieves total, free, and used memory information.
  • getDiskUsage(): Fetches disk usage statistics including total, used, and available space.
  • getNetworkInfo(): Returns details about all network interfaces.
  • getSystemUptime(): Returns the system uptime in seconds.
  • getProcessInfo(): Provides the CPU and memory usage of the current process.
  • getTemperature(): Returns the system temperature (if supported).
  • getLogs(path, keyword): Fetches logs from the specified file, optionally filtering by a keyword.

Example Response

  • CPU Information
{
  "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...
  ]
}
  • Memory Usage
{
    "totalMemory": 16777216,
    "freeMemory": 8388608,
    "usedMemory": 8388608
}
  • Disk Usage
{
  "total": 104857600,
  "used": 52428800,
  "available": 52428800
}

Options

The systemMonitor middleware accepts an object with the following options:

Options

The systemMonitor middleware accepts an object with the following options:

OptionTypeDefaultDescription
cpubooleantrueEnable CPU usage monitoring.
memorybooleantrueEnable memory usage monitoring.
diskbooleantrueEnable disk usage monitoring.
networkbooleantrueEnable network interface information monitoring.
uptimebooleantrueEnable system uptime monitoring.
processInfobooleantrueEnable process CPU and memory usage monitoring.
temperaturebooleanfalseEnable system temperature monitoring (only on Linux/Windows).
logs{ path: string, keyword?: string }nullFetch logs from a specified file, optionally filtered by keyword.
responseTimebooleanfalseTrack response time for each request.

FAQs

Package last updated on 13 Sep 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc