A smart GPU monitor that sends email alerts for idle, stuck, or overheating GPUs. Perfect for managing shared GPU resources and ensuring your jobs are running smoothly.
- Real-time Monitoring: Tracks GPU utilization, memory usage, temperature, and power consumption.
- Idle Detection: Notifies you via email when a GPU becomes idle and is ready for new tasks.
- Stuck Job Detection: Alerts you if a GPU job appears to be stuck (i.e., utilization and memory are static for a period).
- High-Temperature Alerts: Sends a warning if a GPU's temperature exceeds a safe threshold (default: 85°C).
- Smart Notifications: Avoids spam by sending notifications for the same event only once every 30 minutes.
- Easy Setup: Includes an interactive startup script and a configuration tester.
- Logging: Logs all activities and alerts to both the console and a
gpu_monitor.logfile.
1. Prerequisites
- Python 3.6+
- NVIDIA drivers with
nvidia-smicommand available.
2. Configure Email
- Copy the template:
cp email_config_template.json email_config.json - Edit
email_config.jsonwith your email provider's details. For QQ Mail, you need to generate an "app-specific password".
3. Test Configuration
- Make the test script executable:
chmod +x test_config.py - Run the tester to verify
nvidia-smiand your email settings:Follow the prompts to send a test email../test_config.py
4. Run the Monitor
- Make the start script executable:
chmod +x start_monitor.sh - Launch the interactive monitor:
The script will ask which GPUs to monitor and the check interval.
./start_monitor.sh
Direct Execution You can also run the main script directly with command-line arguments:
# Monitor GPU 0 and 1, checking every 60 seconds
python3 gpu_monitor.py --gpus 0 1 --interval 60
# Specify a custom config file
python3 gpu_monitor.py --gpus 0 --config my_config.jsonCommand-line Arguments:
--gpus: (Required) A list of GPU IDs to monitor (e.g.,0 1 2).--interval: (Optional) The check interval in seconds. Default:30.--config: (Optional) Path to the email configuration file. Default:email_config.json.
Find it helpful? Please ⭐ 😉
一个智能GPU监控脚本,可在GPU空闲、卡死或过热时发送邮件通知。非常适合管理共享GPU资源,确保任务顺利运行。
- 实时监控: 跟踪GPU使用率、显存使用、温度和功耗。
- 空闲检测: 当GPU变为空闲状态时,通过邮件通知您,以便分配新任务。
- 卡死检测: 如果GPU任务疑似卡死(使用率和显存长时间无变化),则发送警报。
- 高温警报: 当GPU温度超过安全阈值(默认85°C)时发送警告。
- 智能通知: 避免重复发送邮件,同一类型事件的通知间隔为30分钟。
- 简易设置: 包含交互式启动脚本和配置测试工具。
- 日志记录: 所有活动和警报都会输出到控制台并记录在
gpu_monitor.log文件中。
1. 环境要求
- Python 3.6+
- 已安装NVIDIA驱动,且
nvidia-smi命令可用。
2. 配置邮箱
- 复制模板文件:
cp email_config_template.json email_config.json - 编辑
email_config.json,填入您的邮箱信息。对于QQ邮箱,您需要生成一个“应用专用密码”(授权码)。
3. 测试配置
- 为测试脚本添加执行权限:
chmod +x test_config.py - 运行测试脚本,验证
nvidia-smi和邮箱配置:根据提示发送一封测试邮件以确认配置无误。./test_config.py
4. 运行监控
- 为启动脚本添加执行权限:
chmod +x start_monitor.sh - 启动交互式监控程序:
脚本会提示您输入要监控的GPU编号和检查间隔。
./start_monitor.sh
直接运行 您也可以直接通过命令行参数运行主脚本:
# 监控GPU 0和1,每60秒检查一次
python3 gpu_monitor.py --gpus 0 1 --interval 60
# 指定自定义配置文件
python3 gpu_monitor.py --gpus 0 --config my_config.json命令行参数:
--gpus: (必需) 要监控的GPU ID列表 (例如:0 1 2)。--interval: (可选) 检查间隔(秒)。默认:30。--config: (可选) 邮箱配置文件的路径。默认:email_config.json。
好用记得给 ⭐ 😉