Skip to content

Latest commit

 

History

History
181 lines (128 loc) · 3.75 KB

File metadata and controls

181 lines (128 loc) · 3.75 KB

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.


🚀 AI-Powered MySQL Observability CLI Tool

A command-line tool to collect MySQL metrics, monitor performance, and detect anomalies using machine learning.


📦 Installation

  1. Clone this repository

    git clone https://github.com/<your-username>/mysql-observability-cli.git
    cd mysql-observability-cli
  2. Set up a Python environment

    python3 -m venv venv
    source venv/bin/activate   # macOS/Linux
    venv\Scripts\activate      # Windows
  3. Install dependencies

    pip install -r requirements.txt

🛠️ Configuration

  1. Start your MySQL server Make sure MySQL is running locally (or on a host you can connect to).

  2. Edit config.json On first run, the tool will auto-create config.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"
        ]
      }
    }

▶️ Usage

1. (Optional) Select a database

If you have select_database.py:

python select_database.py

2. Collect metrics

python p3cli.py --monitor
  • Collects 100 samples of MySQL metrics
  • Saves them in metrics_history.json
  • Displays the last one in a table

3. Run anomaly detection

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 --monitor collects 100)

4. Advanced analysis

  • AI-based anomaly detection

    python p3cli.py --ai-analyze
  • Query analysis

    python p3cli.py --analyze-queries

5. Show current configuration

python p3cli.py --config

📊 Example Workflow

# 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

🗂️ Project Structure

.
├── 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

⚠️ Notes

  • metrics_history.json and recent_analysis.json should 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?