How to Monitor MySQL or MariaDB Database Server Using Icinga2 On Ubuntu 22.04 LTS Server

Published: 21 December 2022
on channel: The Lazy SysAdmin
2,599
35

In this video, you will learn how to configure Icinga to monitor your MySQL source and replica servers in your clusters.

Join this channel to get access to perks: https://www.youtube.com/@lazysysad/join

You will learn how to use the check-mysql-health plugin to monitor various states of your MySQL database. Such as the database uptime, database size, the clients that are currently connected to the database, and the replication status.

PLEASE SUBSCRIBE :)
PLEASE HIT LIKE IF IT HELPED :)

GIVE SUPPORT -   / lazysysad  
BUY ME A COFFEE - https://www.buymeacoffee.com/lazysysad
PAYPAL - https://paypal.me/lazysysad

LINKS:
Icinga2 Master Installation and Configuration -    • How to Monitor Entire Infrastructure ...  
Icinga2 Agent Installation and Configuration -    • Icinga2 Agent Installation and Config...  
MySQL8 Replication -    • How to Configure MySQL 8.0 Master-Sla...  
Using SQL Queries to Monitor MySQL Using Icinga2 -    • How to use SQL Queries to Monitor MyS...  
check_mysql_health - https://labs.consol.de/nagios/check_m...

Steps:
mysql -u root -p
CREATE USER 'icinga'@'icinga.lazy.test' IDENTIFIED WITH mysql_native_password BY 'password';
GRANT USAGE ON mysql.* TO 'icinga'@'icinga.lazy.test';
apt --no-install-recommends install monitoring-plugins-contrib
/usr/lib/nagios/plugins/check_mysql_health -h

vi /etc/icinga2/conf.d/mysql-source.lazy.test.conf
object Host "mysql-source.lazy.test" {
import "generic-host"
address = "mysql-source.lazy.test"
check_command = "hostalive"
vars.os = "Linux"
vars.mysql = true
}

vi /etc/icinga2/conf.d/mysql-replica.lazy.test.conf
object Host "mysql-replica.lazy.test" {
import "generic-host"
address = "mysql-replica.lazy.test"
check_command = "hostalive"
vars.os = "Linux"
vars.mysql = true
}

vi /etc/icinga2/conf.d/mysql.conf
apply Service "mysql-uptime" {
import "generic-service"
display_name = "MySQL Uptime"
check_command = "mysql_health"
vars.mysql_health_mode = "uptime"
vars.mysql_health_username = "icinga"
vars.mysql_health_password = "password"
assign where host.vars.mysql == true
}

apply Service "mysql-threads-connected" {
import "generic-service"
display_name = "MySQL Open Connections"
check_command = "mysql_health"
vars.mysql_health_mode = "threads-connected"
vars.mysql_health_username = "icinga"
vars.mysql_health_password = "password"
assign where host.vars.mysql == true
}

sudo mkdir /var/cache/nagios
sudo chown nagios:nagios /var/cache/nagios

vi /etc/icinga2/conf.d/mysql.conf
apply Service "mysql-slow-queries" {
import "generic-service"
display_name = "MySQL Slow Queries"
check_command = "mysql_health"
vars.mysql_health_mode = "slow-queries"
vars.mysql_health_username = "icinga"
vars.mysql_health_password = "password"
assign where host.vars.mysql == true
}

apply Service "mysql-long-running-procs" {
import "generic-service"
display_name = "MySQL Long Running Processes"
check_command = "mysql_health"
vars.mysql_health_mode = "long-running-procs"
vars.mysql_health_warning = "120"
vars.mysql_health_critical = "300"
vars.mysql_health_username = "icinga"
vars.mysql_health_password = "password"
assign where host.vars.mysql == true
}

mysql -u root -p
GRANT REPLICATION CLIENT ON . TO 'icinga'@'icinga.lazy.test';

vi /etc/icinga2/conf.d/mysql-replica.lazy.test.conf
object Host "mysql-replica.lazy.test" {
import "generic-host"
address = "mysql-replica.lazy.test"
check_command = "hostalive"
vars.os = "Linux"
vars.mysql = true
vars.mysql_replica= true
}

vi /etc/icinga2/conf.d/mysql-replica.conf
apply Service "mysql-replica-lag" {
import "generic-service"
display_name = "MySQL Replica Lag"
check_command = "mysql_health"
vars.mysql_health_mode = "slave-lag"
vars.mysql_health_username = "icinga"
vars.mysql_health_password = "password"
assign where host.vars.mysql_replica== true
}

apply Service "mysql-replica-io-status" {
import "generic-service"
display_name = "MySQL Replica IO Status"
check_command = "mysql_health"
vars.mysql_health_mode = "slave-io-running"
vars.mysql_health_username = "icinga"
vars.mysql_health_password = "password"
assign where host.vars.mysql_replica== true
}

apply Service "mysql-replica-sql-status" {
import "generic-service"
display_name = "MySQL Replica SQL Status"
check_command = "mysql_health"
vars.mysql_health_mode = "slave-sql-running"
vars.mysql_health_username = "icinga"
vars.mysql_health_password = "password"
assign where host.vars.mysql_replica== true
}

Chapters:
00:00 Intro
00:33 Create icinga MySQL user
01:20 Install plugins
02:00 Modify object Host file
02:22 apply Service for uptime
03:28 apply Service for threads-connected
04:54 apply Service for slow-queries
06:15 apply Service for long-running-procs
08:03 Grant replication permission
08:33 vars.mysql_replica
09:01 apply Service for slave-lag
09:58 apply Service for slave-io-running
10:50 apply Service for slave-sql-running
13:10 Outro


Watch video How to Monitor MySQL or MariaDB Database Server Using Icinga2 On Ubuntu 22.04 LTS Server online without registration, duration hours minute second in high quality. This video was added by user The Lazy SysAdmin 21 December 2022, don't forget to share it with your friends and acquaintances, it has been viewed on our site 2,599 once and liked it 35 people.