Got it 👍 — let me clean this up into a well-formatted README.md that you can just copy–paste. I’ll make sure headings, code blocks, and sections are clear and readable on GitHub.
A command-line tool to collect MySQL metrics, monitor performance, and detect anomalies using machine learning.
-
Clone this repository
git clone https://github.com/<your-username>/mysql-observability-cli.git cd mysql-observability-cli
-
Set up a Python environment
python3 -m venv venv source venv/bin/activate # macOS/Linux venv\Scripts\activate # Windows
-
Install dependencies
pip install -r requirements.txt
-
Start your MySQL server Make sure MySQL is running locally (or on a host you can connect to).
-
Edit
config.jsonOn first run, the tool will auto-createconfig.json. Update it with your credentials:{ "mysql": { "host": "localhost", "port": 3306, "user": "youruser", "password": "yourpassword", "database": "mysql" }, "ml": { "contamination": 0.1, "random_state": 42, "min_samples_for_training": 10 }, "metrics": { "enabled": [ "Questions", "Threads_connected", "Threads_running", "Slow_queries", "Innodb_buffer_pool_size", "Innodb_buffer_pool_pages_data", "Innodb_buffer_pool_pages_free", "Connections", "Uptime" ] } }
If you have select_database.py:
python select_database.pypython p3cli.py --monitor- Collects 100 samples of MySQL metrics
- Saves them in
metrics_history.json - Displays the last one in a table
python p3cli.py --analyze- Trains an IsolationForest ML model on historical metrics
- Detects if the most recent datapoint looks anomalous
- Requires at least 10 datapoints (satisfied since
--monitorcollects 100)
-
AI-based anomaly detection
python p3cli.py --ai-analyze
-
Query analysis
python p3cli.py --analyze-queries
python p3cli.py --config# Step 1: Start MySQL server
brew services start mysql # macOS
sudo systemctl start mysql # Linux
# Step 2: Run monitor (collects 100 datapoints)
python p3cli.py --monitor
# Step 3: Run anomaly detection
python p3cli.py --analyze
# Step 4 (optional): Run AI-enhanced anomaly detection
python p3cli.py --ai-analyze.
├── p3cli.py # Main CLI tool
├── config.json # User configuration (auto-created on first run)
├── metrics_history.json # Saved metrics history
├── recent_analysis.json # Last analysis results
├── select_database.py # (Optional) database selector script
├── requirements.txt # Dependencies
└── README.md # This guide
metrics_history.jsonandrecent_analysis.jsonshould be ignored in Git (add to.gitignore)- At least 10 datapoints are required for anomaly detection (already handled by default)
- If MySQL is not running, the tool falls back to demo mode (simulated metrics)
✅ Now your README will look neat and structured on GitHub.
Do you also want me to give you a .gitignore file so you don’t push local JSON files, venv, and cache stuff to GitHub?