Resource Manager
System resource monitoring and optimization tool for managing CPU, memory, and disk usage across Linux systems.
Resource Manager Tool
Overview
The Resource Manager is a powerful system administration tool designed to monitor, manage, and optimize system resources across different operating systems. It provides comprehensive resource monitoring, limit setting, and optimization capabilities for system administrators.
Features
Resource Monitoring
- Real-time CPU, memory, and disk usage monitoring
- Cross-platform support (Linux, macOS)
- Detailed metrics collection and storage
- Continuous monitoring with configurable intervals
- Historical data tracking
Resource Management
- CPU usage limits using cgroups (Linux)
- Memory usage limits
- Disk usage monitoring and alerts
- Service-specific resource optimization
- Automatic resource cleanup
Reporting
- HTML reports with interactive charts
- JSON format for programmatic analysis
- Daily, weekly, and monthly report generation
- Customizable report formats
- Historical trend analysis
Service Optimization
- MySQL optimization
- Nginx configuration tuning
- Apache performance tuning
- Redis resource management
- Cross-platform service management
Installation
Prerequisites
- Bash shell
- Basic system utilities (top, free, df)
- yq (optional, for YAML configuration)
- Chart.js (for HTML reports)
Installation Steps
Clone the repository:
git clone <repository-url> cd admin-tools
Make the script executable:
chmod +x resource-manager.sh
Install dependencies:
- For Linux:
sudo apt-get install sysstat # For Debian/Ubuntu sudo yum install sysstat # For RHEL/CentOS
- For macOS:
brew install sysstat
- For Linux:
Create configuration directory:
mkdir -p ~/.config/resource-manager
Download the script from the Lambda Softworks Customer Portal:
- Log in to your Lambda Softworks Customer Portal account
- Navigate to the Files section
- Download the resource-manager.sh script
Usage
Basic Commands
Check current resource usage:
./resource-manager.sh --status
Set resource limits:
./resource-manager.sh --limit-cpu 80 --limit-memory 90
Generate a daily report:
./resource-manager.sh --report daily
Optimize specific services:
./resource-manager.sh --optimize --target-services mysql,nginx
Monitor resources continuously:
./resource-manager.sh --monitor --interval 30 --duration 7200
Command Line Options
--status
: Show current resource usage--limit-cpu N
: Set CPU usage limit to N%--limit-memory N
: Set memory usage limit to N%--limit-disk N
: Set disk usage limit to N%--report [daily|weekly|monthly]
: Generate resource usage report--format [html|json]
: Report format (default: html)--optimize
: Apply recommended resource optimizations--target-services S1,S2,...
: Target specific services for optimization--monitor
: Monitor resources continuously--interval N
: Monitoring interval in seconds (default: 60)--duration N
: Monitoring duration in seconds (default: 3600)--config FILE
: Use custom configuration file--help
: Show help message
Configuration
Configuration File
The tool uses a YAML configuration file located at ~/.config/resource-manager/config.yml
. Example configuration:
# Default thresholds cpu_warning: 80 cpu_critical: 90 memory_warning: 85 memory_critical: 95 disk_warning: 85 disk_critical: 95 # Monitoring settings default_interval: 60 default_duration: 3600 # Service configurations services: mysql: max_connections: 100 buffer_pool_size: 1G nginx: worker_processes: auto worker_connections: 1024
Log Files
- Main log:
~/.local/log/resource-manager.log
- Reports:
~/.local/share/resource-manager/reports/
- Metrics:
~/.local/share/resource-manager/metrics/
Cross-Platform Compatibility
Linux Support
- RHEL/CentOS
- Ubuntu/Debian
- Other Linux distributions with systemd
macOS Support
- macOS 10.15 and later
- Homebrew package management
- Native system monitoring
Examples
Basic Usage
# Check system status ./resource-manager.sh --status # Set resource limits ./resource-manager.sh --limit-cpu 80 --limit-memory 90 # Generate daily report ./resource-manager.sh --report daily --format html
Advanced Usage
# Monitor with custom interval ./resource-manager.sh --monitor --interval 30 --duration 7200 # Optimize multiple services ./resource-manager.sh --optimize --target-services mysql,nginx,redis # Generate JSON report for analysis ./resource-manager.sh --report weekly --format json
Troubleshooting
Common Issues
Permission Errors
- Ensure the script is run with sudo
- Check directory permissions
- Verify user has necessary privileges
Resource Issues
- Verify resource limits
- Check process permissions
- Review system resources
Report Generation Issues
- Check log directory permissions
- Verify HTML template access
- Check disk space
Debug Mode
To enable debug logging:
sudo DEBUG=1 ./resource-manager.sh [OPTIONS]