Why MySQL Health Monitoring Matters
MySQL and MariaDB power the majority of web applications. Without proper monitoring, you will not notice connection pool exhaustion, slow query accumulation, or replication lag until your application starts timing out.
dargslan-mysql-health is a free Python CLI tool that gives you instant visibility into your MySQL/MariaDB server health β connection usage, slow queries, replication status, and database sizes β all without external dependencies.
Install dargslan-mysql-health
pip install dargslan-mysql-health
Requires the mysql CLI client to be installed on your system (included in mysql-client or mariadb-client packages).
Quick Health Report
dargslan-mysql report
Displays server version, uptime, connection statistics, slow query info, and any detected issues.
Health Checks
Connection Monitoring
dargslan-mysql connections
Shows current connections, max connections, max used connections, and usage percentage. Alerts when usage exceeds 80% (warning) or 95% (critical).
Slow Query Analysis
dargslan-mysql slow
Checks if the slow query log is enabled, the long_query_time threshold, and total slow query count. Alerts when slow queries exceed 1000.
Database Sizes
dargslan-mysql databases
Lists all databases with their size in MB, sorted by size descending. Useful for identifying which databases are consuming the most disk space.
Replication Status
dargslan-mysql replication
Checks if replication is configured, IO/SQL thread status, seconds behind master, and last error. Critical alerts for broken replication.
Custom Connection
# Connect to remote server
dargslan-mysql report -H 10.0.0.5 -P 3306 -u admin -p secretpass
# Or use environment variables
export MYSQL_USER=admin
export MYSQL_PASSWORD=secretpass
dargslan-mysql report
Python API
from dargslan_mysql_health import MySQLHealth
mh = MySQLHealth(host="localhost", user="root")
# Full audit
issues = mh.audit()
for issue in issues:
print(f"[{issue['severity'].upper()}] {issue['message']}")
# Connection status
conn = mh.connection_status()
print(f"Connections: {conn['current_connections']}/{conn['max_connections']} ({conn['usage_percent']}%)")
# Database sizes
for db in mh.database_sizes():
print(f"{db['database']}: {db['size_mb']} MB")
# Server info
info = mh.server_info()
print(f"MySQL {info['version']}, uptime: {info['uptime_human']}")
# Replication
repl = mh.replication_status()
if repl['configured']:
print(f"IO: {repl['io_running']}, SQL: {repl['sql_running']}")
print(f"Lag: {repl['seconds_behind']}s")
Severity Levels
| Check | Severity | Threshold |
|---|---|---|
| Connection usage | WARNING | >80% |
| Connection usage | CRITICAL | >95% |
| Slow query log off | INFO | Always |
| High slow queries | WARNING | >1000 |
| Replication broken | CRITICAL | IO/SQL not running |
| Replication lag | WARNING | >60 seconds |
Monitoring Automation
# Add to crontab for hourly checks
0 * * * * dargslan-mysql issues >> /var/log/mysql-health.log 2>&1
# Or use in Python monitoring script
import json
mh = MySQLHealth()
issues = mh.audit()
if any(i["severity"] == "critical" for i in issues):
# Send alert (email, Slack, PagerDuty, etc.)
send_alert("MySQL CRITICAL", json.dumps(issues))
Download the Free Cheat Sheet
Get the complete MySQL Health Checker Cheat Sheet PDF with all CLI commands and Python API reference.
Master Database Administration
Deepen your MySQL/MariaDB skills with our database administration eBooks. Check out all 20+ free Python CLI tools for Linux sysadmins.