An open API service indexing awesome lists of open source software.

https://github.com/maxlab/systemmonitor

Lenovo Legion Pro System Monitor Suite
https://github.com/maxlab/systemmonitor

lenovo-legion-5-pro linux linux-sensors linux-sesor-monitor

Last synced: about 2 months ago
JSON representation

Lenovo Legion Pro System Monitor Suite

Awesome Lists containing this project

README

          

# Legion System Monitor Suite

**Advanced hardware monitoring tools specifically designed for Lenovo Legion 5 Pro gaming laptops**

[![Python](https://img.shields.io/badge/Python-3.7+-blue.svg)](https://python.org)
[![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
[![Hardware](https://img.shields.io/badge/Hardware-Legion%205%20Pro-red.svg)](https://www.lenovo.com/legion)
[![GPU](https://img.shields.io/badge/GPU-RTX%203070-brightgreen.svg)](https://www.nvidia.com)

## 🎯 Purpose

Diagnose and monitor **Lenovo Legion 5 Pro screen disconnection issues** through comprehensive hardware monitoring, specifically targeting thermal throttling and GPU stability problems that cause display disconnections during gaming sessions.

## 🚀 Quick Start

```bash
# Clone the repository
git clone https://github.com/Maxlab/systemmonitor.git
cd systemmonitor

# Run the enhanced Legion monitor
python3 enhanced_legion_monitor.py

# Or use the interactive launcher
chmod +x start_monitor.sh
./start_monitor.sh
```

## 📊 Features

### 🔥 Advanced Temperature Monitoring
- **Multi-source CPU monitoring**: lm-sensors, thermal zones, direct hwmon access
- **Direct k10temp access** for AMD Ryzen 7 5800H
- **NVMe SSD temperature monitoring** with critical threshold parsing
- **Hardware-defined critical temperatures** from system files

### 🎮 Comprehensive GPU Analytics
- **Multi-method GPU detection**: nvidia-smi, proc files, lspci validation
- **RTX 3070 Mobile optimization** with throttling detection
- **Driver version reporting** and compatibility checking
- **Safe parsing** of GPU metrics with graceful fallback

### ⚡ Power System Monitoring
- **Battery voltage monitoring** with AC/battery status detection
- **Power delivery analysis** for mobile gaming platform
- **Charging status** and power source identification

### 🖥️ Beautiful Terminal Interface
```
┌─ LEGION 5 PRO FULL MONITOR v6.0 ────────────────────────────────────┐
│ 🔥 CPU (AMD Ryzen 7 5800H): 52.3°C (Critical: 90°C) - k10temp │
│ 🎮 GPU (RTX 3070 Laptop): 48.1°C - Driver: 525.60.11 │
│ 💾 NVMe SSD: 45.2°C (Critical: 85°C) - hwmon2 │
│ ⚡ Power: 19.2V (AC Connected) - Battery: 95% │
│ 📊 Memory: 15.2GB/32GB (47%) │ 💿 Disk: 245GB/512GB (48%) │
│ 🚨 Alerts: 0 │ ⏱️ Runtime: 00:15:32 │ 📈 Samples: 468 │
└──────────────────────────────────────────────────────────────────────┘
```

## 🛠️ Installation

### Prerequisites
- **Python 3.7+**
- **Linux** (tested on Ubuntu 24.04+)
- **Lenovo Legion 5 Pro** (optimal) or compatible hardware

### Dependencies
Dependencies are **automatically installed** when you run the script:
- `psutil` - System and process utilities
- `colorama` - Terminal color support

### Manual Installation
```bash
pip3 install psutil colorama
```

## 📖 Usage

### Enhanced Legion Monitor
```bash
# Basic monitoring
python3 enhanced_legion_monitor.py --export json

# With custom thresholds
python3 enhanced_legion_monitor.py --cpu-temp 85 --gpu-temp 80 --disk-usage 90

# Export data every 30 seconds
python3 enhanced_legion_monitor.py --interval 30 --export-interval 30
```

### Interactive Launcher
```bash
./start_monitor.sh
```
Choose from 5 preset configurations:
1. **Gaming Mode** - High thresholds for gaming sessions
2. **Diagnostic Mode** - Sensitive thresholds for problem detection
3. **Stress Test** - Extreme thresholds for hardware testing
4. **Silent Mode** - Minimal alerts for background monitoring
5. **Custom Mode** - User-defined thresholds

## 🎮 Controls

| Key | Action |
|-----|--------|
| `q` | Quit gracefully with data preservation |
| `s` | Save current state to all export formats |
| `r` | Reset alert counters and clear warnings |
| `c` | Clear screen and refresh display |

## 📁 Export Formats

### JSON (Structured Data)
```json
{
"timestamp": "2024-12-19T16:30:45",
"cpu": {
"temperature": 52.3,
"usage": 23.4,
"frequency": 3200
},
"gpu": {
"temperature": 48.1,
"usage": 67.8,
"memory_used": 4.2,
"memory_total": 8.0
}
}
```

### CSV (Time Series)
```csv
timestamp,cpu_temp,cpu_usage,gpu_temp,gpu_usage,memory_usage
2024-12-19 16:30:45,52.3,23.4,48.1,67.8,47.2
```

### TXT (Human Readable)
```
Legion System Monitor Report - 2024-12-19 16:30:45
CPU: 52.3°C (23.4% usage) - Normal
GPU: 48.1°C (67.8% usage) - Normal
Memory: 15.2GB/32GB (47%) - Normal
```

## 🏗️ Architecture

### Enhanced Legion Monitor
- **Hardware-Specific Paths**: Direct access to Legion 5 Pro sensors
- **TempReading Dataclass**: Structured temperature data with critical thresholds
- **Multi-Method Validation**: Redundant hardware detection for reliability
- **Graceful Degradation**: Works on non-Legion hardware
- **Multi-threaded Design**: Responsive UI with background monitoring
- **Rotating Buffers**: Memory-efficient long-term monitoring
- **Production-Ready**: Comprehensive error handling and signal management

## 🔧 Configuration

### Command Line Options
```bash
--cpu-temp 85 # CPU temperature threshold (°C)
--gpu-temp 80 # GPU temperature threshold (°C)
--memory-usage 80 # Memory usage threshold (%)
--disk-usage 90 # Disk usage threshold (%)
--interval 2 # Monitoring interval (seconds)
--export-interval 300 # Export interval (seconds)
```

### Configuration File
```json
{
"thresholds": {
"cpu_temperature": 85,
"gpu_temperature": 80,
"memory_usage": 80,
"disk_usage": 90
},
"monitoring": {
"interval": 2,
"export_interval": 300,
"max_history": 300
},
"display": {
"show_graphs": true,
"color_coding": true,
"unicode_boxes": true
}
}
```

## 🎯 Legion 5 Pro Optimization

### Hardware-Specific Features
- **AMD Ryzen 7 5800H**: Direct k10temp sensor access
- **RTX 3070 Mobile**: Enhanced throttling detection
- **NVMe SSD**: Multi-drive temperature monitoring
- **Battery System**: Voltage and power source monitoring

### Sensor Paths
```
CPU Temperature: /sys/class/hwmon/hwmon3/temp1_input
NVMe SSD Temps: /sys/class/hwmon/hwmon2/temp{1,2,3}_input
Battery Voltage: /sys/class/hwmon/hwmon1/in0_input
Critical Limits: /sys/class/hwmon/hwmon*/temp*_crit
```

## 🚨 Troubleshooting

### Common Issues

**No GPU detected**
```bash
# Check NVIDIA driver installation
nvidia-smi
sudo apt install nvidia-driver-570
```

**Permission denied on sensor files**
```bash
# Add user to necessary groups
sudo usermod -a -G adm,dialout,plugdev $USER
# Logout and login again
```

**Temperature sensors not found**
```bash
# Install sensor utilities
sudo apt install lm-sensors
sudo sensors-detect
```

### Screen Disconnection Diagnosis

1. **Monitor thermal throttling**:
```bash
python3 enhanced_legion_monitor.py --cpu-temp 80 --gpu-temp 75
```

2. **Check for power delivery issues**:
- Watch battery voltage during gaming
- Monitor AC adapter connection status

3. **Validate GPU stability**:
- Check driver version compatibility
- Monitor GPU temperature and throttling

## 📈 Performance

### System Impact
- **CPU Overhead**: <1% (2-second intervals)
- **Memory Usage**: ~50MB with 300-sample history
- **Startup Time**: <2 seconds including hardware discovery
- **Response Time**: Instant keyboard controls via threading

### Monitoring Capabilities
- **Temperature Accuracy**: ±1°C with direct sensor access
- **Update Frequency**: Real-time (configurable 1-10 second intervals)
- **History Retention**: 300 samples (configurable)
- **Export Efficiency**: Batched writes with minimal I/O impact

## 🤝 Contributing

1. **Fork** the repository
2. **Create** a feature branch: `git checkout -b feature/amazing-feature`
3. **Commit** changes: `git commit -m 'Add amazing feature'`
4. **Push** to branch: `git push origin feature/amazing-feature`
5. **Open** a Pull Request

### Development Setup
```bash
git clone https://github.com/Maxlab/systemmonitor.git
cd systemmonitor
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```

## 📋 Requirements

### Hardware Requirements
- **Recommended**: Lenovo Legion 5 Pro (AMD Ryzen 7 5800H + RTX 3070)
- **Minimum**: Any Linux system with temperature sensors
- **GPU**: NVIDIA GPU with nvidia-smi support (optional)

### Software Requirements
- **OS**: Linux (Ubuntu 20.04+ recommended)
- **Python**: 3.7 or higher
- **Dependencies**: psutil, colorama (auto-installed)

## 📄 License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## 🙏 Acknowledgments

- **Lenovo** for Legion 5 Pro hardware specifications
- **NVIDIA** for GPU monitoring APIs
- **Linux hwmon** subsystem for sensor access
- **Python community** for excellent monitoring libraries

## 📞 Support

- **Issues**: [GitHub Issues](https://github.com/Maxlab/systemmonitor/issues)
- **Discussions**: [GitHub Discussions](https://github.com/Maxlab/systemmonitor/discussions)
- **Hardware**: Tested on Legion 5 Pro (AMD Ryzen 7 5800H + RTX 3070)

---

**🎮 Built for gamers, by gamers. Keep your Legion cool! 🔥**