Gentoo Wiki


This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc



ZABBIX is software for monitoring of your applications, network and servers.

After installation Zabbix supports checks of ~100 network protocols. Further protocol checks can be added using shell-, C- or perlscripts. Zabbix understands the SNMP Protocol. It can create graphs of network-, cpu- or hard disk load, and so on. Many of these checks are done with agent software which is availabe for many platforms including Linux, Solaris, AIX, HP-UX, BSD, Windows, MacOS. Different views of a network can be defined for checks and documentation.


Zabbix can use a number of database backends. This HOWTO focuses on using Zabbix with MySQL (HOWTO MySQL), but you can also use PostgreSQL or Oracle.

The only frontend currently available for Zabbix is the PHP-based web frontend, so you'll need a PHP compatible web server, such as Apache2 or lighttpd. See HOWTO Apache2 with PHP MySQL.

Use Flags

Much of the use flag information is directly from Zabbix's wiki; however, this is not an exhaustive listing of all available use flags for these packages.







The Zabbix package has not been marked stable yet (Sep 2007). If you're the daring type who wants to use it anyway, start by adding the following line to /etc/portage/package.keywords where ~x86 must match to your machines architecture. In the new 1.4.x versions interesting features are implemented like autodetection of services or XML im-/export of Objects.

echo "net-analyzer/zabbix ~x86" >> /etc/portage/package.keywords

With version 1.4, Zabbix was consolidated into one ebuild for Gentoo. Add the following to your /etc/portage/package.use to gain the desired functionality from Zabbix.

On the Zabbix server machine:

echo "net-analyzer/zabbix server frontend" >> /etc/portage/package.use
(add mysql, etc for the database you're using)

On clients machines you wish to collect statistics from and/or monitor:

echo "net-analyzer/zabbix agent" >> /etc/portage/package.use

Now emerge Zabbix with the following:

emerge -av zabbix

If you intend to use simple ICMP-checks (like ping-checks without installing the zabbix-agent) with your zabbix-server you have to install fping suid-root. To do this you have to do "chmod u+s /usr/sbin/fping" after emerging fping. Beware however that this might be a security risk!

Create the database

Perform the following on your database of choice. The instructions here are for MySQL; however, installation for other databases are very similar. Zabbix ships with .sql files to create the schema and populate it with data for us, so just use the corresponding files like we do in the following examples.

Log on to MySQL and give Zabbix access to its database.

# mysql -u <your MySQL root account> -p
Enter password: <MySQL password>
mysql> create database zabbix;
mysql> grant all on zabbix.* to zabbix@localhost identified by '<some password for zabbix>';
mysql> flush privileges;
mysql> quit

Populate the database with initial Zabbix tables and data.

mysql -uzabbix -p zabbix < /usr/share/zabbix/database/create/schema/mysql.sql
Enter password: <MySQL password>
mysql -uzabbix -p zabbix < /usr/share/zabbix/database/create/data/data.sql
Enter password: <MySQL password>
mysql -uzabbix -p zabbix < /usr/share/zabbix/database/create/data/images_mysql.sql
Enter password: <MySQL password>

Edit /etc/mysql/my.cnf

There are a couple settings that need to be changed from Gentoo's default. The first is the bin log rotation setting. It is not rotated by default, and can quickly fill up your partition. The bin logs keep track of all actions that may change data (INSERT, UPDATE, DELETE, etc) and are primarily used to restore the database after a corruption (see the MySQL binary log documentation for more info). To delete the log every two days, add the following line to /etc/mysql/my.cnf under the mysqld section.

expire_logs_days = 2

Though not recommended, some users forgo the previous step and turn off the bin log completely. If you feel the logs are unnecessary then comment out the log-bin line.

#NOTE: I don't care about recovering from database corruptions and want to save disk space

The other setting that needs to be changed is the InnoDB data file size.

innodb_data_file_path = ibdata1:10M:autoextend:max:128M

After a few days, this will lead to errors with the data history and graphs. Your requirements may vary, but replacing the above with the following should be sufficient.

innodb_data_file_path = ibdata1:128M;ibdata2:50M:autoextend:max:12800M

(Note: You may have to remove either or both ibdata1 or ibdata2 to get MySQL to work after changing the above line.) Credit for tracking down the above fix belongs to For additional information read You may want to change the max size setting to fit your installation.

Configure Startup

On all machines you wish to monitor, you need to modify the files in /etc/zabbix. In particular, you need to point the SERVER= line to the IP address of the server where you are running the Zabbix server. In addition, each client running zabbix-agentd needs to have its hostname defined to a unique value (usually the simple hostname, fully qualified hostnames break remote command functionality).

Furthermore, the ListenIP= should be commented out on all clients where the server and front end are not running locally.

Add the daemons to the default runlevel

On all machines:

rc-update add zabbix-agentd default

On the zabbix server machine:

rc-update add zabbix-server default

Start them

/etc/init.d/zabbix-agentd start
/etc/init.d/zabbix-server start

Configure the Web interface

Install the Zabbix frontend in a vhost:

webapp-config -h $vhost -I zabbix $version -d /$dir
(for example: webapp-config -I zabbix 1.4.2 -d zabbix)

Zabbix requires that php be configured in a specific way. Edit /etc/php/apache2-php5/php.ini

date.timezone = America/Chicago (change to your timezone and uncomment the line)
max_execution_time = 300 (Default is 30, Zabbix wants 300)

And restart Apache so that it sees these changes.

/etc/init.d/apache2 restart

You should now be able to get to a login screen under http://$vhost/$dir.

The initial credentials are 'Admin' with no password.

Updated: If you in some reasons dont want change default config /etc/php/apache2-php5/php.ini, you can do that in very intelligent way - put the file .htaccess in /zabbix/ folder on web:

php_value max_execution_time 300
php_value memory_limit 200M
php_value post_max_size 200M
php_value upload_max_filesize 200M
php_value date.timezone Europe/Berlin

dont forget to change timezone, etc..

Adding Hosts to Monitor

User-Defined Monitored Parameters

Users can define their own monitored parameters in zabbix_agentd.conf To use the parameters below, just copy and paste them into your zabbix_agentd.conf and restart zabbix-agentd.


number of packages installed on a Gentoo system

UserParameter=gentoo.packages_installed,find /var/db/pkg/*/* -type d | wc -l

disk usage (percent used)

UserParameter=system.hd,df -h | grep /dev/hda3 | tr -s " " | cut -d " " -f 5 | cut -d % -f 1

memory usage (megabytes used)

UserParameter=system.mem,free -mt | grep + | tr -s [:space:] | cut -d ' ' -f 3

load average (for the past minute)

UserParameter=system.load,uptime | tr ' ' '\n' | tail -n 3 | head -n 1 | cut -d ',' -f 1

Apache Webserver

You can monitor the apache webserver using the examples below. All of them require mod_status (it comes with apache by default and its trivial to enable).

Total Accesses

UserParameter=apache.accesses,wget --quiet -O - http://localhost/server-status?auto | head -n 9 | grep Accesses | cut -d " " -f 3

Total kBytes

 UserParameter=apache.totalkb,wget --quiet -O - http://localhost/server-status?auto | head -n 9 | grep kBytes | cut -d " " -f 3

CPU Load

UserParameter=apache.cpuload,wget --quiet -O - http://localhost/server-status?auto | head -n 9 | grep CPULoad | cut -d " " -f 2

httpd uptime

UserParameter=apache.uptime,wget --quiet -O - http://localhost/server-status?auto | head -n 9 | grep Uptime | cut -d " " -f 2

Requests per second

UserParameter=apache.reqpersec,wget --quiet -O - http://localhost/server-status?auto | head -n 9 | grep ReqPerSec | cut -d " " -f 2

Bytes per second

UserParameter=apache.bytespersec,wget --quiet -O - http://localhost/server-status?auto | head -n 9 | grep BytesPerSec | cut -d " " -f 2

Bytes per request

UserParameter=apache.bytesperrec,wget --quiet -O - http://localhost/server-status?auto | head -n 9 | grep BytesPerReq | cut -d " " -f 2

Busy Workers

UserParameter=apache.busywokers,wget --quiet -O - http://localhost/server-status?auto | head -n 9 | grep BusyWorkers | cut -d " " -f 2

Idle Workers

UserParameter=apache.idleworkers,wget --quiet -O - http://localhost/server-status?auto | head -n 9 | grep IdleWorkers | cut -d " " -f 2


To make sure Zabbix is working, start by looking at the Reports page from the top menu. The "ZABBIX Server is running" line should say "YES". If it doesn't, try the command 'rc-status' and make sure zabbix-server is listed as 'started'. If not, try '/etc/init.d/zabbix-server start'.

Last modified: Fri, 05 Sep 2008 08:20:00 +0000 Hits: 26,180