1.0.6 • Published 10 months ago

@eslam3400/system-monitoring v1.0.6

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

System Monitoring Tool

Description

This is a system monitoring tool that monitors CPU, memory, and disk usage and sends alerts to a Slack channel when usage exceeds specified thresholds. It's designed to be used as a standalone command-line application.

Features

  • CPU Monitoring: Monitors CPU usage and sends alerts when it exceeds a specified threshold.
  • Memory Monitoring: Monitors memory usage and sends alerts when it exceeds a specified threshold.
  • Disk Monitoring: Monitors disk usage and sends alerts when it exceeds a specified threshold.
  • Slack Integration: Sends alerts to a specified Slack channel.
  • Configurable Thresholds: Thresholds for CPU, memory, and disk usage can be configured via environment variables.
  • Logging: Logs system metrics and errors to the console (optional).

Installation

  1. Install Node.js: Ensure you have Node.js installed on your system. You can download it from https://nodejs.org/.

  2. Install the package globally:

    npm install -g @eslam3400/system-monitoring

Configuration

The following environment variables are required:

  • SM_APP_NAME: The name of your application (e.g., "My Server"). This will be included in the Slack messages and logs.
  • SM_CPU_THRESHOLD: The CPU usage threshold (in percentage) that triggers an alert (e.g., "80").
  • SM_MEMORY_THRESHOLD: The memory usage threshold (in percentage) that triggers an alert (e.g., "75").
  • SM_DISK_THRESHOLD: The disk usage threshold (in percentage) that triggers an alert (e.g., "90").
  • SM_CHECK_INTERVAL: The interval (in milliseconds) between system checks (e.g., "5000").
  • SM_SLACK_BOT_TOKEN: Your Slack bot token (required for sending alerts to Slack). You can create a Slack bot and obtain a token from the Slack API website.
  • SM_SLACK_CHANNEL_ID: The ID of the Slack channel to send alerts to.
  • SM_SLACK_ALERT_INTERVAL: The interval (in hours) between Slack alerts for the same issue (e.g., "6"). This prevents alert spamming.

The following environment variable is optional:

  • SM_LOGS: Set to "true" to enable logging system metrics to the console. Defaults to "false".

Setting Environment Variables

You can set these variables in your .bashrc, .zshrc, or directly in your terminal. After modifying these files, you'll need to reload your shell configuration (e.g., by running source ~/.bashrc or source ~/.zshrc) for the changes to take effect:

export SM_APP_NAME="My Server"
export SM_CPU_THRESHOLD="80"
export SM_MEMORY_THRESHOLD="75"
export SM_DISK_THRESHOLD="90"
export SM_CHECK_INTERVAL="5000"
export SM_SLACK_BOT_TOKEN="xoxb-YOUR_SLACK_BOT_TOKEN"
export SM_SLACK_CHANNEL_ID="YOUR_SLACK_CHANNEL_ID"
export SM_SLACK_ALERT_INTERVAL="6"
export SM_LOGS="true"

Or, you can create a .env file in the directory where you run the system-monitoring command:

SM_APP_NAME=My Server
SM_CPU_THRESHOLD=80
SM_MEMORY_THRESHOLD=75
SM_DISK_THRESHOLD=90
SM_CHECK_INTERVAL=5000
SM_SLACK_BOT_TOKEN=xoxb-YOUR_SLACK_BOT_TOKEN
SM_SLACK_CHANNEL_ID=YOUR_SLACK_CHANNEL_ID
SM_SLACK_ALERT_INTERVAL=6
SM_LOGS=true

Usage

To start the system monitoring tool, simply run the following command in your terminal:

system-monitoring

To stop the monitoring tool, press Ctrl+C in the terminal.

Running in the Background and on Startup with PM2

PM2 is a process manager for Node.js applications that allows you to run your application in the background and automatically restart it if it crashes. It's ideal for ensuring your system monitoring tool is always running.

  1. Install PM2:

    npm install -g pm2
  2. Start the System Monitoring Tool with PM2:

    Navigate to the directory where you want to run the system-monitoring command and then use PM2 to start the process:

    pm2 start system-monitoring --name system-monitoring

    This command starts the system-monitoring tool and names the process "system-monitoring".

  3. Ensure PM2 Starts on Boot:

    To make sure PM2 starts automatically when your system boots, run the following command:

    pm2 startup

    PM2 will provide you with a command to run (specific to your operating system) to set up the startup script. Follow the instructions PM2 gives you.

  4. Save the Current PM2 Process List:

    After setting up the startup script, save the current process list:

    pm2 save
  5. Stopping and Restarting:

    You can stop and restart the monitoring tool using PM2:

    pm2 stop system-monitoring
    pm2 restart system-monitoring
  6. Monitoring PM2 Logs:

    To view the logs of the system monitoring tool managed by PM2:

    pm2 logs system-monitoring

Now, the system monitoring tool will run in the background, restart automatically if it crashes, and start automatically on system boot.

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago