Configure Netdata MySQL monitoring and database performance alerts

Intermediate 25 min May 10, 2026 94 views
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

Set up comprehensive MySQL monitoring with Netdata for real-time database performance metrics, query analysis, and automated alerts. Monitor connection pools, slow queries, and resource usage with production-grade alerting.

Prerequisites

  • MySQL or MariaDB server running
  • Root or sudo access
  • Basic MySQL administration knowledge

What this solves

Netdata provides real-time MySQL monitoring with zero-configuration autodiscovery, detailed performance metrics, and built-in alerting. This tutorial shows you how to configure Netdata to monitor MySQL databases, set up performance alerts for critical metrics like slow queries and connection pool exhaustion, and create custom dashboards for database health monitoring.

Step-by-step installation

Update system packages

Start by updating your package manager to ensure you get the latest versions of all packages.

sudo apt update && sudo apt upgrade -y
sudo dnf update -y

Install Netdata monitoring agent

Install Netdata using the official one-line installer script, which automatically detects your system and installs the appropriate packages.

bash <(curl -Ss https://my-netdata.io/kickstart.sh) --stable-channel --disable-telemetry

The installer will compile Netdata from source and install it with systemd integration. This process takes 3-5 minutes depending on your system.

Install MySQL development packages

Install MySQL client libraries that Netdata requires for database connectivity and metric collection.

sudo apt install -y libmysqlclient-dev mysql-client
sudo dnf install -y mysql-devel mysql

Create MySQL monitoring user

Create a dedicated MySQL user for Netdata with minimal privileges required for monitoring. This follows the principle of least privilege for security.

mysql -u root -p

Run these SQL commands to create the monitoring user:

CREATE USER 'netdata'@'localhost' IDENTIFIED BY 'StrongPassword123!';
GRANT USAGE ON . TO 'netdata'@'localhost';
GRANT REPLICATION CLIENT ON . TO 'netdata'@'localhost';
GRANT PROCESS ON . TO 'netdata'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Configure Netdata MySQL collector

Create the MySQL collector configuration file to specify database connection details and monitoring parameters.

# MySQL monitoring configuration

Multiple MySQL instances can be monitored

localhost: name: 'local_mysql' host: '127.0.0.1' port: 3306 user: 'netdata' pass: 'StrongPassword123!' update_every: 5 priority: 90000 retries: 5 # Enable detailed metrics collection my_cnf: '/etc/mysql/my.cnf' socket: '/var/run/mysqld/mysqld.sock' # Monitor specific databases (optional) # exclude_databases: 'information_schema performance_schema sys mysql' # SSL configuration (if MySQL uses SSL) # ssl_ca: '/path/to/ca-cert.pem' # ssl_cert: '/path/to/client-cert.pem' # ssl_key: '/path/to/client-key.pem'

Enable Python plugins for MySQL monitoring

Enable the Python plugin system and ensure MySQL collector is active by editing the main configuration.

[plugins]
    # Enable python.d plugin
    python.d = yes
    
[plugin:python.d]
    # MySQL monitoring enabled
    mysql = yes
    
    # Update frequency for MySQL metrics (seconds)
    update every = 5
    
    # Command timeout for MySQL queries
    command options = 

Configure MySQL performance alerts

Create custom alert rules for MySQL performance monitoring by creating an alert configuration file.

# MySQL Connection Pool Alerts
alarm: mysql_connections_usage
    on: mysql_localhost.connections
  calc: $used * 100 / $max
  warn: $this > 70
  crit: $this > 85
 every: 10s
 units: %
  info: MySQL connection pool usage percentage
    to: sysadmin

MySQL Slow Queries Alert

alarm: mysql_slow_queries_rate on: mysql_localhost.slow_queries calc: $slow_queries warn: $this > 5 crit: $this > 20 every: 60s units: queries/s info: MySQL slow queries per second to: dba

MySQL Query Cache Hit Rate

alarm: mysql_qcache_hit_rate on: mysql_localhost.qcache_ops calc: $hits * 100 / ($hits + $inserts + $not_cached) warn: $this < 80 crit: $this < 60 every: 60s units: % info: MySQL query cache hit rate percentage to: dba

MySQL InnoDB Buffer Pool Usage

alarm: mysql_innodb_buffer_pool_usage on: mysql_localhost.innodb_buffer_pool_pages calc: $used * 100 / $total warn: $this > 85 crit: $this > 95 every: 30s units: % info: MySQL InnoDB buffer pool usage percentage to: sysadmin

MySQL Replication Lag (if using replication)

alarm: mysql_slave_lag on: mysql_localhost.slave_lag calc: $seconds warn: $this > 30 crit: $this > 120 every: 30s units: seconds info: MySQL slave replication lag in seconds to: dba

MySQL Lock Waits

alarm: mysql_innodb_lock_waits on: mysql_localhost.innodb_lock_structs calc: $lock_structs warn: $this > 100 crit: $this > 500 every: 30s units: locks info: MySQL InnoDB lock structures count to: dba

Configure email notifications

Set up email notifications for MySQL alerts by configuring the health notification system.

# Email notification configuration
SEND_EMAIL="YES"
DEFAULT_RECIPIENT_EMAIL="admin@example.com"
EMAIL_SENDER="netdata@example.com"

SMTP configuration

EMAIL_SMTP_SERVER="smtp.example.com" EMAIL_SMTP_PORT="587" EMAIL_SMTP_USERNAME="netdata@example.com" EMAIL_SMTP_PASSWORD="your_smtp_password" EMAIL_SMTP_SECURE="STARTTLS"

Role-based recipients

role_recipients_sysadmin="sysadmin@example.com" role_recipients_dba="dba@example.com"

Notification frequency

DEFAULT_RECIPIENT_CUSTOM_FREQUENCIES="critical:10m, warning:1h"

Enable HTML email format

EMAIL_PLAINTEXT_ONLY="NO"

Enable and restart Netdata service

Restart Netdata to apply the MySQL monitoring configuration and alert rules.

sudo systemctl restart netdata
sudo systemctl enable netdata
sudo systemctl status netdata

Configure firewall for Netdata web interface

Open port 19999 to access the Netdata web dashboard from your local network or specific IP addresses.

sudo ufw allow from 192.168.1.0/24 to any port 19999
sudo ufw reload
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" port protocol="tcp" port="19999" accept'
sudo firewall-cmd --reload
Security Note: Replace 192.168.1.0/24 with your actual network range. Never expose Netdata to the public internet without authentication.

Advanced MySQL monitoring configuration

Enable MySQL performance schema monitoring

Configure additional MySQL performance metrics by enabling Performance Schema monitoring in your MySQL configuration.

[mysqld]

Enable Performance Schema

performance_schema = ON performance_schema_max_table_instances = 400 performance_schema_max_table_handles = 4000 performance_schema_events_statements_history_size = 20 performance_schema_events_statements_history_long_size = 1000

Enable slow query log

slow_query_log = 1 slow_query_log_file = /var/log/mysql/slow.log long_query_time = 2 log_queries_not_using_indexes = 1

Enable general log for debugging (disable in production)

general_log = 1

general_log_file = /var/log/mysql/general.log

Create advanced MySQL metrics collector

Configure Netdata to collect additional MySQL metrics including table statistics and custom queries.

advanced_mysql:
    name: 'mysql_performance'
    host: '127.0.0.1'
    port: 3306
    user: 'netdata'
    pass: 'StrongPassword123!'
    update_every: 10
    
    # Custom queries for specific metrics
    queries:
        table_stats:
            query: 'SELECT table_schema, COUNT(*) as table_count FROM information_schema.tables WHERE table_schema NOT IN ("information_schema", "performance_schema", "sys", "mysql") GROUP BY table_schema'
            dimensions:
                - name: 'table_count'
                  algorithm: 'absolute'
                  multiplier: 1
                  divisor: 1
        
        connection_errors:
            query: 'SHOW GLOBAL STATUS LIKE "Connection_errors%"'
            dimensions:
                - name: 'Connection_errors_accept'
                - name: 'Connection_errors_internal'
                - name: 'Connection_errors_max_connections'
                - name: 'Connection_errors_peer_address'
                - name: 'Connection_errors_select'
                - name: 'Connection_errors_tcpwrap'

Verify your setup

Check that Netdata is running and collecting MySQL metrics correctly.

# Check Netdata service status
sudo systemctl status netdata

Verify MySQL plugin is loaded

sudo netdata -W debug 2>&1 | grep -i mysql

Check MySQL connectivity from Netdata

sudo -u netdata mysql -h 127.0.0.1 -u netdata -p -e "SHOW STATUS LIKE 'Uptime';"

Test alert configuration

sudo /usr/libexec/netdata/plugins.d/alarm-notify.sh test

View real-time MySQL metrics

curl -s http://localhost:19999/api/v1/charts | grep mysql

Access the Netdata web interface at http://your-server-ip:19999. Navigate to the MySQL section to see database performance charts including connections, queries per second, slow queries, and buffer pool usage.

Key metrics to monitor: Focus on connection usage (should stay below 80%), query cache hit rate (above 80%), slow queries per second (minimize), and InnoDB buffer pool efficiency (above 95%).

Configure Slack notifications

Set up Slack webhook integration

Configure Netdata to send MySQL alerts to Slack channels for team notifications.

# Slack notification configuration
SEND_SLACK="YES"
SLACK_WEBHOOK_URL="https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK"
DEFAULT_RECIPIENT_SLACK="#alerts"

Role-specific Slack channels

role_recipients_sysadmin="#sysadmin-alerts" role_recipients_dba="#database-alerts"

Slack message customization

SLACK_CHANNEL="#netdata-alerts" SLACK_USERNAME="NetdataBot" SLACK_ICON_EMOJI=":exclamation:"

Message format

SLACK_DETAILED_MESSAGES="YES"

Common issues

SymptomCauseFix
MySQL charts not appearingPython MySQL module not installedsudo pip3 install PyMySQL or sudo apt install python3-pymysql
Connection refused to MySQLWrong credentials or hostTest connection manually: mysql -h 127.0.0.1 -u netdata -p
Alerts not triggeringAlert configuration syntax errorCheck logs: sudo journalctl -u netdata | grep -i health
Email notifications not workingSMTP configuration issuesTest email: sudo /usr/libexec/netdata/plugins.d/alarm-notify.sh test
High CPU usage from NetdataToo frequent MySQL pollingIncrease update_every from 5 to 10 seconds in MySQL config
Missing InnoDB metricsMySQL user lacks PROCESS privilegeGrant privilege: GRANT PROCESS ON . TO 'netdata'@'localhost';
Slow query alerts false positiveThreshold too low for workloadAdjust slow query alert threshold in /etc/netdata/health.d/mysql_custom.conf

Performance tuning for MySQL monitoring

To optimize Netdata's impact on MySQL performance while maintaining comprehensive monitoring:

  • Set MySQL collector update_every to 10-15 seconds for production systems
  • Use connection pooling by configuring max_connections appropriately
  • Monitor only critical databases by using exclude_databases option
  • Enable MySQL query cache to reduce repetitive query overhead
  • Consider using a dedicated read-only replica for monitoring if available

For high-traffic MySQL instances, you may want to explore Prometheus-based MySQL monitoring which offers more granular control over metric collection frequency and retention.

Next steps

Running this in production?

Need comprehensive database monitoring? Setting this up once is straightforward. Keeping it patched, monitored, backed up and performant across environments is the harder part. See how we run infrastructure like this for European teams.

Automated install script

Run this to automate the entire setup

Need help?

Don't want to manage this yourself?

We handle managed devops services for businesses that depend on uptime. From initial setup to ongoing operations.