Hack85.Monitor Service Availability with Zabbix


Hack 85. Monitor Service Availability with Zabbix

It's nice to have some warning before those help calls come flooding in. Be the first to know what's happening with critical servers on your network!

It will happen to everyone sooner or later: you'll be minding your own business, blissfully unaware that the network is crashing to its knees until a secretary claims that the Internet is down. By that time, the bosses have all noticed, and everyone wants answers. Full-blown panic kicks in, and you race around the office, pinging things at random to try to figure out what's happening. Wouldn't it be nice if you had some sort of detailed real-time network map that could monitor services and tell you what was going on? Zabbix to the rescue! Zabbix is a host monitoring tool that can do amazing things. Read on to see how you can apply it in your own network.

9.9.1. Dependencies

Zabbix is a complicated beast, so there are naturally a few dependencies to note before you rush headlong into the installation. Zabbix is written in PHP, so make sure you have a relatively recent version installed. If you haven't upgraded in a while, this might be the time to do so. Since Zabbix is completely web-based, you'll obviously need a web server as well. Par for the course, Apache or Apache2 is the recommended server of choice. Make sure when you install Apache that you configure it with mod-php enabled as well. This ensures that Apache can understand the embedded PHP that makes Zabbix what it is. Then, make sure you have the PHP GD library installed (available from http://www.boutell.com/gd/). While Zabbix will technically run without this, it's not recommended, as this is the library that generates the network maps and graphs that make Zabbix so useful. Finally, you'll need a SQL database. While Zabbix supports both PostgreSQL and MySQL, in this example we'll be using MySQL.

9.9.2. Installing Zabbix

Unfortunately, installing Zabbix isn't as straightforward as many applications we've discussed so far. Some parts of its installation, which I'll highlight as we go along, are optional.

The first step in getting Zabbix up and running is to download and untar the source code. You can find this at the home page (http://www.zabbix.com). At the time this book was written, the latest version was 1.0. Download the archive file of the latest version, untar it in your normal build location, and navigate to the new directory. First, we'll need to configure Zabbix to make use of the database choice we've selected (MySQL) and to use SNMP. Run the following command to prepare the installation:

 $ ./configurewith-mysqlwith net-snmp 

This shouldn't take too long, so don't grab a beer just yet! Before you move on to the make, you'll need to take a second to prepare the MySQL database for Zabbix. Navigate to the create/ directory and then start MySQL, create the Zabbix database, and concatenate the .sql scripts to populate the tables:

 # mysqlu <username>  -p <password>     Mysql> create database Zabbix;    Mysql> quit; # cd create/mysql  # cat schema.sql |mysqlu <username>  -p <password>  Zabbix  # cd ../data  # cat data.sql |mysqlu <username>  -p <password>  Zabbix  

You can now jump back to the root of the Zabbix directory and issue the make command.

Once the make completes, take a moment to copy the contents of the bin/directory to somewhere in your path. I tend to use /usr/local/bin.

 # cp bin/* /usr/local/bin 

This is a fairly unsophisticated installation mechanism, but you're almost done. Now we have to set a few variables so that PHP knows how to properly access your database. Navigate to frontend/php/include in your Zabbix source directory and open the file db.inc.php in your favorite text editor. Make the following changes:

 $DB_TYPE ="MySQL"; $DB_SERVER ="localhost"; $DB_DATABASE ="Zabbix"; $DB_USER ="<MySQL username here>" $DB_PWD ="<MySQL password here>" 

The $DB_DATABASE variable is the name of the database you created in MySQL for Zabbix earlier. Once these changes have been made, copy the PHP files to your web root:

 # cpR frontends/php/*  /srv/www/htdocs/  

Now make the directory /etc/zabbix and copy the sample configuration files to it:

 # mkdir /etc/zabbix # cp misc/conf/zabbix_suckerd.conf /etc/zabbix/zabbix_suckerd.conf # cp misc/conf/zabbix_trapperd.conf /etc/zabbix/zabbix_trapperd.conf 

These sample configuration files are fine for small-time applications, but if you're planning on deploying Zabbix on a large-scale or enterprise rollout you should read the configuration files section of the online Zabbix manual, available at http://www.zabbix.com/manual/v1.1/config_files.php. Doing so will save you many headaches in the future. Once these files are moved, you're done with the installation! All that's left is to fire up the Zabbix daemons and ensure that they work:

 # zabbix_suckerd # zabbix_trapperd 

Assuming everything went as planned, you can now point your web browser to http://127.0.0.1 and see your new Zabbix installation. When you get to the login screen, enter Admin for your username and leave the password field blank. Once logged in, take a moment to change the default password.

9.9.3. Monitoring Hosts

After that installation, you certainly deserve to do something easy now! Fortunately, Zabbix seems to be designed with ease in mind. Let's start adding some hosts to monitor. The upper section of the screen has the navigation bars that you'll use to navigate around Zabbix. Click Hosts to add a new host to your monitoring. Figure 9-3 shows the fields available when adding a new host on the Hosts tab in Zabbix.

Figure 9-3. The Zabbix Hosts tab


You'll see here that you have several options when adding your new hosts. Fill in the options to suit your needs and click Add. Note that if you'd rather monitor by hostname than by DNS (which is often an excellent idea), checking the Use IP Address box will give you an additional box to provide the IP address to monitor. For example, let's assume we want to configure Zabbix to notify us if 192.168.2.118 ever stops serving FTP traffic. To do so, on the Hosts tab, we would enter 192.168.2.118 in the Host field. We'd then change the port to 22 since we're interested in FTP traffic. Next, move over to the Items tab. We'll need to type in a description for this item, so we'll call it Home-FTP. Under Type, select "Simple check." In the Key field, enter "ftp." The rest we can leave as it is. Now wait a few minutes, and check the Latest Values tab. You should see an option there for 192.168.2.118 (or the hostname if you gave it one). Since the FTP server is running, we get a return value of 1. Had the server not been running, we would see 0 in that field. Notice that to the right you have the option to graph, trend, and compare data collected over time. This allows for detailed data analysis on the uptime and availability of your servers. It is also an excellent demonstration of the graphical qualities of Zabbix.

9.9.4. Mapping the Network

The last aspect of Zabbix that we'll look at is the mapping feature (shown in Figure 9-4). This is an excellent tool for providing a quick reference map of the network showing detailed status. To begin, click on the lower Network Maps button. Create a new network map by filling in the name you wish to call your new map. If you'll have a lot of hosts to monitor, change the size of the map to make it bigger. Click Add to continue. Once you've created your map, it's time to add some hosts to it. Select the host we created in the previous example, Home-FTP. You can then select the coordinates you wish for the icon representing Home-FTP to be displayed on. Select the Server icon and click Add. The page will refresh, and when it finishes loading, you'll see your icon representing Home-FTP on the map. You can continue adding hosts and placing them on the map until you have a full representation of your network.

9.9.5. The Details

What we've covered here is a fraction of the capabilities of Zabbix. If you'd like to get more in depth with it, you can install the Zabbix agents on the machines you wish to monitor. Once you've done that, you can monitor statistics such as CPU utilization, drive space, and anything else that can be monitored via SNMP. You can also define custom triggers to alert you right away to emergency situations. Trigger definition is highly detailed and can get quite elaborate and complex. If you'd like to learn more about this incredibly flexible network monitoring tool, check out the Zabbix web page at http://www.zabbix.com for more information. There is a fairly active forum there dedicated to helping users in need and sharing configuration tips and tricks.

Brian Warshawsky

Figure 9-4. The mapping features of Zabbix




Linux Server Hacks (Vol. 2)
BSD Sockets Programming from a Multi-Language Perspective (Programming Series)
ISBN: N/A
EAN: 2147483647
Year: 2003
Pages: 162
Authors: M. Tim Jones

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net