System Monitor
Real-time system monitoring and alerting tool for Linux systems with interactive dashboard and comprehensive reporting.
System Monitor
A comprehensive system monitoring tool that provides real-time monitoring, alerting, and reporting capabilities for Linux and macOS systems.
Features
Real-time Monitoring
- CPU usage and temperature monitoring
- Memory usage and swap monitoring
- Disk usage and I/O monitoring
- Network traffic and connection monitoring
- Process monitoring and management
- Service status monitoring
Alerting System
- Configurable thresholds for resource usage
- Multiple alert severity levels (info, warning, critical)
- Email notifications
- Slack integration
- Customizable alert intervals
- JSON-based alert storage
Reporting
- HTML reports with interactive charts
- JSON reports for programmatic analysis
- Historical data tracking
- Customizable report intervals
- Process and service status reports
Interactive Dashboard
- Real-time system metrics visualization
- Responsive web interface
- Auto-updating charts and tables
- Customizable port and host settings
- Mobile-friendly design
Cross-Platform Support
- Linux (RHEL, Debian, and variants)
- macOS
- Consistent metrics collection across platforms
- Platform-specific optimizations
Installation
Prerequisites
- Bash shell
- Python 3 (for dashboard)
- jq (for JSON processing)
- yq (for YAML processing, optional)
Installation Steps
- Clone the repository:
git clone https://github.com/yourusername/lambda-scripts.git cd lambda-scripts/admin-tools
- Make the script executable:
chmod +x system-monitor.sh
- Install dependencies:
For Debian/Ubuntu:
sudo apt-get update sudo apt-get install -y python3 jq
For RHEL/CentOS:
sudo yum install -y python3 jq
For macOS:
brew install python3 jq
- Create configuration file (optional):
mkdir -p ~/.config/system-monitor cat > ~/.config/system-monitor/config.yml << EOF interval: 60 threshold: 80 slack_webhook_url: "https://hooks.slack.com/services/your/webhook/url" email_notifications: true EOF
Usage
Basic Usage
- Start monitoring:
./system-monitor.sh --monitor
- Generate HTML report:
./system-monitor.sh --report html
- Start interactive dashboard:
./system-monitor.sh --dashboard 8080
Advanced Usage
- Monitor with custom interval and threshold:
./system-monitor.sh --monitor 30 85
- Generate JSON report:
./system-monitor.sh --report json
- Use custom configuration file:
./system-monitor.sh --config /path/to/config.yml --monitor
Command Line Options
--monitor [interval] [threshold]
: Start monitoring with optional interval and threshold--report [html|json]
: Generate system report in specified format--dashboard [port]
: Start interactive dashboard on specified port--config FILE
: Use custom configuration file--help
: Show help message
Configuration
Configuration File Location
- Default:
~/.config/system-monitor/config.yml
- Custom: Specified via
--config
option
Configuration Options
# Monitoring settings interval: 60 # Monitoring interval in seconds threshold: 80 # Alert threshold percentage # Notification settings email_notifications: true # Enable email notifications slack_webhook_url: "" # Slack webhook URL for notifications # Dashboard settings dashboard_port: 8080 # Dashboard port number dashboard_host: "0.0.0.0" # Dashboard host address # Service monitoring monitored_services: # List of services to monitor - sshd - nginx - apache2 - mysql - postgresql
Logs and Data Storage
Log File Location
- Linux:
~/.local/log/system-monitor.log
- macOS:
~/Library/Logs/system-monitor.log
Metrics Storage
- Location:
~/.local/share/system-monitor/metrics/
- Format: JSON files with timestamps
- Retention: Configurable (default: 7 days)
Alerts Storage
- Location:
~/.local/share/system-monitor/alerts/
- Format: JSON files with timestamps
- Retention: Configurable (default: 30 days)
Reports Storage
- Location:
~/.local/share/system-monitor/reports/
- Format: HTML and JSON files
- Retention: Configurable (default: 90 days)
Cross-Platform Compatibility
Linux Support
- RHEL/CentOS 7+
- Ubuntu 18.04+
- Debian 10+
- Other Linux distributions with systemd
macOS Support
- macOS 10.15+
- Intel and Apple Silicon Macs
- Native macOS services support
Examples
Basic Monitoring
# Start monitoring with default settings ./system-monitor.sh --monitor # Monitor with custom interval (30s) and threshold (85%) ./system-monitor.sh --monitor 30 85
Report Generation
# Generate HTML report ./system-monitor.sh --report html # Generate JSON report ./system-monitor.sh --report json
Dashboard Usage
# Start dashboard on default port (8080) ./system-monitor.sh --dashboard # Start dashboard on custom port ./system-monitor.sh --dashboard 9090
Custom Configuration
# Use custom config file ./system-monitor.sh --config /path/to/config.yml --monitor # Monitor specific services ./system-monitor.sh --monitor --services nginx,mysql,postgresql
Troubleshooting
Common Issues
- Permission Issues
# Fix log directory permissions mkdir -p ~/.local/log chmod 755 ~/.local/log # Fix metrics directory permissions mkdir -p ~/.local/share/system-monitor/metrics chmod 755 ~/.local/share/system-monitor/metrics
- Dashboard Not Starting
# Check Python installation python3 --version # Check port availability lsof -i :8080 # Start with verbose logging ./system-monitor.sh --dashboard --debug
- Alert Notifications Not Working
# Check email configuration echo "Test email" | mail -s "Test" root # Check Slack webhook curl -X POST -H 'Content-type: application/json' --data '{"text":"Test"}' $SLACK_WEBHOOK_URL
Debug Mode
To enable debug logging:
sudo DEBUG=1 ./system-monitor.sh [OPTIONS]