Skip to content

Sen-Se1/monitoring-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

28 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” System Monitoring and Auto-Healing Solution

Python 3.8+ License: MIT Dash psutil

A comprehensive proactive monitoring and auto-healing system for DevOps environments, developed in Python with real-time web interface.

✨ Features

🎯 Real-time Monitoring

  • πŸ“Š System Metrics: CPU, memory, disk, network
  • πŸ”§ Services: Systemd service status (nginx, mysql, ssh, etc.)
  • ⏱️ Configurable Interval: From 10 seconds to several minutes

🚨 Intelligent Alert System

  • πŸ“ˆ Customizable Thresholds: Flexible alert threshold configuration
  • πŸ“§ Email Notifications: HTML formatted alerts with built-in anti-spam
  • ⚠️ Severity Levels: Warning and Critical

πŸ”§ Automatic Auto-Healing

  • πŸ”„ Service Restart: Automatic restart of stopped services
  • 🧹 Intelligent Cleanup: Temporary files and cache management
  • πŸ’Ύ Memory Optimization: Termination of memory-hungry processes

πŸ“Š Interactive Dashboard

  • 🌐 Web Interface: Dashboard accessible at http://localhost:8050
  • πŸ“ˆ Real-time Charts: Interactive visualizations with Plotly
  • πŸ”„ Auto Refresh: Updates every 5 seconds

πŸš€ Quick Start

Prerequisites

  • Python 3.8 or higher
  • Administrator access (for service monitoring)
  • Port 8050 available

Automatic Installation

🐧 Linux / macOS

chmod +x start.sh
./start.sh

πŸͺŸ Windows

.\start.ps1

Manual Installation

# Create virtual environment
python -m venv venv

# Activation (Linux/macOS)
source venv/bin/activate

# Activation (Windows)
venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Create directories
mkdir -p logs

Configuration

Create a .env file:

# Monitoring
MONITORING_INTERVAL=10
CPU_THRESHOLD=80.0
MEMORY_THRESHOLD=85.0
DISK_THRESHOLD=90.0

# Services to monitor
MONITORED_SERVICES=cron,dbus,apache2,nginx,mysql

# Auto-healing
AUTO_HEALING_ENABLED=True

# Email (optional)
EMAIL_ALERTS_ENABLED=True
EMAIL_SMTP_SERVER=smtp.gmail.com
EMAIL_SENDER=your@email.com
EMAIL_SENDER_PASSWORD=your_app_password
EMAIL_RECIPIENTS=alert@company.com

🎯 Usage

Complete Launch

python main.py

The system starts and the dashboard is accessible at: http://localhost:8050

Individual Modules

Monitoring Only

python monitoring/monitor.py

Dashboard Only

python visualization/dashboard.py

πŸ“ Project Structure

monitoring-system/
β”œβ”€β”€ πŸ“Š main.py                    # Main entry point
β”œβ”€β”€ πŸ“‹ requirements.txt          # Python dependencies
β”œβ”€β”€ πŸ” .env                      # Configuration
β”œβ”€β”€ πŸš€ start.ps1                 # Windows installation
β”œβ”€β”€ 🐧 start.sh                  # Linux installation
β”‚
β”œβ”€β”€ πŸ“ monitoring/               # Monitoring modules
β”‚   β”œβ”€β”€ πŸ–₯️ system_monitor.py    # System metrics
β”‚   β”œβ”€β”€ πŸ”Œ service_monitor.py   # Service monitoring
β”‚   β”œβ”€β”€ 🚨 alert_manager.py     # Alert management
β”‚   └── πŸ”§ monitor.py           # Main orchestrator
β”‚
β”œβ”€β”€ πŸ“ visualization/            # Interface
β”‚   └── πŸ“ˆ dashboard.py         # Web dashboard
β”‚
β”œβ”€β”€ πŸ“ config/                   # Configuration
β”‚   └── βš™οΈ settings.py          # Application parameters
β”‚
β”œβ”€β”€ πŸ“ autohealing/              # Auto-healing
β”‚   β”œβ”€β”€ πŸ”§ service_healer.py    # Service repair
β”‚   β”œβ”€β”€ πŸ› οΈ system_healer.py    # System repair
β”‚   β”œβ”€β”€ πŸ“ action_logger.py    # Action logging
β”‚   └── ⚑ triggers.py          # Triggers
β”‚
β”œβ”€β”€ πŸ“ utils/                    # Utilities
β”‚   β”œβ”€β”€ πŸ“ json_array_logger.py # JSON logger
β”‚   └── πŸ“§ email_sender.py     # Email sending
β”‚
└── πŸ“ logs/                     # Data
    └── πŸ“„ monitoring.json      # Structured JSON logs

πŸ›  Technologies Used

Language & Core

  • Python 3.8+ - Main language
  • Virtual Environment - Dependency isolation

Monitoring & Metrics

  • psutil - System metrics (CPU, memory, disk, network)
  • subprocess - Systemd service management
  • platform - OS detection and hardware information

Visualization & Interface

  • Dash - Web framework for analytical applications
  • Plotly - Interactive real-time charts
  • Pandas - Data manipulation and analysis
  • Dash Bootstrap Components - Responsive UI

Data & Logging

  • JSON - Structured logging format
  • datetime - Timestamp management
  • threading - Parallel execution

Notification & Communication

  • smtplib - Email sending via SMTP/TLS
  • email.mime - HTML message formatting

Configuration

  • python-dotenv - Environment variables
  • os - Filesystem interactions

πŸ“Š Output Examples

Monitoring Console

πŸ”„ Monitoring cycle #1
πŸ“Š [2024-01-15 10:30:00] System metrics:
   CPU: 45.2% | Memory: 67.8% | Disk: 82.1%
πŸ”§ Service status:
   🟒 cron: Active
   🟒 dbus: Active
   πŸ”΄ nginx: Stopped
🚨 ALERTS:
   πŸ”΄ Service nginx is stopped
πŸ”§ AUTO-HEALING ACTIONS:
   βœ… service_restart: Service nginx restarted successfully

Structured JSON Logs

{
  "timestamp": "2024-01-15T10:30:00.000000",
  "event_type": "action",
  "action_type": "service_restart",
  "status": "SUCCESS",
  "service": "nginx",
  "message": "Service nginx restarted successfully"
}

πŸ› Troubleshooting

Common Issues

❌ "systemctl not found" (Windows)

Solution: Adapt service_monitor.py to use PowerShell

πŸ“§ Emails not received

Check:

  • SMTP settings in .env
  • Gmail app password
  • Firewall/antivirus

πŸ“Š Dashboard inaccessible

Check:

  • Port 8050 available
  • logs/monitoring.json file exists

Diagnostic Commands

# Check logs
tail -f logs/monitoring.json

# Test metrics
python -c "import psutil; print(f'CPU: {psutil.cpu_percent()}%')"

# Check services
systemctl status nginx mysql

πŸš€ Development

Contribution

Contributions are welcome!

  1. Fork the project
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Development Structure

# Development installation
pip install -r requirements.txt
pip install -e .

# Tests (to be implemented)
python -m pytest tests/

# Code validation
flake8 monitoring/ visualization/ autohealing/

πŸ“ˆ Roadmap

Upcoming Features

  • Docker container monitoring
  • Database metrics
  • Slack/Teams notifications
  • Complete REST API
  • Dashboard authentication
  • Automatic PDF reports

Technical Improvements

  • Native Windows support
  • Real-time database
  • High availability cluster
  • Machine learning for adaptive thresholds

πŸ“„ License

This project is licensed under the MIT License. See the LICENSE file for details.

πŸ‘₯ Authors

πŸ™ Acknowledgments

  • psutil - For the excellent system metrics library
  • Plotly/Dash - For interactive visualizations
  • Python - For the language and ecosystem

πŸ“ž Support

Get Started β€’ Documentation β€’ Contribute β€’ Issues


⭐ Don't forget to star the project if you find it useful!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published