There are a few things you can do that can decrease the amount of time it take Icinga to startup (or restart). These speedups involve easing some of the burden involved in processing your configuration files.
Using these techniques is particularly useful when you have one or more of the following:
Complex configurations (heavy use of template features)
Installations where frequest restarts are necessary
Whenever Icinga starts/restarts it has to process your configuration files before it can get down to the business of monitoring. This configuration startup process involves a number of steps:
Reading the config files
Resolving template definitions
"Recombobulating" your objects (Ethan Galstads term for the various types of work that occurs)
Duplicating object definitions
Inheriting object properties
Sorting your object definitions
Verifying object relationship integrity
Checking for circular paths
Some of these steps can be quite time-consuming when you have large or complex configurations. Is there a way to speed any of these steps up? Yes!
Evaluating Startup Times
Before we get on to making things faster, we need to see what's possible and whether or not we should even bother with the whole thing. This is easy to do - simply start Icinga with the -s or --test-scheduling command line switch to get timing and scheduling information.
Starting with Icinga 1.0.2 there is an additional option -S or --show-scheduling. This will add information about the scheduling queue to the output.
An example of the output (abbreviated to only show relevant portions) is shown below. For this example, we're using an Icinga config that has 25 hosts defined and just over 10,000 services.
#> /usr/local/icinga/bin/icinga -s /usr/local/icinga/etc/icinga.cfg Icinga 1.3 Copyright (c) 2009 Nagios Core Development Team and Community Contributors Copyright (c) 1999-2009 Ethan Galstad Last Modified: 12-16-2009 License: GPL Timing information on object configuration processing is listed below. You can use this information to see if precaching your object configuration would be useful. Object Config Source: Config files (uncached) OBJECT CONFIG PROCESSING TIMES (* = Potential for precache savings with -u option) ---------------------------------- Read: 0.486780 sec Resolve: 0.004106 sec * Recomb Contactgroups: 0.000077 sec * Recomb Hostgroups: 0.000172 sec * Dup Services: 0.028801 sec * Recomb Servicegroups: 0.010358 sec * Duplicate: 5.666932 sec * Inherit: 0.003770 sec * Recomb Contacts: 0.030085 sec * Sort: 2.648863 sec * Register: 2.654628 sec Free: 0.021347 sec ============ TOTAL: 11.555925 sec * = 8.393170 sec (72.63%) estimated savings Timing information on configuration verification is listed below. CONFIG VERIFICATION TIMES (* = Potential for speedup with -x option) ---------------------------------- Object Relationships: 1.400807 sec Circular Paths: 54.676622 sec * Misc: 0.006924 sec ============ TOTAL: 56.084353 sec * = 54.676622 sec (97.5%) estimated savings
Okay, let's see what happened. Looking at the totals, it took roughly 11.6 seconds to process the configuration files and another 56 seconds to verify the config. That means that every time we start or restart Icinga with this configuration, it will take nearly 68 seconds of startup work before it can monitor anything! That's not acceptable if we have to restart Icinga on a semi-regular basis.
What can we do about this? Take another look at the output and you'll see that Icinga estimates that we could save about 8.4 seconds off the configuration processing time and another 54.7 off the verification times. In total, Icinga thinks we could save 63 seconds of the normal startup time if some optimizations were taken.
Whoa! From 68 seconds to just 5 seconds? Yep, read on for how to do it.
Pre-Caching Object Configuration
Icinga can spend quite a bit of time parsing your config files, especially if you make use of the template features such as inheritance, etc. In order to reduce the time it takes to parse your config, you can have Icinga pre-process and pre-cache your config files for future use.
When you run Icinga with the -p command line option, Icinga will read your config files in, process them, and save them to a pre-cached object config file (specified by the precached_object_file directive). This pre-cached config file will contain pre-processed configuration entries that are easier/faster for Icinga to process in the future.
You must use the -p command line option along with either the -v or -s command line options, as shown below. This ensures that your configuration is verified before the precached file is created.
/usr/local/icinga/bin/icinga -pv /usr/local/icinga/etc/icinga.cfg
The size of your precached config file will most likely be significantly larger than the sum of the sizes of your object config files. This is normal and by design.
Once the precached object configuration file have been created, you can start Icinga and tell it to use the precached config file instead of your object config file(s) by using the -u command line option.
/usr/local/icinga/bin/icinga -ud /usr/local/icinga/etc/icinga.cfg
If you modify your configuration files, you will need to re-verify and re-cache your configuration files before restarting Icinga. If you don't re-generate the precached object file, Icinga will continue to use your old configuration because it is now reading from the precached file, rather than your source configuration files.
Skipping Circular Path Tests
The second (and most time-intensive) portion of the configuration startup phase is the circular path check. In the example above, it took nearly a minute to perform this step of the configuration verification.
What is the circular path check and why does it take so long? The circular patch check is designed to ensure that you don't define any circular paths in your host, host dependency, or service dependency definitions. If a circular path existed in your config files, Icinga could end up in a deadlock situation. The most likely reason for the check taking so long is that we're not using an efficient algorithm. A much more efficient algorithm for detecting circular paths would be most welcomed. Hint: That means all you CompSci graduate students who have been emailing me about doing your thesis on Icinga can contribute some code back. :-)
If you want to skip the circular path check when Icinga starts, you can add the -x command line option like this:
/usr/local/icinga/bin/icinga -xd /usr/local/icinga/etc/icinga.cfg
It is of utmost importance that you verify your configuration before starting/restarting Icinga when skipping circular path checks. Failure to do so could lead to deadlocks in the Icinga logic. You have been warned.
Putting It All Together
Follow these steps if you want to make use of potential speedups from pre-caching your configuration and skipping circular path checks.
1. Verify your configuration and create the precache file with the following command:
/usr/local/icinga/bin/icinga -vp /usr/local/icinga/etc/icinga.cfg
2. Stop Icinga if it is currently running.
3. Start Icinga like so to use the precached config file and skip circular path checks:
/usr/local/icinga/bin/icinga -uxd /usr/local/icinga/etc/icinga.cfg
4. When you modify your original configuration files in the future and need to restart Icinga to make those changes take place, repeat step 1 to re-verify your config and regenerate your cached config file. Once that is done you can restart Icinga through the web interface or by sending a SIGHUP signal. If you don't re-generate the precached object file, Icinga will continue to use your old confguration because it is now reading from the precached file, rather than your source configuration files.
5. That's it! Enjoy the increased startup speed.
© 2009-2011 Icinga Development Team, http://www.icinga.org