Set up comprehensive MariaDB monitoring with mysqld_exporter, Prometheus metrics collection, and custom Grafana dashboards for database performance insights and alerting.
Prerequisites
- MariaDB 11.6 or compatible MySQL server
- Root access to the server
- At least 2GB RAM for monitoring stack
- Network access to download packages
What this solves
Monitoring MariaDB performance is essential for maintaining database health and preventing outages. This tutorial configures complete MariaDB monitoring with Prometheus metrics collection using mysqld_exporter and creates comprehensive Grafana dashboards for visualizing query performance, connection metrics, and resource usage.
Step-by-step configuration
Install MariaDB 11.6
Start by installing MariaDB 11.6 from the official repository to ensure you get the latest performance features.
sudo apt update
curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | sudo bash
sudo apt install -y mariadb-server mariadb-client
Secure MariaDB installation
Start MariaDB and run the security script to remove default accounts and set a root password.
sudo systemctl enable --now mariadb
sudo mysql_secure_installation
Create monitoring user
Create a dedicated MySQL user for Prometheus monitoring with minimal required privileges.
sudo mysql -u root -p
CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'StrongMonitoringPass123!';
GRANT PROCESS, REPLICATION CLIENT, SELECT ON . TO 'exporter'@'localhost';
GRANT SELECT ON performance_schema.* TO 'exporter'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Configure MariaDB for monitoring
Enable performance monitoring features in MariaDB configuration.
[mysqld]
Performance Schema
performance_schema = ON
performance_schema_consumer_events_statements_current = ON
performance_schema_consumer_events_statements_history = ON
performance_schema_consumer_events_statements_history_long = ON
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
General monitoring
general_log = 0
log_error = /var/log/mysql/error.log
innodb_monitor_enable = all
sudo systemctl restart mariadb
Install mysqld_exporter
Download and install the official Prometheus MySQL exporter for MariaDB metrics collection.
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.15.1/mysqld_exporter-0.15.1.linux-amd64.tar.gz
tar xzf mysqld_exporter-0.15.1.linux-amd64.tar.gz
sudo cp mysqld_exporter-0.15.1.linux-amd64/mysqld_exporter /usr/local/bin/
sudo chmod +x /usr/local/bin/mysqld_exporter
Create mysqld_exporter configuration
Configure the exporter with database connection credentials and security settings.
sudo useradd --no-create-home --shell /bin/false mysqld_exporter
[client]
user=exporter
password=StrongMonitoringPass123!
host=localhost
port=3306
sudo mkdir -p /etc/mysqld_exporter
sudo chown mysqld_exporter:mysqld_exporter /etc/mysqld_exporter
sudo chmod 600 /etc/mysqld_exporter/.my.cnf
Create mysqld_exporter systemd service
Set up mysqld_exporter as a systemd service for automatic startup and process management.
[Unit]
Description=MySQL Exporter
Wants=network-online.target
After=network-online.target
After=mariadb.service
[Service]
User=mysqld_exporter
Group=mysqld_exporter
Type=simple
ExecStart=/usr/local/bin/mysqld_exporter \
--config.my-cnf=/etc/mysqld_exporter/.my.cnf \
--collect.global_status \
--collect.info_schema.innodb_metrics \
--collect.auto_increment.columns \
--collect.info_schema.processlist \
--collect.binlog_size \
--collect.info_schema.tablestats \
--collect.global_variables \
--collect.info_schema.query_response_time \
--collect.info_schema.userstats \
--collect.info_schema.clientstats \
--collect.info_schema.tables \
--collect.perf_schema.tablelocks \
--collect.perf_schema.file_events \
--collect.perf_schema.eventswaits \
--collect.perf_schema.indexiowaits \
--collect.perf_schema.tableiowaits \
--collect.slave_status \
--web.listen-address=0.0.0.0:9104
SyslogIdentifier=mysqld_exporter
Restart=always
[Install]
WantedBy=multi-user.target
Start and enable mysqld_exporter
Enable the mysqld_exporter service to start on boot and verify it's collecting metrics.
sudo systemctl daemon-reload
sudo systemctl enable --now mysqld_exporter
sudo systemctl status mysqld_exporter
Install and configure Prometheus
Install Prometheus to collect and store MariaDB metrics from mysqld_exporter.
sudo apt install -y prometheus
Configure Prometheus for MariaDB monitoring
Add mysqld_exporter as a scrape target in Prometheus configuration.
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'mysqld'
static_configs:
- targets: ['localhost:9104']
scrape_interval: 10s
metrics_path: /metrics
params:
collect[]: ['mysql.global_status', 'mysql.global_variables']
- job_name: 'node'
static_configs:
- targets: ['localhost:9100']
scrape_interval: 15s
sudo systemctl restart prometheus
sudo systemctl enable prometheus
Install and configure Grafana
Install Grafana for creating MariaDB performance dashboards and alerting.
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
sudo apt update
sudo apt install -y grafana
Configure Grafana data source
Start Grafana and configure Prometheus as a data source for MariaDB metrics.
sudo systemctl enable --now grafana-server
Access Grafana at http://your-server:3000 with username admin and password admin. Add Prometheus data source:
- URL:
http://localhost:9090 - Access: Server (default)
- HTTP Method: GET
Import MariaDB dashboard
Create a comprehensive MariaDB monitoring dashboard with key performance metrics.
{
"dashboard": {
"id": null,
"title": "MariaDB Performance Monitor",
"tags": ["mariadb", "mysql", "database"],
"timezone": "browser",
"panels": [
{
"id": 1,
"title": "MySQL Uptime",
"type": "stat",
"targets": [
{
"expr": "mysql_global_status_uptime",
"legendFormat": "Uptime"
}
],
"gridPos": {"h": 4, "w": 6, "x": 0, "y": 0}
},
{
"id": 2,
"title": "Connections",
"type": "graph",
"targets": [
{
"expr": "rate(mysql_global_status_connections[5m])",
"legendFormat": "Connections/sec"
},
{
"expr": "mysql_global_status_threads_connected",
"legendFormat": "Connected Threads"
}
],
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 4}
},
{
"id": 3,
"title": "Query Rate",
"type": "graph",
"targets": [
{
"expr": "rate(mysql_global_status_queries[5m])",
"legendFormat": "Queries/sec"
},
{
"expr": "rate(mysql_global_status_questions[5m])",
"legendFormat": "Questions/sec"
}
],
"gridPos": {"h": 8, "w": 12, "x": 12, "y": 4}
},
{
"id": 4,
"title": "InnoDB Buffer Pool",
"type": "graph",
"targets": [
{
"expr": "mysql_global_status_innodb_buffer_pool_pages_data * mysql_global_variables_innodb_page_size",
"legendFormat": "Data Pages"
},
{
"expr": "mysql_global_status_innodb_buffer_pool_pages_free * mysql_global_variables_innodb_page_size",
"legendFormat": "Free Pages"
}
],
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 12}
}
],
"time": {
"from": "now-1h",
"to": "now"
},
"refresh": "30s"
}
}
Import this dashboard through Grafana UI: Dashboard → Import → Paste JSON.
Configure alerting rules
Set up Prometheus alerting rules for critical MariaDB metrics and performance thresholds.
groups:
- name: mariadb
rules:
- alert: MariaDBDown
expr: mysql_up == 0
for: 1m
labels:
severity: critical
annotations:
summary: "MariaDB instance is down"
description: "MariaDB database on {{ $labels.instance }} has been down for more than 1 minute"
- alert: MariaDBHighConnections
expr: mysql_global_status_threads_connected / mysql_global_variables_max_connections > 0.8
for: 5m
labels:
severity: warning
annotations:
summary: "MariaDB connection usage high"
description: "MariaDB is using {{ $value | humanizePercentage }} of max connections"
- alert: MariaDBSlowQueries
expr: rate(mysql_global_status_slow_queries[5m]) > 0.1
for: 5m
labels:
severity: warning
annotations:
summary: "MariaDB slow queries detected"
description: "MariaDB is experiencing {{ $value }} slow queries per second"
- alert: MariaDBInnoDBBufferPoolLow
expr: mysql_global_status_innodb_buffer_pool_pages_free / mysql_global_status_innodb_buffer_pool_pages_total < 0.1
for: 5m
labels:
severity: warning
annotations:
summary: "MariaDB InnoDB buffer pool usage high"
description: "InnoDB buffer pool free pages below 10%: {{ $value | humanizePercentage }}"
- alert: MariaDBReplicationLag
expr: mysql_slave_lag_seconds > 30
for: 2m
labels:
severity: critical
annotations:
summary: "MariaDB replication lag high"
description: "Replication lag is {{ $value }} seconds on {{ $labels.instance }}"
- alert: MariaDBTableLocks
expr: rate(mysql_global_status_table_locks_waited[5m]) > 0.1
for: 5m
labels:
severity: warning
annotations:
summary: "MariaDB table lock waits detected"
description: "Table locks waited: {{ $value }} per second"
Update Prometheus configuration for alerting
Include the MariaDB alerting rules in Prometheus configuration.
global:
scrape_interval: 15s
evaluation_interval: 15s
rule_files:
- "/etc/prometheus/mariadb-alerts.yml"
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'mysqld'
static_configs:
- targets: ['localhost:9104']
scrape_interval: 10s
metrics_path: /metrics
- job_name: 'node'
static_configs:
- targets: ['localhost:9100']
sudo systemctl reload prometheus
Install node_exporter for system metrics
Add system-level monitoring to correlate database performance with server resources.
wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz
tar xzf node_exporter-1.7.0.linux-amd64.tar.gz
sudo cp node_exporter-1.7.0.linux-amd64/node_exporter /usr/local/bin/
sudo useradd --no-create-home --shell /bin/false node_exporter
Create node_exporter service
Set up node_exporter as a systemd service for system metrics collection.
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter --web.listen-address=:9100
SyslogIdentifier=node_exporter
Restart=always
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now node_exporter
Verify your setup
Test that all monitoring components are working correctly and collecting MariaDB metrics.
# Check MariaDB status
sudo systemctl status mariadb
Verify mysqld_exporter metrics
curl http://localhost:9104/metrics | grep mysql_up
Check Prometheus targets
curl http://localhost:9090/api/v1/targets
Test database connection
mysql -u exporter -p -e "SHOW GLOBAL STATUS LIKE 'Uptime';"
Verify Grafana is accessible
curl -I http://localhost:3000
Check alert rules are loaded
curl http://localhost:9090/api/v1/rules
http://your-server:3000 and Prometheus at http://your-server:9090 to view dashboards and metrics.Key metrics to monitor
Focus on these critical MariaDB performance indicators in your Grafana dashboards:
| Metric | Description | Alert Threshold |
|---|---|---|
| mysql_up | Database availability | == 0 |
| mysql_global_status_threads_connected | Current connections | > 80% of max_connections |
| mysql_global_status_slow_queries | Slow query rate | > 0.1/sec |
| mysql_global_status_innodb_buffer_pool_hit_rate | Buffer pool efficiency | < 95% |
| mysql_global_status_table_locks_waited | Lock contention | > 0.1/sec |
| mysql_global_status_created_tmp_disk_tables | Disk temp tables | > 10% of tmp tables |
| mysql_slave_lag_seconds | Replication lag | > 30 seconds |
| mysql_global_status_aborted_connections | Failed connections | > 5% of total |
Advanced monitoring configuration
Enable query response time monitoring
Configure MariaDB to collect detailed query performance statistics.
sudo mysql -u root -p
INSTALL SONAME 'query_response_time';
SET GLOBAL query_response_time_stats = ON;
SET GLOBAL query_response_time_range_base = 10;
Configure custom mysqld_exporter collectors
Enable additional performance schema collectors for detailed monitoring.
[client]
user=exporter
password=StrongMonitoringPass123!
host=localhost
port=3306
[mysqld_exporter]
collect.global_status=true
collect.global_variables=true
collect.slave_status=true
collect.info_schema.processlist=true
collect.info_schema.tables=true
collect.info_schema.innodb_tablespaces=true
collect.info_schema.innodb_metrics=true
collect.perf_schema.tablelocks=true
collect.perf_schema.eventswaits=true
collect.perf_schema.file_events=true
Common issues
| Symptom | Cause | Fix |
|---|---|---|
| mysqld_exporter won't start | Incorrect database credentials | Verify user and password in /etc/mysqld_exporter/.my.cnf |
| No metrics in Prometheus | Exporter not accessible | Check firewall and service status: sudo systemctl status mysqld_exporter |
| Permission denied for monitoring user | Insufficient privileges | Grant required permissions: GRANT PROCESS, REPLICATION CLIENT, SELECT ON . TO 'exporter'@'localhost'; |
| Grafana dashboard empty | Wrong data source configuration | Verify Prometheus URL and test connection in Grafana |
| High CPU on mysqld_exporter | Too many collectors enabled | Disable unnecessary collectors in systemd service file |
| Alerts not firing | Alert rules not loaded | Check Prometheus config and reload: sudo systemctl reload prometheus |
| Connection refused to database | MariaDB not running | Start MariaDB: sudo systemctl start mariadb |
| Slow query log not working | Incorrect log file permissions | Fix ownership: sudo chown mysql:mysql /var/log/mysql/slow.log |
Security considerations
Secure your MariaDB monitoring setup with these production-ready configurations:
Restrict monitoring user access
Limit the monitoring user to specific hosts and minimal privileges.
-- Drop existing user if needed
DROP USER 'exporter'@'localhost';
-- Create user with host restriction
CREATE USER 'exporter'@'127.0.0.1' IDENTIFIED BY 'StrongMonitoringPass123!';
GRANT PROCESS, REPLICATION CLIENT ON . TO 'exporter'@'127.0.0.1';
GRANT SELECT ON performance_schema.* TO 'exporter'@'127.0.0.1';
FLUSH PRIVILEGES;
Secure configuration files
Protect credential files from unauthorized access.
sudo chmod 600 /etc/mysqld_exporter/.my.cnf
sudo chown mysqld_exporter:mysqld_exporter /etc/mysqld_exporter/.my.cnf
Verify permissions
ls -la /etc/mysqld_exporter/
This monitoring setup integrates well with MySQL backup monitoring with Prometheus alerts for comprehensive database operations oversight.
Performance optimization
Optimize your monitoring setup for production environments with high-volume databases:
Configure efficient scraping
Adjust scrape intervals based on your monitoring needs and database load.
scrape_configs:
- job_name: 'mysqld'
static_configs:
- targets: ['localhost:9104']
scrape_interval: 30s
scrape_timeout: 10s
metrics_path: /metrics
params:
collect[]:
- mysql.global_status
- mysql.global_variables
- mysql.slave_status
- mysql.info_schema.processlist
Optimize Prometheus retention
Configure appropriate data retention for MariaDB metrics storage.
ARGS="--config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus/ --storage.tsdb.retention.time=30d --storage.tsdb.retention.size=10GB --web.console.libraries=/etc/prometheus/console_libraries --web.console.templates=/etc/prometheus/consoles --web.enable-lifecycle"
sudo systemctl restart prometheus
For high-availability setups, consider implementing MariaDB Galera cluster for multi-master replication alongside this monitoring configuration.
Next steps
- Set up MySQL backup monitoring with Prometheus alerts for complete database operations oversight
- Configure MariaDB Galera cluster for multi-master replication to monitor high-availability database setups
- Configure Prometheus Alertmanager with Slack integration for team notifications
- Implement MariaDB connection pooling with ProxySQL monitoring
- Set up MariaDB master-slave replication with SSL encryption monitoring
Running this in production?
Automated install script
Run this to automate the entire setup
#!/usr/bin/env bash
set -euo pipefail
# MariaDB 11.6 monitoring setup with Prometheus and Grafana
# Supports Ubuntu, Debian, AlmaLinux, Rocky Linux, CentOS
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Default values
DB_ROOT_PASS="${1:-}"
MONITOR_PASS="${2:-StrongMonitoringPass123!}"
EXPORTER_VERSION="0.15.1"
# Usage message
usage() {
echo "Usage: $0 [db_root_password] [monitoring_password]"
echo " db_root_password: MariaDB root password (will prompt if not provided)"
echo " monitoring_password: Password for monitoring user (default: StrongMonitoringPass123!)"
exit 1
}
# Cleanup function
cleanup() {
echo -e "${RED}[ERROR]${NC} Installation failed. Cleaning up..."
systemctl stop mysqld_exporter 2>/dev/null || true
systemctl disable mysqld_exporter 2>/dev/null || true
rm -f /etc/systemd/system/mysqld_exporter.service
userdel mysqld_exporter 2>/dev/null || true
rm -rf /etc/mysqld_exporter
rm -f /usr/local/bin/mysqld_exporter
exit 1
}
trap cleanup ERR
# Check if running as root or with sudo
if [[ $EUID -ne 0 ]]; then
echo -e "${RED}[ERROR]${NC} This script must be run as root or with sudo"
exit 1
fi
# Auto-detect distribution
echo -e "${BLUE}[1/10]${NC} Detecting operating system..."
if [ -f /etc/os-release ]; then
. /etc/os-release
case "$ID" in
ubuntu|debian)
PKG_MGR="apt"
PKG_INSTALL="apt install -y"
PKG_UPDATE="apt update"
MYSQL_CONFIG_DIR="/etc/mysql/mysql.conf.d"
MYSQL_CONFIG_FILE="$MYSQL_CONFIG_DIR/mysqld.cnf"
;;
almalinux|rocky|centos|rhel|ol|fedora)
PKG_MGR="dnf"
PKG_INSTALL="dnf install -y"
PKG_UPDATE="dnf update -y"
MYSQL_CONFIG_DIR="/etc/mysql/mysql.conf.d"
MYSQL_CONFIG_FILE="/etc/my.cnf.d/server.cnf"
# Fallback for older systems
if ! command -v dnf &> /dev/null; then
PKG_MGR="yum"
PKG_INSTALL="yum install -y"
PKG_UPDATE="yum update -y"
fi
;;
amzn)
PKG_MGR="yum"
PKG_INSTALL="yum install -y"
PKG_UPDATE="yum update -y"
MYSQL_CONFIG_FILE="/etc/my.cnf.d/server.cnf"
;;
*)
echo -e "${RED}[ERROR]${NC} Unsupported distribution: $ID"
exit 1
;;
esac
echo -e "${GREEN}✓${NC} Detected: $PRETTY_NAME"
else
echo -e "${RED}[ERROR]${NC} Cannot detect operating system"
exit 1
fi
# Update system packages
echo -e "${BLUE}[2/10]${NC} Updating system packages..."
$PKG_UPDATE
# Install prerequisites
echo -e "${BLUE}[3/10]${NC} Installing prerequisites..."
$PKG_INSTALL curl wget tar
# Install MariaDB 11.6
echo -e "${BLUE}[4/10]${NC} Installing MariaDB 11.6..."
if ! command -v mysql &> /dev/null; then
curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | bash
$PKG_INSTALL mariadb-server mariadb-client
fi
# Start and enable MariaDB
echo -e "${BLUE}[5/10]${NC} Starting MariaDB service..."
systemctl enable mariadb
systemctl start mariadb
# Secure MariaDB installation
echo -e "${BLUE}[6/10]${NC} Securing MariaDB installation..."
if [[ -z "$DB_ROOT_PASS" ]]; then
echo -e "${YELLOW}[WARNING]${NC} Please enter MariaDB root password:"
read -s DB_ROOT_PASS
fi
# Run mysql_secure_installation programmatically
mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '$DB_ROOT_PASS';" 2>/dev/null || true
mysql -u root -p"$DB_ROOT_PASS" -e "DELETE FROM mysql.user WHERE User='';"
mysql -u root -p"$DB_ROOT_PASS" -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"
mysql -u root -p"$DB_ROOT_PASS" -e "DROP DATABASE IF EXISTS test;"
mysql -u root -p"$DB_ROOT_PASS" -e "FLUSH PRIVILEGES;"
# Create monitoring user
echo -e "${BLUE}[7/10]${NC} Creating monitoring user..."
mysql -u root -p"$DB_ROOT_PASS" << EOF
CREATE USER IF NOT EXISTS 'exporter'@'localhost' IDENTIFIED BY '$MONITOR_PASS';
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
GRANT SELECT ON performance_schema.* TO 'exporter'@'localhost';
FLUSH PRIVILEGES;
EOF
# Configure MariaDB for monitoring
echo -e "${BLUE}[8/10]${NC} Configuring MariaDB for monitoring..."
mkdir -p "$(dirname "$MYSQL_CONFIG_FILE")"
cat > "$MYSQL_CONFIG_FILE" << 'EOF'
[mysqld]
# Performance Schema
performance_schema = ON
performance_schema_consumer_events_statements_current = ON
performance_schema_consumer_events_statements_history = ON
performance_schema_consumer_events_statements_history_long = ON
# 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
# General monitoring
general_log = 0
log_error = /var/log/mysql/error.log
innodb_monitor_enable = all
EOF
# Create log directory
mkdir -p /var/log/mysql
chown mysql:mysql /var/log/mysql
chmod 755 /var/log/mysql
# Restart MariaDB to apply configuration
systemctl restart mariadb
# Install mysqld_exporter
echo -e "${BLUE}[9/10]${NC} Installing mysqld_exporter..."
cd /tmp
wget -q "https://github.com/prometheus/mysqld_exporter/releases/download/v${EXPORTER_VERSION}/mysqld_exporter-${EXPORTER_VERSION}.linux-amd64.tar.gz"
tar xzf "mysqld_exporter-${EXPORTER_VERSION}.linux-amd64.tar.gz"
cp "mysqld_exporter-${EXPORTER_VERSION}.linux-amd64/mysqld_exporter" /usr/local/bin/
chmod 755 /usr/local/bin/mysqld_exporter
rm -rf "mysqld_exporter-${EXPORTER_VERSION}.linux-amd64"*
# Create mysqld_exporter user and configuration
useradd --no-create-home --shell /bin/false mysqld_exporter || true
mkdir -p /etc/mysqld_exporter
cat > /etc/mysqld_exporter/.my.cnf << EOF
[client]
user=exporter
password=$MONITOR_PASS
host=localhost
port=3306
EOF
chown -R mysqld_exporter:mysqld_exporter /etc/mysqld_exporter
chmod 700 /etc/mysqld_exporter
chmod 600 /etc/mysqld_exporter/.my.cnf
# Create systemd service
cat > /etc/systemd/system/mysqld_exporter.service << 'EOF'
[Unit]
Description=MySQL Exporter
Wants=network-online.target
After=network-online.target
After=mariadb.service
[Service]
User=mysqld_exporter
Group=mysqld_exporter
Type=simple
ExecStart=/usr/local/bin/mysqld_exporter \
--config.my-cnf=/etc/mysqld_exporter/.my.cnf \
--collect.global_status \
--collect.info_schema.innodb_metrics \
--collect.auto_increment.columns \
--collect.info_schema.processlist \
--collect.binlog_size \
--collect.info_schema.tablestats \
--collect.global_variables \
--collect.info_schema.query_response_time \
--collect.info_schema.userstats \
--collect.info_schema.clientstats \
--collect.info_schema.tables \
--collect.perf_schema.tablelocks \
--collect.perf_schema.file_events \
--collect.perf_schema.eventswaits \
--collect.perf_schema.indexiowaits \
--collect.perf_schema.tableiowaits \
--collect.slave_status \
--web.listen-address=0.0.0.0:9104
SyslogIdentifier=mysqld_exporter
Restart=always
[Install]
WantedBy=multi-user.target
EOF
# Enable and start mysqld_exporter
systemctl daemon-reload
systemctl enable mysqld_exporter
systemctl start mysqld_exporter
# Configure firewall based on distribution
if command -v ufw &> /dev/null; then
ufw allow 9104/tcp
elif command -v firewall-cmd &> /dev/null; then
firewall-cmd --permanent --add-port=9104/tcp
firewall-cmd --reload
fi
# Verification
echo -e "${BLUE}[10/10]${NC} Verifying installation..."
sleep 5
if ! systemctl is-active --quiet mariadb; then
echo -e "${RED}✗${NC} MariaDB service is not running"
exit 1
fi
if ! systemctl is-active --quiet mysqld_exporter; then
echo -e "${RED}✗${NC} mysqld_exporter service is not running"
exit 1
fi
if ! curl -sf http://localhost:9104/metrics > /dev/null; then
echo -e "${RED}✗${NC} mysqld_exporter metrics endpoint is not responding"
exit 1
fi
echo -e "${GREEN}✓${NC} MariaDB monitoring setup completed successfully!"
echo -e "${GREEN}✓${NC} MariaDB 11.6 is running on port 3306"
echo -e "${GREEN}✓${NC} mysqld_exporter is running on port 9104"
echo -e "${YELLOW}[INFO]${NC} Metrics endpoint: http://$(hostname -I | awk '{print $1}'):9104/metrics"
echo -e "${YELLOW}[INFO]${NC} Add this target to your Prometheus configuration:"
echo -e " - job_name: 'mariadb'"
echo -e " static_configs:"
echo -e " - targets: ['$(hostname -I | awk '{print $1}'):9104']"
Review the script before running. Execute with: bash install.sh