This Python script monitors NVIDIA GPU memory usage and sends email notifications when available memory exceeds a specified threshold.
- Python 3.x
- NVIDIA GPU
- NVIDIA drivers installed
- Gmail account (for sending notifications)
- Install the required Python packages:
pip install -r requirements.txt- Create a
dev.envfile in the project directory with your email credentials:
EMAIL=your.email@gmail.com
SMTP_USER=your.email@gmail.com
SMTP_PASS=your_app_password
Important Note: For Gmail, you need to use an App Password instead of your regular password. To generate an App Password:
- Go to your Google Account settings
- Navigate to Security
- Enable 2-Step Verification if not already enabled
- Generate an App Password for "Mail"
See Google's guide on generating App Passwords here: https://support.google.com/accounts/answer/185833?hl=en&authuser=1
Run the script with default settings:
python gpu_monitor.py--interval: Polling interval in seconds (default: 60)--threshold: Free memory threshold in MB (default: 6000)--once: Run once and exit (default: True)--smtp-server: SMTP server address (default: smtp.gmail.com)--smtp-port: SMTP server port (default: 587)--server_name: Server name for email notifications (default: NTU_51)
Example with custom settings:
python gpu_monitor.py --interval 60 --threshold 6000 --once --server_name "MY_SERVER"The script will:
- Check available memory on all NVIDIA GPUs
- Send an email notification when a GPU has free memory above the specified threshold
- Exit after one check (with
--once) or continue monitoring at the specified interval
You'll receive an email notification when a GPU has available memory above the threshold. The email will include:
- The server name
- GPU ID
- Amount of available memory