Skip to content

vishnugan/Remote-System-Monitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Remote System Monitor

Overview

This project collects system metrics (CPU, memory, disk usage) from multiple remote servers via SSH and logs the data to Logstash for centralized analysis.

Available Files

  • remote_monitor.py – Python script for collecting remote system metrics and logging them to Logstash.
  • .env – Environment variables configuration file for setting up the script.
  • requirements.txt – Required Python packages for running the script.
  • Dockerfile – Docker configuration to containerize the script.
  • README.md – Documentation for setup, usage, and deployment.

What the Script Does

  1. Reads a list of remote servers from the .env file.
  2. Uses SSH with an RSA private key to access each server.
  3. Executes system monitoring commands remotely.
  4. Collects CPU, memory, and disk usage metrics.
  5. Logs metrics to Logstash for centralized monitoring.
  6. Runs only once per execution.

How to Build

docker build -t remote-monitor .

How to Deploy

Running the Python Script Directly

Ensure .env is configured, then execute:

pip install -r requirements.txt
python remote_monitor.py

Running the Docker Container

Use the .env file and run the container:

docker run --rm --env-file .env remote-monitor

To schedule a cron job on the host system to run the container every hour. Append the following line to the crontab

0 * * * * docker run --rm --env-file /path/to/.env remote-monitor
  • 0 * * * * → Runs at the start of every hour.
  • docker run --rm → Runs the container, cleans up after execution.
  • --env-file /path/to/.env → Uses environment variables for execution.

Required Environment Variables

Define these values in the .env file:

LOGSTASH_HOST=<LOGSTASH_SERVER_HOSTNAME>  # Logstash server hostname or IP
LOGSTASH_PORT=<LOGSTASH_SERVER_PORT>      # Logstash server port. Default: 5044
PRIVATE_KEY_PATH=/path/to/key.pem         # Path to RSA private key for SSH authentication
USERNAME=<USERNAME>                       # SSH username for remote servers
REMOTE_HOSTS=host1.example.com,host2.example.com,host3.example.com  # Comma-separated list of remote servers

Logstash configuration - reference

  1. Receives Logs: Listens on TCP port 5044 (matching the Python script's Logstash handler).
  2. Parses JSON: Uses the JSON codec to process structured logs.
  3. Formats Data:
    • Converts CPU and memory usage to float.
    • Stores disk usage as string (since it may contain %).
  4. Stores in Elasticsearch:
    • Sends parsed logs to an Elasticsearch cluster.
    • Uses daily index naming (remote-system-metrics-YYYY.MM.dd).
    • Supports authentication if required.

About

This project collects system metrics (CPU, memory, disk usage) from multiple remote servers via SSH and logs the data to Logstash for centralized analysis.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors