UnderHost
Knowledgebase Docs

Database monitoring: health and performance metrics

Monitor MySQL/MariaDB health, query performance, disk usage, connections, and detect issues before they impact users.

On this page

Database monitoring is the backbone of reliable web hosting. It detects problems before they impact your users: slow queries degrade performance, connection exhaustion causes lockouts, disk full crashes applications, and resource leaks can bring down entire servers. Proactive monitoring with alerts prevents outages, improves responsiveness, and gives you early warning before problems escalate.

Check database status

Start with real-time status checks to see if the database is healthy right now:

# Active connections and threads
SHOW STATUS LIKE 'Threads%';

# Currently running queries
SHOW PROCESSLIST;

# Connection limits
SHOW VARIABLES LIKE 'max_connections';

Watch for:

  • High thread count: Many simultaneous connections can exhaust resources
  • Long-running queries: Queries stuck for hours indicate problems
  • Connections approaching max_connections: When you hit the limit, new clients get rejected

Monitor performance metrics

Check query load

Track total queries being executed to detect if load is increasing:

SHOW STATUS LIKE 'Queries';     # All queries executed
SHOW STATUS LIKE 'Questions';   # Client queries (internal ones excluded)

What's normal? A WordPress site with 100 visitors/day might execute 100-500 queries. If your numbers suddenly 10x, something's wrong—usually a runaway plugin or misconfiguration.

Check slow queries

MySQL can log queries taking longer than a threshold, letting you identify bottlenecks:

# Enable slow query log (add to /etc/my.cnf)
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow-query.log
long_query_time = 2  # Log queries >2 seconds

# View slow queries
tail -50 /var/log/mysql/slow-query.log

# Analyze with mysqldumpslow
mysqldumpslow /var/log/mysql/slow-query.log | head -20

Check table health and fragmentation

Over time, tables become fragmented (wasted space), slowing queries:

SELECT TABLE_NAME, DATA_FREE, INDEX_LENGTH, DATA_LENGTH
FROM information_schema.TABLES
WHERE TABLE_SCHEMA='mydb'
ORDER BY DATA_FREE DESC;

High DATA_FREE values indicate fragmentation. Fix with: OPTIMIZE TABLE tablename;

Monitor connections and locks

Connection exhaustion and locks are common problems:

# See current connections
SHOW PROCESSLIST;

# Count connections by user
SELECT USER, COUNT(*) FROM information_schema.PROCESSLIST GROUP BY USER;

# Check wait events (what's blocking)
SHOW OPEN TABLES WHERE In_use > 0;

On shared hosting: You typically have 10-50 connections. On VPS/Dedicated: You can have hundreds, but too many still slows things down.

Check disk usage and free space

Running out of disk space is a catastrophic failure—the database will crash when it can't write:

# Overall MySQL disk space
df -h /var/lib/mysql

# Size by database
du -sh /var/lib/mysql/*

# Table sizes in current database
SELECT TABLE_NAME, ROUND(((data_length + index_length) / 1024 / 1024), 2) AS size_mb
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'mydb'
ORDER BY size_mb DESC;

Critical: Keep at least 10% disk free. Many hosts enforce limits—check your control panel (cPanel/aaPanel/CloudPanel) for current usage.

Built-in monitoring tools

ToolLocation/AccessWhat it shows
cPanel MetricscPanel → MetricsCPU, memory, disk, MySQL process usage
phpMyAdmincPanel → phpMyAdminDatabase sizes, table info, slow query analysis
aaPanel DashboardaaPanel Web UIReal-time server and database stats
CloudPanelCloudPanel Web UIPer-domain resource usage, database metrics
Percona Monitoring (PMM)Optional third-partyProfessional-grade MySQL monitoring and alerting

Set up automated alerts

Don't just monitor manually—set up alerts! A problem you discover at 3 AM because of an email is better than discovering it because your site went down.

Key metrics to alert on:

  • Disk usage >85%: You're running out of space
  • Connections >90% of max: Risk of connection exhaustion
  • Query time >5 seconds: Individual queries are slow
  • CPU usage >80%: Server is working hard, risk of slowdown
  • MySQL restart: Service crashed and auto-restarted (investigate why)

Alert options:

  • cPanel has basic alerting email notifications
  • aaPanel/CloudPanel built-in alerts
  • Custom bash scripts that run via cron and email you
  • Third-party services like Uptime Robot, Datadog, or New Relic

Monitor database replication (VPS/Dedicated)

If you're running a replicated database (backup server), monitor replication status:

SHOW SLAVE STATUS\G

Look for Seconds_Behind_Master—anything >0 means the replica is falling behind.

Monitoring best practices

  • Monitor continuously: Set up automated checks every 5-15 minutes
  • Keep historical data: Track trends over weeks/months to see if load is growing
  • Set baseline metrics: Know what "normal" looks like for your application so anomalies stand out
  • Act on alerts: If an alert fires, investigate—don't ignore
  • Document issues: Keep notes on what you found and how you fixed it
  • Test recovery procedures: Know how to restore from backups if needed
Monitor before you have problems

Setting up monitoring when your site is running smoothly makes it easy to spot changes. Waiting until things are broken makes diagnosis much harder. Start now.

Related: Slow query analysis | Database administration | MySQL performance tuning

Was this article helpful?

Need hosting for database-backed apps?

Run WordPress, CMS, PHP apps, and MySQL/MariaDB workloads on UnderHost hosting, VPS, or managed servers.

Related articles

Back to Database