README.md aktualisiert
This commit is contained in:
553
README.md
553
README.md
@@ -1,3 +1,552 @@
|
||||
# deep-shop-strace-analyse
|
||||
# Deep Shop strace Analyse
|
||||
|
||||
Überprüft gründlich womit PHP der Shop beschäftigt ist per strace.
|
||||
Ein leistungsstarkes Python-Tool zur Performance-Analyse von JTL-Shop-Instanzen durch systematisches Tracing von PHP-FPM-Prozessen.
|
||||
|
||||
## 📋 Inhaltsverzeichnis
|
||||
|
||||
- [Überblick](#überblick)
|
||||
- [Features](#features)
|
||||
- [Voraussetzungen](#voraussetzungen)
|
||||
- [Installation](#installation)
|
||||
- [Verwendung](#verwendung)
|
||||
- [Ausgabe-Dateien](#ausgabe-dateien)
|
||||
- [Beispiele](#beispiele)
|
||||
- [Troubleshooting](#troubleshooting)
|
||||
- [Technische Details](#technische-details)
|
||||
- [Contributing](#contributing)
|
||||
- [Kontakt](#kontakt)
|
||||
|
||||
---
|
||||
|
||||
## 🎯 Überblick
|
||||
|
||||
`straceanalyse.py` ist ein spezialisiertes Diagnose-Tool für JTL-Shop-Umgebungen auf Plesk-basierten Servern. Es analysiert PHP-FPM-Prozesse mittels `strace` und identifiziert Performance-Probleme wie:
|
||||
|
||||
- Fehlende Bilder und Dateien (ENOENT-Fehler)
|
||||
- Übermäßige Filesystem-Zugriffe
|
||||
- Langsame MySQL-Queries
|
||||
- Redis-Operation-Patterns
|
||||
- ImageMagick-Bottlenecks
|
||||
- Memory-Allocation-Probleme
|
||||
|
||||
Das Tool verknüpft jedes Problem mit dem auslösenden PHP-Script und generiert automatisch Lösungsvorschläge.
|
||||
|
||||
---
|
||||
|
||||
## ✨ Features
|
||||
|
||||
### Kern-Features
|
||||
|
||||
- **🔍 Automatische PHP-FPM-Prozess-Erkennung**: Findet alle aktiven Worker für einen Shop
|
||||
- **📊 Syscall-Analyse**: Detaillierte Aufschlüsselung aller System-Calls
|
||||
- **📁 Fehlende-Dateien-Tracking**: Identifiziert nicht vorhandene Bilder/Ressourcen
|
||||
- **🔗 Script-Context-Mapping**: Zeigt welches PHP-Script fehlende Dateien aufruft
|
||||
- **💾 Multi-Format-Export**: TXT, CSV, Bash-Scripts
|
||||
- **🚀 Parallel-Processing**: Analysiert alle PHP-FPM-Worker gleichzeitig
|
||||
- **📈 Progress-Tracking**: Echtzeit-Fortschrittsanzeige
|
||||
|
||||
### Analyse-Bereiche
|
||||
|
||||
- **Filesystem Operations**: stat(), open(), access() Calls
|
||||
- **MySQL Queries**: SELECT, UPDATE, INSERT, DELETE
|
||||
- **Redis Operations**: SADD, GET, SET, HGET, etc.
|
||||
- **Network I/O**: Langsame Verbindungen, Timeouts
|
||||
- **Memory Operations**: mremap(), mmap() Patterns
|
||||
- **Image Processing**: ImageMagick-Aufrufe
|
||||
|
||||
---
|
||||
|
||||
## 📦 Voraussetzungen
|
||||
|
||||
### System-Anforderungen
|
||||
|
||||
- **OS**: Linux (Debian/Ubuntu)
|
||||
- **Python**: 3.7+
|
||||
- **Plesk**: Ja (für Multi-PHP-Pool-Support)
|
||||
- **Root-Zugriff**: Erforderlich für strace
|
||||
|
||||
### Abhängigkeiten
|
||||
```bash
|
||||
# System-Pakete
|
||||
apt-get install strace python3
|
||||
|
||||
# Python-Module (Standard-Library)
|
||||
# Keine zusätzlichen pip-Pakete erforderlich!
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Installation
|
||||
|
||||
### 1. Repository klonen
|
||||
```bash
|
||||
git clone https://git.jtl-hosting.de/thomasciesla/deep-shop-strace-analyse.git
|
||||
cd deep-shop-strace-analyse
|
||||
```
|
||||
|
||||
### 2. Script ausführbar machen
|
||||
```bash
|
||||
chmod +x straceanalyse.py
|
||||
```
|
||||
|
||||
### 3. Test-Run
|
||||
```bash
|
||||
python3 straceanalyse.py --help
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 💻 Verwendung
|
||||
|
||||
### Basis-Syntax
|
||||
```bash
|
||||
python3 straceanalyse.py <domain> [duration] [max_processes]
|
||||
```
|
||||
|
||||
### Parameter
|
||||
|
||||
| Parameter | Typ | Default | Beschreibung |
|
||||
|-----------|-----|---------|--------------|
|
||||
| `domain` | String | **Pflicht** | Shop-Domain (z.B. `example.com`) |
|
||||
| `duration` | Integer | `5` | Sekunden pro Prozess-Trace |
|
||||
| `max_processes` | Integer | `alle` | Max. Anzahl zu analysierender Prozesse |
|
||||
|
||||
### Basis-Beispiele
|
||||
```bash
|
||||
# Standard-Analyse (5 Sekunden pro Prozess, alle Worker)
|
||||
python3 straceanalyse.py mein-shop.de
|
||||
|
||||
# Längere Analyse für mehr Daten (10 Sekunden)
|
||||
python3 straceanalyse.py mein-shop.de 10
|
||||
|
||||
# Limitiert auf 20 Prozesse
|
||||
python3 straceanalyse.py mein-shop.de 10 20
|
||||
|
||||
# Sehr schnelle Analyse (3 Sekunden, max 10 Prozesse)
|
||||
python3 straceanalyse.py mein-shop.de 3 10
|
||||
```
|
||||
|
||||
### Erweiterte Verwendung
|
||||
|
||||
#### High-Traffic-Shop analysieren
|
||||
```bash
|
||||
# Bei hoher Last: Kurze Duration, viele Prozesse
|
||||
python3 straceanalyse.py high-traffic-shop.de 3 50
|
||||
```
|
||||
|
||||
#### Low-Traffic-Shop analysieren
|
||||
```bash
|
||||
# Bei wenig Traffic: Längere Duration für mehr Daten
|
||||
python3 straceanalyse.py low-traffic-shop.de 15
|
||||
```
|
||||
|
||||
#### Kontinuierliches Monitoring
|
||||
```bash
|
||||
# Alle 5 Minuten analysieren
|
||||
watch -n 300 'python3 straceanalyse.py mein-shop.de 5 10'
|
||||
```
|
||||
|
||||
#### Output in Log-Datei
|
||||
```bash
|
||||
python3 straceanalyse.py mein-shop.de 10 | tee shop-analyse-$(date +%Y%m%d-%H%M).log
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📂 Ausgabe-Dateien
|
||||
|
||||
Das Script erstellt ein Verzeichnis: `/root/shop_analysis_<domain>_<timestamp>/`
|
||||
|
||||
### Generierte Dateien
|
||||
|
||||
#### 1. `missing_files_all.txt`
|
||||
Komplette Liste aller fehlenden Dateien mit Script-Context.
|
||||
```
|
||||
[ 24x] /var/www/vhosts/shop.de/httpdocs/media/image/manufacturer/28/xs/logo.jpg
|
||||
======================================================================
|
||||
Aufgerufen von:
|
||||
* includes/src/Catalog/Product/Artikel.php
|
||||
* includes/src/Helpers/Product.php
|
||||
|
||||
Bei Requests:
|
||||
* /artikel/produktname-123
|
||||
* /kategorie/hersteller-28
|
||||
|
||||
PIDs: 12345, 12346, 12347
|
||||
```
|
||||
|
||||
#### 2. `missing_files_by_script.txt`
|
||||
Gruppiert nach PHP-Script - zeigt welches Script welche Dateien sucht.
|
||||
```
|
||||
======================================================================
|
||||
SCRIPT: includes/src/Catalog/Product/Artikel.php
|
||||
======================================================================
|
||||
Anzahl fehlender Dateien: 156
|
||||
|
||||
[ 24x] media/image/manufacturer/28/xs/logo.jpg
|
||||
[ 18x] media/image/product/1234/sm/produkt.jpg
|
||||
...
|
||||
```
|
||||
|
||||
#### 3. `missing_files_by_category.txt`
|
||||
Nach Kategorie gruppiert (Hersteller, Produkte, Variationen, etc.).
|
||||
```
|
||||
======================================================================
|
||||
HERSTELLER-BILDER
|
||||
======================================================================
|
||||
Anzahl Dateien: 89
|
||||
Zugriffe gesamt: 456
|
||||
|
||||
[ 24x] media/image/manufacturer/28/xs/logo.jpg
|
||||
[ 20x] media/image/manufacturer/180/xs/logo.jpg
|
||||
...
|
||||
```
|
||||
|
||||
#### 4. `missing_files.csv`
|
||||
CSV-Format für Excel/Spreadsheet-Analyse.
|
||||
```csv
|
||||
Zugriffe,Kategorie,Dateipfad,Aufgerufen_von_Script
|
||||
24,Hersteller,"/var/www/.../manufacturer/28/xs/logo.jpg","Artikel.php; Product.php"
|
||||
20,Hersteller,"/var/www/.../manufacturer/180/xs/logo.jpg","Product.php"
|
||||
```
|
||||
|
||||
#### 5. `create_placeholders.sh` ⭐
|
||||
**Automatisches Fix-Script** - Erstellt Platzhalter für fehlende Bilder.
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# Ausführen mit:
|
||||
bash create_placeholders.sh
|
||||
|
||||
# Output:
|
||||
# Erstelle fehlende Dateien...
|
||||
# Fertig!
|
||||
# Erstellt: 156 Platzhalter
|
||||
# Übersprungen: 23 (existieren bereits)
|
||||
# Total Dateien: 179
|
||||
```
|
||||
|
||||
#### 6. `missing_manufacturer_ids.txt`
|
||||
Liste aller Hersteller-IDs mit fehlenden Bildern.
|
||||
```
|
||||
# Hersteller IDs mit fehlenden Bildern
|
||||
# Total: 45 Hersteller
|
||||
28
|
||||
180
|
||||
493
|
||||
1104
|
||||
...
|
||||
```
|
||||
|
||||
#### 7. `missing_files_paths_only.txt`
|
||||
Nur Dateipfade - für weitere Script-Verarbeitung.
|
||||
```
|
||||
/var/www/vhosts/shop.de/httpdocs/media/image/manufacturer/28/xs/logo.jpg
|
||||
/var/www/vhosts/shop.de/httpdocs/media/image/product/1234/sm/bild.jpg
|
||||
...
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📊 Terminal-Ausgabe
|
||||
|
||||
### Beispiel-Output
|
||||
```
|
||||
================================================================================
|
||||
PERFORMANCE ANALYSE: mein-shop.de
|
||||
Datum: 2025-10-27 16:30:45
|
||||
================================================================================
|
||||
|
||||
SYSCALL STATISTIK
|
||||
--------------------------------------------------------------------------------
|
||||
newfstatat : 2456 ( 35.2%) ###################
|
||||
recvfrom : 1823 ( 26.1%) #############
|
||||
sendto : 1245 ( 17.8%) #########
|
||||
poll : 892 ( 12.8%) ######
|
||||
read : 234 ( 3.4%) ##
|
||||
...
|
||||
|
||||
FEHLENDE DATEIEN (ENOENT) - MIT SCRIPT CONTEXT
|
||||
--------------------------------------------------------------------------------
|
||||
WARNUNG: 156 verschiedene Dateien nicht gefunden!
|
||||
WARNUNG: 678 Zugriffe
|
||||
|
||||
Top 10 fehlende Dateien (mit aufrufendem Script):
|
||||
|
||||
[ 24x] media/image/manufacturer/28/xs/logo.jpg
|
||||
Aufgerufen von:
|
||||
-> includes/src/Catalog/Product/Artikel.php
|
||||
-> includes/src/Helpers/Product.php
|
||||
|
||||
[ 20x] media/image/manufacturer/180/xs/logo.jpg
|
||||
Aufgerufen von:
|
||||
-> includes/src/Catalog/Product/Artikel.php
|
||||
...
|
||||
|
||||
FEHLER
|
||||
--------------------------------------------------------------------------------
|
||||
ENOENT : 678x
|
||||
EAGAIN : 234x
|
||||
|
||||
================================================================================
|
||||
EXPORTIERE FEHLENDE DATEIEN
|
||||
================================================================================
|
||||
|
||||
Dateien exportiert nach: /root/shop_analysis_mein-shop.de_20251027_163045
|
||||
|
||||
Erstellt:
|
||||
missing_files_all.txt - Komplette Liste MIT Script-Context
|
||||
missing_files_by_script.txt - Gruppiert nach PHP-Script
|
||||
missing_files_by_category.txt - Nach Kategorie gruppiert
|
||||
missing_files.csv - CSV mit Script-Info
|
||||
create_placeholders.sh - Bash Script
|
||||
missing_manufacturer_ids.txt - Hersteller IDs
|
||||
missing_files_paths_only.txt - Nur Pfade
|
||||
|
||||
Quick-Fix:
|
||||
bash /root/shop_analysis_mein-shop.de_20251027_163045/create_placeholders.sh
|
||||
|
||||
================================================================================
|
||||
ZUSAMMENFASSUNG
|
||||
================================================================================
|
||||
* Total Syscalls: 6972
|
||||
* Fehlende Dateien: 156
|
||||
* MySQL Queries: 423
|
||||
|
||||
Export-Verzeichnis: /root/shop_analysis_mein-shop.de_20251027_163045
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔧 Beispiele
|
||||
|
||||
### Szenario 1: Performance-Problem diagnostizieren
|
||||
```bash
|
||||
# Shop läuft langsam - erste Analyse
|
||||
python3 straceanalyse.py slow-shop.de 10
|
||||
|
||||
# Ausgabe prüfen - viele fehlende Bilder?
|
||||
# → Quick-Fix ausführen
|
||||
cd /root/shop_analysis_*
|
||||
bash create_placeholders.sh
|
||||
|
||||
# Erneut testen
|
||||
python3 straceanalyse.py slow-shop.de 5
|
||||
```
|
||||
|
||||
### Szenario 2: Spezifisches Script debuggen
|
||||
```bash
|
||||
# Analyse durchführen
|
||||
python3 straceanalyse.py problem-shop.de 10
|
||||
|
||||
# In den Exports nach problematischem Script suchen
|
||||
cat /root/shop_analysis_*/missing_files_by_script.txt | grep -A 20 "Problem.php"
|
||||
```
|
||||
|
||||
### Szenario 3: Alle Shops auf Server analysieren
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# analyse_all_shops.sh
|
||||
|
||||
SHOPS=(
|
||||
"shop1.de"
|
||||
"shop2.de"
|
||||
"shop3.de"
|
||||
)
|
||||
|
||||
for shop in "${SHOPS[@]}"; do
|
||||
echo "Analysiere $shop..."
|
||||
python3 straceanalyse.py "$shop" 5 10
|
||||
echo "---"
|
||||
done
|
||||
```
|
||||
|
||||
### Szenario 4: Vergleich vor/nach Optimierung
|
||||
```bash
|
||||
# Vor Optimierung
|
||||
python3 straceanalyse.py shop.de 10 > /tmp/before.txt
|
||||
|
||||
# ... Optimierungen durchführen ...
|
||||
|
||||
# Nach Optimierung
|
||||
python3 straceanalyse.py shop.de 10 > /tmp/after.txt
|
||||
|
||||
# Vergleichen
|
||||
diff /tmp/before.txt /tmp/after.txt
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🐛 Troubleshooting
|
||||
|
||||
### Problem: "Keine PHP-FPM Prozesse gefunden"
|
||||
|
||||
**Ursache**: Falsche Domain oder keine aktiven Worker
|
||||
|
||||
**Lösung**:
|
||||
```bash
|
||||
# Prüfen welche Pools existieren
|
||||
systemctl list-units | grep plesk-php
|
||||
|
||||
# Domain-Name exakt wie in Plesk verwenden
|
||||
ps aux | grep php-fpm | grep pool
|
||||
```
|
||||
|
||||
### Problem: "Keine Syscalls aufgezeichnet"
|
||||
|
||||
**Ursache**: Shop hat gerade wenig Traffic
|
||||
|
||||
**Lösungen**:
|
||||
```bash
|
||||
# 1. Längere Duration
|
||||
python3 straceanalyse.py shop.de 20
|
||||
|
||||
# 2. Traffic generieren (anderes Terminal)
|
||||
for i in {1..50}; do curl -s https://shop.de/ > /dev/null & done
|
||||
|
||||
# 3. Zu Peak-Zeiten wiederholen
|
||||
```
|
||||
|
||||
### Problem: "Permission denied" bei strace
|
||||
|
||||
**Ursache**: Keine Root-Rechte
|
||||
|
||||
**Lösung**:
|
||||
```bash
|
||||
# Als root ausführen
|
||||
sudo python3 straceanalyse.py shop.de 10
|
||||
|
||||
# Oder mit sudo prefix im Script
|
||||
```
|
||||
|
||||
### Problem: Script hängt/läuft sehr lange
|
||||
|
||||
**Ursache**: Zu viele Prozesse oder zu lange Duration
|
||||
|
||||
**Lösung**:
|
||||
```bash
|
||||
# Prozesse limitieren
|
||||
python3 straceanalyse.py shop.de 5 10
|
||||
|
||||
# Script abbrechen: Ctrl+C
|
||||
# Bereits gesammelte Daten bleiben erhalten
|
||||
```
|
||||
|
||||
### Problem: "unknown" bei Script-Context
|
||||
|
||||
**Ursache**: Prozess war idle oder konnte Context nicht auslesen
|
||||
|
||||
**Bedeutung**:
|
||||
- Normal bei idle Workers
|
||||
- Keine Aktion nötig wenn nur wenige "unknown"
|
||||
- Bei vielen "unknown": Längere Duration probieren
|
||||
|
||||
---
|
||||
|
||||
## 🔬 Technische Details
|
||||
|
||||
### Funktionsweise
|
||||
|
||||
1. **Prozess-Discovery**: Findet alle PHP-FPM-Worker via `ps aux`
|
||||
2. **Context-Extraktion**: Liest `/proc/$pid/environ` für REQUEST_URI und SCRIPT_FILENAME
|
||||
3. **Syscall-Tracing**: Führt `strace` mit Timeout auf jeden Prozess aus
|
||||
4. **Pattern-Matching**: Analysiert strace-Output mit Regex-Patterns
|
||||
5. **Context-Mapping**: Verknüpft fehlende Dateien mit PHP-Scripts
|
||||
6. **Multi-Format-Export**: Generiert 7 verschiedene Output-Dateien
|
||||
|
||||
### Strace-Parameter
|
||||
```bash
|
||||
strace -p $PID \ # An Prozess anhängen
|
||||
-f \ # Child-Prozesse folgen
|
||||
-s 500 \ # String-Länge auf 500 Zeichen
|
||||
-e trace=all\ # Alle Syscalls tracen
|
||||
-T # Zeit pro Syscall anzeigen
|
||||
```
|
||||
|
||||
### Performance-Impact
|
||||
|
||||
- **CPU**: ~2-5% pro Worker während Trace
|
||||
- **Memory**: ~50MB für Script + Daten
|
||||
- **Shop-Impact**: Minimal (< 1% Latenz)
|
||||
- **Duration**: 5 Sekunden = ~0 bemerkbar
|
||||
|
||||
### Limitierungen
|
||||
|
||||
- **Idle-Workers**: Keine Daten wenn Prozess nichts tut
|
||||
- **Context-Loss**: Bei sehr kurzen Requests
|
||||
- **Root-Requirement**: Muss als root laufen
|
||||
- **Plesk-Specific**: Für andere Setups Anpassungen nötig
|
||||
|
||||
---
|
||||
|
||||
## 🤝 Contributing
|
||||
|
||||
Beiträge sind willkommen!
|
||||
|
||||
### Workflow
|
||||
|
||||
1. Issue erstellen: [Issues](https://git.jtl-hosting.de/thomasciesla/deep-shop-strace-analyse/issues)
|
||||
2. Branch erstellen: `git checkout -b feature/deine-feature`
|
||||
3. Änderungen committen: `git commit -am 'Add feature'`
|
||||
4. Push: `git push origin feature/deine-feature`
|
||||
5. Pull Request: [Pull Requests](https://git.jtl-hosting.de/thomasciesla/deep-shop-strace-analyse/pulls)
|
||||
|
||||
### Code-Style
|
||||
|
||||
- **PEP 8** für Python-Code
|
||||
- **Docstrings** für alle Funktionen
|
||||
- **Type Hints** wo möglich
|
||||
- **Kommentare** für komplexe Logik
|
||||
|
||||
### Testing
|
||||
```bash
|
||||
# Grundfunktion testen
|
||||
python3 straceanalyse.py test-shop.de 3 5
|
||||
|
||||
# Ausgabe-Dateien prüfen
|
||||
ls -la /root/shop_analysis_*/
|
||||
|
||||
# CSV-Format validieren
|
||||
python3 -c "import csv; list(csv.reader(open('/root/shop_analysis_*/missing_files.csv')))"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📧 Kontakt
|
||||
|
||||
**Maintainer**: Thomas Ciesla
|
||||
**Email**: [thomas.ciesla@jtl-software.com](mailto:thomas.ciesla@jtl-software.com)
|
||||
**Teams**: thomas.ciesla@jtl-software.com
|
||||
**Issues**: [GitHub Issues](https://git.jtl-hosting.de/thomasciesla/deep-shop-strace-analyse/issues)
|
||||
|
||||
---
|
||||
|
||||
## 📄 License
|
||||
|
||||
Copyright © 2025 JTL-Software GmbH
|
||||
|
||||
Dieses Tool ist für den internen Gebrauch bei JTL-Software entwickelt.
|
||||
|
||||
---
|
||||
|
||||
## 🙏 Danksagungen
|
||||
|
||||
- **JTL-Shop Team** für die Shop-Architektur
|
||||
- **Plesk** für das Multi-PHP-Pool-System
|
||||
- **Linux strace** für das mächtige Tracing-Tool
|
||||
|
||||
---
|
||||
|
||||
## 📝 Changelog
|
||||
|
||||
### Version 1.0.0 (2025-10-27)
|
||||
- ✨ Initial Release
|
||||
- 🔍 PHP-FPM Prozess-Analyse
|
||||
- 📁 Fehlende-Dateien-Detection
|
||||
- 🔗 Script-Context-Mapping
|
||||
- 📊 Multi-Format-Export
|
||||
- 🚀 Parallel-Processing
|
||||
- 📈 Progress-Tracking
|
||||
|
||||
---
|
||||
|
||||
**Happy Debugging! 🐛🔍**
|
||||
Reference in New Issue
Block a user