In Zabbix when we want to monitor some database, it is possible to do this by making use of the Open Database Connectivity (ODBC) software. ODBC is kind of a software sitting between the DBMS and the application (in our case Zabbix). Zabbix can query any database, which is supported by unixODBC or Independent Open DataBase Connectivity (iODBC).
We need of course, our Zabbix server setup. If you have compiled the server then you need to make sure that it was compiled with the option --with-unixODBC
.
unixODBC
packages.# yum install unixODBC -y # yum install unixODBC-devel -y (if you need sources to compile)
# yum install mysql-connector-odbc
odbcinst.ini
file. Here we have to add the location of our ODBC database driver. To find the location you can run the next command:# odbcinst -j unixODBC 2.2.14 DRIVERS............: /etc/odbcinst.ini SYSTEM DATA SOURCES: /etc/odbc.ini
odbcinst.ini
and list our database driver:# vi /etc/odbcinst.ini # Driver from the mysql-connector-odbc package # Setup from the unixODBC package [MySQL] Description = ODBC for MySQL Driver = /usr/lib/libmyodbc5.so Setup = /usr/lib/libodbcmyS.so Driver64 = /usr/lib64/libmyodbc5.so Setup64 = /usr/lib64/libodbcmyS.so FileUsage = 1
This file should already be OK, just make sure that the library for the Driver64
option is really on the system in that location.
odbc.ini
file to create our dsn
(data source) and add our database config
.:# vi /etc/odbc.ini [mysql-test] => name of the dsn we will use Description = Mysql test DB Driver = mysql Server = 127.0.0.1 User = root Password = <root db password> Port = 3306 Database = <zabbix database>
# isql mysql-test
isql
command with the -v
option for verbose.Database monitor
.<unique short description>
with our own unique key naming and <dsn>
with our DSN name from the one in the odbc.ini
file.odbc.ini
file already.select count(*) from items
.Numeric
.Decimal
.To be able to get Zabbix to read data from our database, we need to keep a few simple steps in mind. We need to compile Zabbix with UnixODBC support for which we need the package unixODBC-devel
. Zabbix does not connect directly to the database but makes use of ODBC for this so we need to install the unixODBC
package as well. Depending on what database we want to use, we also need the proper ODBC driver for our database. So in our case we had to make use of the mysql-connector-odbc
package.
Next, we had to configure unixODBC which was done by editing two files odbcinst.ini
and odbc.ini
. The odbcinst.ini
file is used to configure the installed drivers. It seems Red Hat / Centos comes already with a basic configuration, so we didn't have to make any changes.
Next, we had to add a data source in the odbc.ini
file which is what we call a DSN. The DSN name is always between []
and we need this name for our Zabbix item. We also had to add the driver, in our case, mysql-
the server where our database was running and connection settings such as username, password, port, and database name.
In our case, it was easy to install the MySQL driver because it was already provided in a package from our OS. Sometimes it's not so easy to find the correct driver for instance when using Oracle. The website from unixODBC has a list of supported databases and drivers: http://www.unixodbc.org/drivers.html.
Some limitations to keep in mind:
select
command.sql=
in lowercase. – with -unixODBC
.