Virtual databases (in the cloud, on VMs, or in containers) are the backbone of modern applications. However, their dynamic nature creates challenges: from resource contention to hidden failures invisible at the OS level. Without robust monitoring, these issues lead to downtime and losses. Zabbix is an open-source tool that enables comprehensive monitoring of database health across all layers, from infrastructure to business metrics. This guide will help you set up monitoring for virtual databases using Zabbix, ensuring transparency and control.
Deploying Zabbix
Architecture:
Installation Steps:
1. Install Server: Sets up the server and web interface with PostgreSQL support.
wget https://repo.zabbix.com/zabbix/6.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.4-1+ubuntu22.04_all.deb
dpkg -i zabbix-release_6.4-1+ubuntu22.04_all.deb
apt update
apt install zabbix-server-pgsql zabbix-frontend-php php-pgsql zabbix-apache-conf
2. Configure Database: Creates a database for Zabbix data storage.
CREATE USER zabbix_user WITH PASSWORD 'StrongPassword';
GRANT ALL PRIVILEGES ON DATABASE zabbix_db TO zabbix_user;
3. Import Schema: Populates the database with initial data.
4. Configure Server: Connects the server to the database.
DBHost=localhost
DBName=zabbix_db
DBUser=zabbix_user
DBPassword=StrongPassword
5. Start Services: Launches Zabbix and the web server.
systemctl enable zabbix-server
Configuring PostgreSQL Monitoring
1. Install Agent: The agent collects metrics from the database server.
2. Configure Access: Create a user for PostgreSQL monitoring.
GRANT pg_monitor TO zabbix_mon;
3. Configure Agent: Defines custom parameters for metric collection.
UserParameter=pg.connections[*], psql -U zabbix_mon -c "SELECT COUNT(*) FROM pg_stat_activity WHERE state = 'active'" -t
UserParameter=pg.locks[*], psql -U zabbix_mon -c "SELECT COUNT(*) FROM pg_locks" -t
4. Configure Template in Zabbix:
- Import "PostgreSQL by Zabbix agent".
- Assign to the host.
- Set macros: `{$PG.USER}=zabbix_mon`, `{$PG.PASSWORD}=MonitorPass`.
Configuring MySQL Monitoring
1. Create User: Create a user for MySQL monitoring.
GRANT PROCESS, REPLICATION CLIENT ON *.* TO 'zabbix_mon'@'localhost';
GRANT SELECT ON performance_schema.* TO 'zabbix_mon'@'localhost';
2. Configure Access: Simplifies agent connection.
[client]
user=zabbix_mon
password=MonitorPass
3. Configure Agent: Collects basic MySQL metrics.
UserParameter=mysql.connections,mysqladmin status | awk '{print $$4}'
UserParameter=mysql.queries_per_sec,mysqladmin status | awk '{print $$6}'
4. Use Template: Apply "MySQL by Zabbix agent" with macros:
`{$MYSQL.USER}=zabbix_mon`, `{$MYSQL.PASSWORD}=MonitorPass`.
Key Metrics for SRE
Example Trigger:
Fires if the number of connections exceeds 90% of the maximum.
{Template DB PostgreSQL:pg.max_connections.last()} * 100 > 90
Zabbix provides deep monitoring of virtual databases, enabling SREs to predict and prevent issues. This guide offers a basic setup for PostgreSQL and MySQL, which can be extended to meet your needs.