How to Monitor Your MySQL Database with Vigilmon
MySQL powers some of the world's busiest applications — WordPress, Shopify, and countless others. When MySQL goes down, your entire application stops. Setting up reliable monitoring is one of the highest-leverage investments you can make.
This guide shows you how to monitor MySQL using Vigilmon, a free uptime monitoring platform built for developers.
Common MySQL Failure Modes
MySQL doesn't just "go down" — it degrades:
-
Max connections reached — new connections get
Too many connectionserrors - Deadlocks — transactions lock each other out and roll back
- InnoDB buffer pool pressure — disk I/O spikes as memory runs out
- Replication broken — your replica stops syncing, serving stale reads
- Slow query accumulation — one bad query brings the server to a crawl
Vigilmon catches the end result: when your app can't reach MySQL, your health endpoint returns an error and Vigilmon fires an alert within 60 seconds.
Building a MySQL Health Endpoint
PHP / Laravel
// routes/api.php
Route::get('/health/db', function () {
try {
DB::select('SELECT 1');
return response()->json(['status' => 'ok', 'db' => 'mysql'], 200);
} catch (\Exception $e) {
return response()->json(['status' => 'error', 'db' => $e->getMessage()], 503);
}
});
Python / Django
from django.http import JsonResponse
from django.db import connections
from django.db.utils import OperationalError
def health_mysql(request):
try:
conn = connections['default']
conn.cursor().execute('SELECT 1')
return JsonResponse({'status': 'ok', 'db': 'mysql'})
except OperationalError as e:
return JsonResponse({'status': 'error', 'db': str(e)}, status=503)
Node.js / Express
const mysql2 = require('mysql2/promise');
const pool = mysql2.createPool({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
waitForConnections: true,
connectionLimit: 10
});
app.get('/health/db', async (req, res) => {
try {
await pool.query('SELECT 1');
res.json({ status: 'ok', db: 'mysql' });
} catch (err) {
res.status(503).json({ status: 'error', db: err.message });
}
});
Setting Up Vigilmon Monitoring
- Create a free account at vigilmon.online
- Add an HTTP monitor pointing to
/health/db - Set check interval: 1 minute
- Configure alerts (email, Slack webhook, or PagerDuty)
- Enable multi-region consensus — Vigilmon won't alert unless multiple regions confirm the failure
TCP Port Monitor (Backup)
MySQL listens on port 3306. Add a TCP monitor as a secondary check:
- Host: your MySQL server IP or hostname
- Port:
3306 - This catches cases where MySQL crashes completely
Advanced MySQL Health Checks
Check Connection Count
SHOW STATUS LIKE 'Threads_connected';
-- Alert if Threads_connected > 80% of max_connections
SHOW VARIABLES LIKE 'max_connections';
Check Replication Status
SHOW SLAVE STATUS\G
-- Look for:
-- Slave_IO_Running: Yes
-- Slave_SQL_Running: Yes
-- Seconds_Behind_Master: 0
Slow Query Detection
SHOW STATUS LIKE 'Slow_queries';
Response Time Monitoring
Vigilmon tracks not just uptime but response time. For MySQL health endpoints:
- <50ms: Healthy — simple SELECT 1 should return instantly
- 50-200ms: Degraded — MySQL is under load
- >500ms: Critical — likely lock contention or I/O pressure
Set a response time alert at 300ms to catch slowdowns before they become outages.
Alerting Strategy
| Scenario | Alert Severity | Action |
|---|---|---|
/health/db returns 503 |
Critical — page on-call | Restart MySQL or failover |
| Response time >300ms | Warning — Slack alert | Check slow query log |
| TCP 3306 not responding | Critical — page on-call | Check MySQL process |
| Replication lag >30s | Warning | Check replica error log |
Production Checklist
- [ ] Health endpoint with
SELECT 1and timeout - [ ] TCP monitor on port 3306
- [ ] Replication health endpoint (if using replicas)
- [ ] Response time threshold alert (300ms)
- [ ] Alert routing: critical → PagerDuty, warning → Slack
- [ ] Maintenance windows for schema migrations
Why Multi-Region Monitoring Matters
A single-location health check generates false positives from regional network blips. Vigilmon runs checks from multiple global regions and only alerts when a majority confirm the failure. This eliminates alert fatigue while keeping true MTTD under 2 minutes.
Start monitoring your MySQL database for free →
Vigilmon is an uptime monitoring platform for developers. Free tier includes 10 monitors with 1-minute checks.
Top comments (0)