Troubleshooting¶
This comprehensive troubleshooting guide covers common issues, solutions, and debugging techniques for the Fitness Dashboard.
Quick Diagnostic Checklist¶
Before diving into specific issues, run through this basic checklist:
- Database Connection: Can you connect to MySQL?
- Environment Variables: Are all required env vars set?
- Dependencies: Are all Python packages installed?
- Port Availability: Is port 8501 available for Streamlit?
- File Permissions: Can the application read/write necessary files?
- Logs: Check recent logs for error messages
Installation and Setup Issues¶
Poetry and Dependencies¶
Poetry Command Not Found
Error: command not found: poetry
Cause: Poetry not installed or not in PATH
Solutions:
Python Version Compatibility
Error: requires python >=3.10, but you have 3.9
Solutions:
Lock File Issues
Error: poetry.lock is not consistent with pyproject.toml
Solutions:
Virtual Environment Issues¶
Virtual Environment Not Activated
Symptoms: Packages not found, wrong Python version
Solutions:
Database Connection Issues¶
MySQL Connection Problems¶
Access Denied for User
Error: ERROR 1045 (28000): Access denied for user 'fitness_user'@'localhost'
Diagnostic Steps:
# Check MySQL service status
brew services list | grep mysql # macOS
sudo systemctl status mysql # Linux
# Test connection manually
mysql -u fitness_user -p
Solutions:
-- Reset user password
ALTER USER 'fitness_user'@'localhost' IDENTIFIED BY 'new_password';
FLUSH PRIVILEGES;
-- Or recreate user
DROP USER IF EXISTS 'fitness_user'@'localhost';
CREATE USER 'fitness_user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON sweat.* TO 'fitness_user'@'localhost';
FLUSH PRIVILEGES;
Can't Connect to MySQL Server
Error: ERROR 2002 (HY000): Can't connect to local MySQL server
Diagnostic Steps:
# Check if MySQL is running
ps aux | grep mysql
# Check port availability
netstat -tlnp | grep 3306
lsof -i :3306
Solutions:
Database Does Not Exist
Error: ERROR 1049 (42000): Unknown database 'sweat'
Solution:
Environment Configuration Issues¶
Missing Environment Variables
Error: KeyError: 'MYSQL_USER'
or similar
Diagnostic Steps:
# Check environment variables
echo $MYSQL_USER
printenv | grep MYSQL
# Check .env file exists
ls -la .env
cat .env
Solutions:
RDS Connection Issues (Production)¶
RDS Connection Timeout
Error: Connection timeout when connecting to RDS
Diagnostic Steps:
# Test connectivity
telnet your-rds-endpoint.amazonaws.com 3306
# Check security groups
aws ec2 describe-security-groups --group-ids sg-xxxxxxxxx
Solutions: - Verify security group allows inbound port 3306 - Check VPC subnet configuration - Ensure RDS is publicly accessible if needed - Verify endpoint URL is correct
Streamlit Application Issues¶
Application Won't Start¶
Port Already in Use
Error: OSError: [Errno 48] Address already in use
Diagnostic Steps:
Solutions:
Module Import Errors
Error: ModuleNotFoundError: No module named 'src'
Diagnostic Steps:
# Check current directory
pwd
ls -la src/
# Check Python path
python -c "import sys; print('\n'.join(sys.path))"
Solutions:
Dashboard Display Issues¶
Empty Dashboard/No Data
Symptoms: Dashboard loads but shows no workouts
Diagnostic Steps:
# Check database contents
mysql -u fitness_user -p sweat -e "SELECT COUNT(*) FROM workout_summary;"
# Check for data import issues
python src/update_db.py
Solutions:
- Import sample data: python src/update_db.py
- Verify CSV file path in pyproject.toml
- Check database connection in Streamlit
Charts Not Displaying
Symptoms: Chart areas are blank or show errors
Diagnostic Steps:
# Check browser console for JavaScript errors
# Open browser dev tools (F12) and check console
# Verify Plotly installation
python -c "import plotly; print(plotly.__version__)"
Solutions:
Performance Issues¶
Slow Loading Times
Symptoms: Dashboard takes long time to load or update
Diagnostic Steps:
# Check database query performance
mysql -u fitness_user -p sweat -e "
SELECT COUNT(*) FROM workout_summary;
SHOW PROCESSLIST;
"
# Monitor system resources
top
htop
Solutions:
Memory Issues
Error: MemoryError
or system becomes unresponsive
Solutions:
Data Import Issues¶
CSV Processing Problems¶
File Not Found
Error: FileNotFoundError: [Errno 2] No such file or directory
Diagnostic Steps:
# Check file exists
ls -la src/*.csv
# Check pyproject.toml configuration
grep input_filename pyproject.toml
Solutions:
CSV Parsing Errors
Error: pandas.errors.ParserError
or encoding issues
Diagnostic Steps:
Solutions:
Data Validation Failures
Error: ValueError: Invalid date format
or similar
Diagnostic Steps:
# Check data types
import pandas as pd
df = pd.read_csv('src/your_data.csv')
print(df.dtypes)
print(df.head())
Solutions:
Database Import Issues¶
Duplicate Key Errors
Error: pymysql.err.IntegrityError: (1062, "Duplicate entry")
Solutions:
Production Deployment Issues¶
Service Management Problems¶
Systemd Service Won't Start
Error: Service fails to start or immediately stops
Diagnostic Steps:
# Check service status
sudo systemctl status fitness-dashboard
# View service logs
sudo journalctl -u fitness-dashboard -f
# Check service file
sudo systemctl cat fitness-dashboard
Solutions:
# Fix common service file issues
sudo systemctl edit fitness-dashboard
# Ensure correct user and paths
[Service]
User=fitness-app
WorkingDirectory=/home/fitness-app/fitness-dashboard
EnvironmentFile=/home/fitness-app/.env
# Reload and restart
sudo systemctl daemon-reload
sudo systemctl restart fitness-dashboard
Nginx Configuration Issues¶
502 Bad Gateway
Error: Nginx shows 502 error
Diagnostic Steps:
# Check Nginx error logs
sudo tail -f /var/log/nginx/error.log
# Test Nginx configuration
sudo nginx -t
# Check if Streamlit is running
ps aux | grep streamlit
curl http://localhost:8501
Solutions:
SSL Certificate Issues
Error: SSL certificate warnings or failures
Diagnostic Steps:
# Check certificate status
sudo certbot certificates
# Test SSL configuration
openssl s_client -connect workouts.barbhs.com:443
Solutions:
Performance Troubleshooting¶
Database Performance¶
Slow Queries
Symptoms: Dashboard responds slowly, timeouts
Diagnostic Steps:
-- Enable slow query log
SET GLOBAL slow_query_log = 'ON';
SET GLOBAL long_query_time = 2;
-- Check running queries
SHOW PROCESSLIST;
-- Analyze query performance
EXPLAIN SELECT * FROM workout_summary WHERE workout_date >= '2024-01-01';
Solutions:
Memory and Resource Issues¶
High Memory Usage
Symptoms: System runs out of memory, applications crash
Diagnostic Steps:
# Monitor memory usage
free -h
top -o %MEM
# Check swap usage
swapon --show
# Monitor specific process
ps aux --sort=-%mem | head -10
Solutions:
Debugging Techniques¶
Application Debugging¶
Enable Debug Mode:
# In Streamlit app
import streamlit as st
import logging
# Enable debug logging
logging.basicConfig(level=logging.DEBUG)
# Show debug information
if st.checkbox("Debug Mode"):
st.write("Session State:", dict(st.session_state))
st.write("Environment:", os.environ.get("ENVIRONMENT"))
# Test database connection
try:
db_service = DatabaseService()
result = db_service.test_connection()
st.write("Database Connection:", "✅ OK" if result else "❌ Failed")
except Exception as e:
st.error(f"Database Error: {e}")
Log Analysis:
# View recent application logs
tail -f /var/log/fitness-dashboard/app.log
# Search for specific errors
grep -i "error\|exception" /var/log/fitness-dashboard/app.log
# Monitor logs in real-time
sudo journalctl -u fitness-dashboard -f
# Filter logs by time
journalctl -u fitness-dashboard --since "2024-01-15 10:00:00"
Network Debugging¶
Connection Testing:
# Test database connectivity
telnet mysql-host 3306
nc -zv mysql-host 3306
# Test web application
curl -I http://localhost:8501
curl -I https://workouts.barbhs.com
# Check DNS resolution
nslookup workouts.barbhs.com
dig workouts.barbhs.com
Performance Profiling¶
Database Profiling:
-- Profile query performance
SET profiling = 1;
SELECT * FROM workout_summary WHERE workout_date >= '2024-01-01';
SHOW PROFILES;
SHOW PROFILE FOR QUERY 1;
Python Profiling:
import cProfile
import pstats
# Profile a specific function
profiler = cProfile.Profile()
profiler.enable()
# Your code here
result = expensive_function()
profiler.disable()
stats = pstats.Stats(profiler)
stats.sort_stats('cumulative')
stats.print_stats(10)
Getting Help¶
Log Collection¶
When reporting issues, collect relevant information:
#!/bin/bash
# collect_debug_info.sh
echo "=== System Information ===" > debug_info.txt
uname -a >> debug_info.txt
python --version >> debug_info.txt
echo -e "\n=== Service Status ===" >> debug_info.txt
systemctl status fitness-dashboard >> debug_info.txt 2>&1
echo -e "\n=== Recent Logs ===" >> debug_info.txt
journalctl -u fitness-dashboard --lines=50 >> debug_info.txt 2>&1
echo -e "\n=== Database Connection ===" >> debug_info.txt
mysql -u fitness_user -p$MYSQL_PWD -e "SELECT COUNT(*) FROM sweat.workout_summary;" >> debug_info.txt 2>&1
echo -e "\n=== Disk Usage ===" >> debug_info.txt
df -h >> debug_info.txt
echo -e "\n=== Memory Usage ===" >> debug_info.txt
free -h >> debug_info.txt
Support Resources¶
- GitHub Issues: Report bugs and request features
- Email Support: barbs@balex.com
- Documentation: Check other sections of this documentation
- Community: Share solutions and get help from other users
Common Solutions Summary¶
Issue Category | Quick Fix | Documentation Link |
---|---|---|
Installation | poetry install && poetry shell |
Installation Guide |
Database Connection | Check MySQL service and credentials | Database Setup |
Import Issues | Verify CSV file and run update_db.py |
Data Import |
Performance | Add database indexes and caching | Architecture |
Production Issues | Check service logs and restart services | Production Setup |
Remember: Most issues can be resolved by checking logs, verifying configuration, and ensuring all services are running properly.