Ad Widget

Collapse

My way of monitoring MariaDB Multi-Master / Multi-Source Replication

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DembeanCadillac
    Junior Member
    • Mar 2024
    • 2

    #1

    My way of monitoring MariaDB Multi-Master / Multi-Source Replication

    I use MariaDB 10.5.22 with multiple replications and want to monitor them with Zabbix. I had a few options for templates, "Template DB MySQL by Zabbix agent", "Template DB MySQL by ODBC", and "Template DB MySQL by Zabbix agent 2". Zabbix agent (no 2) was the one that I could make work.

    1. Install Zabbix agent. My repository has 6.0.27. If it's already installed, skip to step 3.
    Code:
    yum install zabbix-agent
    2. Restart MariaDB since the installation of Zabbix agent killed it for some reason. (?!?)
    Code:
    systemctl start mariadb
    Note: You may need to adjust this for your flavor of Linux.

    3. Edit /etc/zabbix_agentd.conf.
    • In the Server section, enter the IP of your Zabbix server if not already set.
      Code:
      Server=zabbix.server.ip,127.0.0.1
    • In the Hostname section, set your database server's hostname if not already set.
    • In the Include section, add this line: (you may choose a different directory if you prefer; just remember it for later)
      Code:
      Include=/etc/zabbix/zabbix_agentd.d/*.conf
    4. Create the include directory.
    Code:
    mkdir /etc/zabbix/zabbix_agentd.d
    5. Log in to MariaDB and create a user:
    Code:
    GRANT PROCESS, SHOW DATABASES, SLAVE MONITOR, SHOW VIEW ON *.* TO `zbx_monitor`@`localhost` IDENTIFIED BY 'SuperSecretPasswordHere'
    Note: if MariaDB is not bound to 127.0.0.1, change localhost appropriately in this and also the next step.

    6. Create /var/lib/zabbix/.my.cnf
    Code:
    [client]
    user='zbx_monitor'
    password='SuperSecretPasswordHere'
    host=localhost
    7. Create /etc/zabbix/zabbix_agentd.d/template_db_mysql.conf
    Code:
    UserParameter=mysql.ping[*], mysqladmin ping
    UserParameter=mysql.get_status_variables[*], mysql -sNX -e "show global status"
    UserParameter=mysql.version[*], mysqladmin -s version
    UserParameter=mysql.db.discovery[*], mysql -sN -e "show databases"
    UserParameter=mysql.dbsize[*], mysql -sN -e "SELECT COALESCE(SUM(DATA_LENGTH + INDEX_LENGTH),0) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='$3'"
    UserParameter=mysql.replication.discovery[*], mysql -sNX -e "show all slaves status"
    UserParameter=mysql.slave_status[*], mysql -sNX -e "show slave \"$3\" status"
    Note: $3 is used a couple of times. This is for backwards compatibility with techniques that store the database host and port as macros.

    8. Restart zabbix-agent.
    Code:
    systemctl restart zabbix-agent
    9. From your Zabbix server, test to see if things are working. If not, hopefully the output of the below commands gives you enough information to start troubleshooting.
    Code:
    zabbix_get -s database.server.ip -k vfs.fs.size[/,pused]
    Code:
    zabbix_get -s database.server.ip -k mysql.replication.discovery[]
    10.
    Originally posted by Isuaven
    In template in Replication discovery Preprocessing change Javascript to this:
    Code:
    var arr=[],a=""
    while (a=value.match(/Master_Host.*>(.*)<.*/)) {
    arr.push({"{#MASTERHOST}": a[1]})
    value=value.substr(a.index+1)
    }
    return JSON.stringify(arr)
    11. Add "Template DB MySQL by Zabbix agent" to your host.

    Let me know if you use this. Good luck.
    Last edited by DembeanCadillac; 08-04-2024, 17:38.
Working...