Monitoring guide
MySQL monitoring: key metrics and alerts
MySQL problems usually show up as slow queries, full connection limits or replicas falling behind. A handful of status variables and the slow log cover most of it.
4 min read14 sectionsUpdated
On this page
SHOW GLOBAL STATUS WHERE Variable_name IN
('Threads_connected','Threads_running','Questions','Slow_queries',
'Innodb_buffer_pool_reads','Innodb_buffer_pool_read_requests','Aborted_connects');
-- replication (8.0.22+)
SHOW REPLICA STATUS\G -- Seconds_Behind_Source, Replica_IO_Running, Replica_SQL_Running| Metric | Healthy | Worry when |
|---|---|---|
| Threads_connected / max_connections | Comfortable headroom | Above 80% |
| Threads_running | Low single or double digits | Spikes: queries piling up |
| Buffer pool hit rate = 1 − reads ÷ read_requests | Above 99% for OLTP | Dropping: working set does not fit |
| Slow_queries rate | Low and stable | Rising after a deploy |
| Seconds_Behind_Source | Near 0 | Above your RPO, or NULL (replication stopped) |
-- enable the slow log
SET GLOBAL slow_query_log = 'ON';
SET GLOBAL long_query_time = 0.5;
-- top statements by total time (performance_schema)
SELECT DIGEST_TEXT, COUNT_STAR, ROUND(SUM_TIMER_WAIT/1e12, 1) AS total_s, ROUND(AVG_TIMER_WAIT/1e9, 1) AS avg_ms
FROM performance_schema.events_statements_summary_by_digest
ORDER BY SUM_TIMER_WAIT DESC LIMIT 10;Collecting metrics continuously
The OpenTelemetry Collector's mysql receiver reads these status variables on a schedule (use a read-only user):
receivers:
mysql:
endpoint: db:3306
username: otel_monitor
password: ${env:MYSQL_MONITOR_PASSWORD}
collection_interval: 60s
exporters:
otlphttp/vitalrix:
encoding: json
metrics_endpoint: ${env:VITALRIX_API}/api/v1/metrics/otlp/v1/metrics
headers: { x-api-key: ${env:VITALRIX_KEY} }
service:
pipelines:
metrics: { receivers: [mysql], exporters: [otlphttp/vitalrix] }MySQL monitoring with VitalRix
Collector metrics arrive over OTLP and can be charted on dashboards and used in alert rules. A TCP check confirms MySQL accepts connections from the network your app uses, and APM traces show which requests wait on MySQL and for how long, from the client spans your instrumented services create. See also MySQL too many connections and finding slow database queries.
Alerts to start with
- Threads_connected above 80% of max_connections for 5 minutes.
- Threads_running above a level you rarely see (for example 30) for 5 minutes.
- Replication: Seconds_Behind_Source above your RPO, or replication threads not running.
- Disk used above 80% on the data volume.
- MySQL not answering a TCP check from the application network.
- Database time per request rising in APM traces.
| Metric | Source | Starting alert |
|---|---|---|
| Threads_connected vs max_connections | SHOW GLOBAL STATUS / VARIABLES | Above 80% |
| Threads_running | SHOW GLOBAL STATUS | Sustained above the number of CPU cores |
| Slow queries | Slow query log (long_query_time) | A rising rate after a deploy |
| Replication lag | Seconds_Behind_Source in SHOW REPLICA STATUS | Above 30 seconds, or NULL (replication stopped) |
| InnoDB buffer pool hit ratio | 1 - Innodb_buffer_pool_reads / Innodb_buffer_pool_read_requests | Below 99% on a hot database |
| Aborted connects | Aborted_connects | A spike: wrong credentials or a network problem |
| Deadlocks | SHOW ENGINE INNODB STATUS, or innodb_print_all_deadlocks | Any repeated pattern |
-- turn on the slow query log without a restart
SET GLOBAL slow_query_log = ON;
SET GLOBAL long_query_time = 1;
-- what is running right now, longest first
SELECT id, user, time, state, left(info, 80) FROM information_schema.processlist WHERE command <> 'Sleep' ORDER BY time DESC LIMIT 10;
-- replication health (MySQL 8.0.22+; older versions: SHOW SLAVE STATUS)
SHOW REPLICA STATUS\GWhat the incidents look like
- "Too many connections" when application pools grow faster than max_connections: see MySQL too many connections.
- Threads_running spikes with a pile of identical queries: usually a missing index or a cache that expired and sent every request to the database at once.
- Replication stops after an error on the replica, and Seconds_Behind_Source becomes NULL; an alert on "lag above 30 s" alone never fires. Alert on NULL too.
- Disk fills with binary logs when binlog_expire_logs_seconds is unset on an old server.
Pair database metrics with APM: a trace shows which endpoint sends the slow query, so the fix lands in the right code.
What is a good buffer pool size?
On a dedicated database server, often 50 to 75% of RAM, so the working set fits. Check the hit rate rather than guessing.
Does monitoring add load to MySQL?
Reading status variables every minute is negligible. Long-running performance_schema queries should run off-peak.
Check it now, free
- Response time checker: Measure TTFB with DNS, connect, TLS and server time.
Related reading
- MongoDB monitoring: metrics that matter: Monitor MongoDB: operation rates and latency, slow queries from the profiler, WiredTiger cache, connections, replication lag and oplog window.
- MySQL slow query log: how to enable and read it: Enable the MySQL slow query log without a restart, choose a sensible threshold, summarise it with mysqldumpslow and pt-query-digest, and fix what it finds.
- Nginx monitoring: status, logs and alerts: Monitor Nginx with stub_status and JSON access logs: active and dropped connections, request rate, 5xx share, upstream time and alerts to set.
- Next.js performance monitoring: Monitor Next.js apps end to end: Core Web Vitals from real users, server rendering and route handler latency with OpenTelemetry, caching behaviour and errors.
- Why is my website slow? A step-by-step diagnosis: Diagnose a slow website in order: server, loading, stability and responsiveness. Use real-user data, lab tests and traces to find what to fix first.
- Node.js performance monitoring: Monitor Node.js apps: event loop delay, heap and garbage collection, request latency per route, outgoing calls and errors.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.