A powerful MySQL slow query log analyzer with HTML reports
MySQL Badger is a comprehensive tool for analyzing MySQL slow query logs, inspired by the excellent pgBadger for PostgreSQL. It transforms your slow query logs into detailed, interactive HTML reports with statistical analysis and visualizations.
- π Query Statistics - (min, max, mean, median, 95th percentile, standard deviation)
- π Interactive Charts - Query frequency and execution time trends over time
- π Query Analysis - Normalized queries with detailed execution patterns
- π Detailed Breakdowns - Lock time, rows sent/examined, query size analysis
- π¨ Beautiful Reports - Simple, responsive HTML interface
- β‘ Fast Processing - Efficient parsing of large log files (to be tested with large logs actually)
- π§ͺ Tested - Test suite with 27 unit tests
# Clone the repository git clone https://github.com/eSolutionsTech/mysqlBadger.git cd mysqlBadger # Install the CLI tool cd packages/mysql_badger_cli pip install -e .
# Generate a report from your slow query log mysql-badger -f /path/to/mysql-slow.log -o report.html # Open the generated report in your browser open report.html
For each query, MySQL Badger calculates and displays:
Attribute | pct | total | min | max | avg | 95% | stddev | median |
---|---|---|---|---|---|---|---|---|
Count | β | β | - | - | - | - | - | - |
Exec time | β | β | β | β | β | β | β | β |
Lock time | β | β | β | β | β | β | β | β |
Rows sent | β | β | β | β | β | β | β | β |
Rows examined | β | β | β | β | β | β | β | β |
Query size | β | β | β | β | β | β | β | β |
- Time Series Charts - Query frequency and average execution time over time
- Query Distribution - ASCII histograms showing execution time patterns
- Top Queries - Sorted by total time and frequency
- Query Examples - Real query samples with execution context
Example from generated HTML report
Example from generated HTML report
mysql-badger [OPTIONS]
Options:
-f, --file PATH Path to the MySQL slow query log file [required]
-o, --output PATH Output HTML report file [default: mysql-report.html]
-t, --top-n INTEGER Number of top queries to display [default: 10]
--help Show this message and exit
# Generate report with top 20 queries
mysql-badger -f /var/log/mysql/mysql-slow.log -o detailed-report.html -t 20
The project includes comprehensive tests covering all statistical calculations:
# Run all tests cd packages/mysql_badger_cli python -m pytest tests/ -v # Run with coverage python -m pytest tests/ --cov=src --cov-report=html
Test coverage includes:
- Statistical calculations (QueryStatistics class)
- Data parsing and aggregation
- Percentage calculations
- Edge cases (empty data, None values, duplicates)
# Clone and setup git clone https://github.com/eSolutionsTech/mysqlBadger.git cd mysqlBadger/packages/mysql_badger_cli # Create virtual environment python -m venv .venv source .venv/bin/activate # Linux/Mac # or .venv\Scripts\activate # Windows, never tested btw # Install development dependencies pip install -e ".[dev]"
mysqlBadger/
βββ assets/images/ # Logo and documentation images
βββ examples/ # Sample files for testing
β βββ sample-slow.log # Example MySQL slow query log
β βββ mysql_badger_report.html
βββ packages/
β βββ mysql_badger_cli/ # Main CLI package
β βββ src/ # Source code
β βββ tests/ # Test suite
β βββ templates/ # HTML report templates
βββ README.md
- Python 3.7+
- Dependencies:
pandas
- Data analysis and manipulationJinja2
- HTML template enginenumpy
- Numerical computations
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature
) - Add tests for new functionality
- Ensure all tests pass (
pytest
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Feature | MySQL Badger | pt-query-digest | mysqldumpslow |
---|---|---|---|
HTML Reports | β | β | β |
Statistical Analysis | β | β | β |
Time Series Charts | β | β | β |
Query Normalization | β | β | β |
Interactive Interface | β | β | β |
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
- Main Developer: Marian Simpetru | eSolutions.tech
- Created with assistance from: DanuΘa (π)
- Inspired by pgBadger - the excellent PostgreSQL log analyzer that I think is a must-have if you run any PostgreSQL database
- Built because pgBadger is the best tool of its kind, but there was no equivalent variant for MySQL. Though not yet as extensive as pgBadger, this project aims to fill that gap.
- Special thanks to Silviu and Emil
- Documentation: Check this README and inline code comments
- Issues: GitHub Issues