Skip to content

itsmehmaaz/AI-Powered-Resource-Monitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧠 AI-Powered System Resource Monitor

A genuinely AI-powered, Linux-based system resource monitor implemented in C that uses machine learning techniques for intelligent predictions and anomaly detection.

🤖 AI/ML Features

This project implements real machine learning algorithms:

Feature Algorithm Description
EWMA Prediction Exponentially Weighted Moving Average Gives more weight to recent data for smooth predictions
Anomaly Detection Gaussian Model (Unsupervised Learning) Learns "normal" behavior and detects unusual patterns
Pattern Learning Time-of-Day Profiling Learns typical usage for each hour of the day
Adaptive Thresholds Percentile-Based Learning Thresholds that adapt to your system's actual workload
Model Persistence Binary Serialization AI model saved/loaded across restarts

The system learns from your usage patterns and improves predictions over time.

📋 Core Features

  • Real-time Monitoring: CPU, Memory, and Disk usage from /proc filesystem
  • Proactive Alerts: Warns based on predicted (not current) usage
  • CSV Logging: Historical data saved for analysis
  • Learning Progress: Visual indicator showing AI training status
  • Configurable: Adjust thresholds, intervals, and paths

🏗️ Project Structure

AI Powered Resource Monitor/
├── include/
│   ├── ai_engine.h      # 🧠 AI/ML algorithms
│   ├── alerter.h        # Alert system
│   ├── config.h         # Configuration
│   ├── cpu_monitor.h    # CPU monitoring
│   ├── data_logger.h    # CSV logging
│   ├── disk_monitor.h   # Disk monitoring
│   ├── mem_monitor.h    # Memory monitoring
│   └── predictor.h      # Basic predictions
├── src/
│   ├── ai_engine.c      # 🧠 EWMA, Anomaly Detection, Pattern Learning
│   ├── alerter.c        # Alert implementation
│   ├── config.c         # Config loading
│   ├── cpu_monitor.c    # /proc/stat reader
│   ├── data_logger.c    # CSV writer
│   ├── disk_monitor.c   # statvfs implementation
│   ├── main.c           # Main loop with AI integration
│   ├── mem_monitor.c    # /proc/meminfo reader
│   └── predictor.c      # Moving average, linear trend
├── logs/
│   ├── resource_history.csv  # Data log
│   ├── alerts.log            # Alert history
│   └── ai_model.dat          # 🧠 Saved AI model
├── config.txt
├── Makefile
├── DESIGN.md
└── README.md

🚀 Quick Start (Windows WSL)

# 1. Install WSL (PowerShell as Admin)
wsl --install

# 2. After restart, open WSL
wsl

# 3. Install build tools
sudo apt update && sudo apt install build-essential

# 4. Navigate to project
cd /mnt/d/Downloads/AI\ Powered\ Resource\ Monitor

# 5. Build and run
make clean && make
./resource_monitor

📊 Sample Output

╔══════════════════════════════════════════════════════════════════════╗
║         🧠 AI-Powered System Resource Monitor 🧠                   ║
╠══════════════════════════════════════════════════════════════════════╣
║  ✓ EWMA Prediction      ✓ Anomaly Detection    ✓ Pattern Learning  ║
║  ✓ Adaptive Thresholds  ✓ Model Persistence    ✓ Proactive Alerts  ║
╚══════════════════════════════════════════════════════════════════════╝

  📅 2025-12-28 23:00:45    🧠 Learning: [████████████░░░░░░░░] 60%    🎯 Confidence: 75%

┌─────────────┬──────────┬──────────┬──────────┬──────────┬──────────┐
│   METRIC    │ CURRENT  │   EWMA   │ EXPECTED │THRESHOLD │  STATUS  │
├─────────────┼──────────┼──────────┼──────────┼──────────┼──────────┤
│ 🔲 CPU      │  45.2%   │  48.1%   │  52.3%   │  80.0%   │      OK  │
│ 💾 Memory   │  68.5%   │  69.2%   │  67.0%   │  75.0%   │ WARNING  │
│ 💿 Disk     │  34.8%   │  34.8%   │  34.5%   │  90.0%   │      OK  │
└─────────────┴──────────┴──────────┴──────────┴──────────┴──────────┘

🔍 Anomaly Detection
┌─────────────┬─────────┬──────────┬──────────┬────────────────────────┐
│   METRIC    │ Z-SCORE │ EXPECTED │  ACTUAL  │         REASON         │
├─────────────┼─────────┼──────────┼──────────┼────────────────────────┤
│ CPU         │  +0.32  │  45.0%   │  45.2%   │ Normal                 │
│ Memory      │  +1.85  │  65.0%   │  68.5%   │ Normal                 │
│ Disk        │  +0.02  │  34.7%   │  34.8%   │ Normal                 │
└─────────────┴─────────┴──────────┴──────────┴────────────────────────┘

🔬 How the AI Works

1. EWMA (Exponentially Weighted Moving Average)

S_t = α * X_t + (1 - α) * S_{t-1}
  • α = 0.3 (smoothing factor)
  • More weight on recent values for responsive predictions

2. Anomaly Detection (Gaussian Model)

z_score = (value - mean) / std_dev
is_anomaly = |z_score| > 2.5
  • Uses Welford's algorithm for online mean/variance
  • Detects values >2.5 standard deviations from normal

3. Time-of-Day Pattern Learning

  • Maintains 24 statistical buckets (one per hour)
  • Learns "normal" usage patterns for each hour
  • Detects anomalies specific to time of day

4. Adaptive Thresholds

warning_threshold = 90th_percentile * 1.1
critical_threshold = 99th_percentile * 1.05
  • Learns from actual usage instead of fixed values

🧪 Testing

# Generate CPU load
stress --cpu 4 --timeout 60

# Generate memory load
stress --vm 2 --vm-bytes 1G --timeout 60

Watch the AI detect these as anomalies!

📚 OS Concepts

Concept Implementation
/proc filesystem CPU & memory stats from kernel
System calls statvfs() for disk stats
Signal handling Graceful shutdown, model saving
File I/O CSV logging, model persistence
Online algorithms Welford's algorithm for streaming stats

📜 License

MIT License - Free for educational use.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors