1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
5
<title>Fast Startup Options</title>
7
<STYLE type="text/css">
9
.Default { font-family: verdana,arial,serif; font-size: 8pt; }
10
.PageTitle { font-family: verdana,arial,serif; font-size: 16pt; font-weight: bold; }
16
<body bgcolor="#FFFFFF" text="black" class="Default">
19
<img src="images/nagios.jpg" border="0" alt="Nagios" title="Nagios">
20
<h1 class="PageTitle">Fast Startup Options</h1>
26
<img src="images/upto.gif" border="0" align="middle" alt="Up To" title="Up To">Up To: <a href="toc.html">Contents</a><br>
27
<img src="images/seealso.gif" border="0" align="middle" alt="See Also" title="See Also"> See Also: <a href="tuning.html">Performance Tuning</a>, <a href="largeinstalltweaks.html">Large Installation Tweaks</a>
31
<strong><u>Introduction</u></strong>
35
There are a few things you can do that can decrease the amount of time it take Nagios to startup (or restart). These speedups involve easing some of the burden involved in processing your configuration files.
39
Using these techniques is particularly useful when you have one or more of the following:
43
<li>Large configurations</li>
44
<li>Complex configurations (heavy use of template features)</li>
45
<li>Installations where frequest restarts are necessary</li>
49
<strong><u>Background</u></strong>
53
Whenever Nagios 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:
57
<li>Reading the config files</li>
58
<li>Resolving template definitions</li>
59
<li>"Recombobulating" your objects (my term for the various types of work that occurs)</li>
60
<li>Duplicating object definitions</li>
61
<li>Inheriting object properties</li>
62
<li>Sorting your object definitions</li>
63
<li>Verifying object relationship integrity</li>
64
<li>Checking for circular paths</li>
69
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!
73
<strong><u>Evaluating Startup Times</u></strong>
77
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 nagios with the <b>-s</b> command line switch to get timing and scheduling information.
81
An example of the output (abbreviated to only show relevant portions) is shown below. For this example, I'm using a Nagios config that has 25 hosts defined and just over 10,000 services.
84
<pre style="padding: 0 0 0 50px;">
85
/usr/local/nagios/bin/nagios -s /usr/local/nagios/etc/nagios.cfg
88
Copyright (c) 1999-2007 Ethan Galstad (http://www.nagios.org)
89
Last Modified: 01-27-2007
92
Timing information on object configuration processing is listed
93
below. You can use this information to see if precaching your
94
object configuration would be useful.
96
Object Config Source: Config files (uncached)
98
OBJECT CONFIG PROCESSING TIMES (* = Potential for precache savings with -u option)
99
----------------------------------
101
Resolve: 0.004106 sec *
102
Recomb Contactgroups: 0.000077 sec *
103
Recomb Hostgroups: 0.000172 sec *
104
Dup Services: 0.028801 sec *
105
Recomb Servicegroups: 0.010358 sec *
106
Duplicate: 5.666932 sec *
107
Inherit: 0.003770 sec *
108
Recomb Contacts: 0.030085 sec *
110
Register: 2.654628 sec
113
TOTAL: 11.555925 sec * = 8.393170 sec (72.63%) estimated savings
116
Timing information on configuration verification is listed below.
118
CONFIG VERIFICATION TIMES (* = Potential for speedup with -x option)
119
----------------------------------
120
Object Relationships: 1.400807 sec
121
Circular Paths: 54.676622 sec *
124
TOTAL: 56.084353 sec * = 54.676622 sec (97.5%) estimated savings
128
Okay, lets see what happened. Looking at the totals, it took roughly <b>11.6</b> seconds to process the configuration files and another <b>56</b> seconds to verify the config. That means that every time I start or restart Nagios with this configuration, it will take nearly <b>68 seconds</b> of startup work before it can monitor anything! That's not acceptable if I have to restart Nagios on a semi-regular basis.
132
What can I do about this? Take another look at the output and you'll see that Nagios estimates that I could save about <b>8.4</b> seconds off the configuration processing time and another <b>54.7</b> off the verification times. In total, Nagios thinks I could save <b>63 seconds</b> of the normal startup time if some optimizations were taken.
136
Whoa! From <b>68 seconds</b> to just <b>5 seconds</b>? Yep, read on for how to do it.
142
<strong><u>Pre-Caching Object Configuration</u></strong>
146
Nagios 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 Nagios pre-process and pre-cache your config files for future use.
149
<table border="0" class="Default">
153
When you run nagios with the <b>-p</b> command line option, Nagios will read your config files in, process them, and save them to a pre-cached object config file (specified by the <a href="configmain.html#precached_object_file">precached_object_file</a> directive). This pre-cached config file will contain pre-processed configuration entries that are easier/faster for Nagios to process in the future.
157
You must use the <b>-p</b> command line option along with either the <b>-v</b> or <b>-s</b> command line options, as shown below. This ensures that your configuration is verified before the precached file is created.
160
<pre style="padding: 0 0 0 50px;">
161
/usr/local/nagios/bin/nagios -pv /usr/local/nagios/etc/nagios.cfg
165
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.
169
<div style="float: right; clear: right; padding: 0 0 25px 25px;">
170
<img src="images/fast-startup1.png" alt="Pre-Caching Object Config Files" title="Pre-Caching Object Config Files" border="0">
178
Once the precached object configuration file have been created, you can start Nagios and tell it to use the precached config file instead of your object config file(s) by using the <b>-u</b> command line option.
181
<pre style="padding: 0 0 0 50px;">
182
/usr/local/nagios/bin/nagios -ud /usr/local/nagios/etc/nagios.cfg
185
<p><img src="images/important.gif" border="0" align="bottom" alt="Important" title="Important"> If you modify your configuration files, you will need to re-verify and re-cache your configuration files before restarting Nagios. If you don't re-generate the precached object file, Nagios will continue to use your old configuration because it is now reading from the precached file, rather than your source configuration files.
190
<div style="float: right; padding: 0 0 0 25px;">
191
<img src="images/fast-startup2.png" alt="Pre-Caching Object Config Files" title="Pre-Caching Object Config Files" border="0">
198
<strong><u>Skipping Circular Path Tests</u></strong>
202
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.
206
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, Nagios could end up in a deadlock situation. The most likely reason for the check taking so long is that I'm 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 Nagios can contribute some code back. :-)
210
If you want to skip the circular path check when Nagios starts, you can add the -x command line option like this:
213
<pre style="padding: 0 0 0 50px;">
214
/usr/local/nagios/bin/nagios -xd /usr/local/nagios/etc/nagios.cfg
217
<p><img src="images/important.gif" border="0" align="bottom" alt="Important" title="Important"> It is of utmost importance that you verify your configuration before starting/restarting Nagios when skipping circular path checks. Failure to do so could lead to deadlocks in the Nagios logic. You have been warned.
221
<strong><u>Putting It All Together</u></strong>
225
Follow these steps if you want to make use of potential speedups from pre-caching your configuration and skipping circular path checks.
229
1. Verify your configuration and create the precache file with the following command:
232
<pre style="padding: 0 0 0 50px;">
233
/usr/local/nagios/bin/nagios -vp /usr/local/nagios/etc/nagios.cfg
237
2. Stop Nagios if it is currently running.
241
3. Start Nagios like so to use the precached config file and skip circular path checks:
244
<pre style="padding: 0 0 0 50px;">
245
/usr/local/nagios/bin/nagios -uxd /usr/local/nagios/etc/nagios.cfg
250
4. When you modify your original configuration files in the future and need to restart Nagios 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 Nagios through the web interface or by sending a SIGHUP signal. If you don't re-generate the precached object file, Nagios will continue to use your old confguration because it is now reading from the precached file, rather than your source configuration files.
254
5. That's it! Enjoy the increased startup speed.
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
9
<title>Fast Startup Options</title>
13
<STYLE type="text/css">
17
.Default { font-family: verdana,arial,serif; font-size: 8pt; }
19
.PageTitle { font-family: verdana,arial,serif; font-size: 16pt; font-weight: bold; }
31
<body bgcolor="#FFFFFF" text="black" class="Default">
37
<img src="images/nagios.jpg" border="0" alt="Nagios" title="Nagios">
39
<h1 class="PageTitle">Fast Startup Options</h1>
51
<img src="images/upto.gif" border="0" align="middle" alt="Up To" title="Up To">Up To: <a href="toc.html">Contents</a><br>
53
<img src="images/seealso.gif" border="0" align="middle" alt="See Also" title="See Also"> See Also: <a href="tuning.html">Performance Tuning</a>, <a href="largeinstalltweaks.html">Large Installation Tweaks</a>
61
<strong><u>Introduction</u></strong>
69
There are a few things you can do that can decrease the amount of time it take Nagios to startup (or restart). These speedups involve easing some of the burden involved in processing your configuration files.
77
Using these techniques is particularly useful when you have one or more of the following:
85
<li>Large configurations</li>
87
<li>Complex configurations (heavy use of template features)</li>
89
<li>Installations where frequest restarts are necessary</li>
97
<strong><u>Background</u></strong>
105
Whenever Nagios 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:
113
<li>Reading the config files</li>
115
<li>Resolving template definitions</li>
117
<li>"Recombobulating" your objects (my term for the various types of work that occurs)</li>
119
<li>Duplicating object definitions</li>
121
<li>Inheriting object properties</li>
123
<li>Sorting your object definitions</li>
125
<li>Verifying object relationship integrity</li>
127
<li>Checking for circular paths</li>
137
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!
145
<strong><u>Evaluating Startup Times</u></strong>
153
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 nagios with the <b>-s</b> command line switch to get timing and scheduling information.
161
An example of the output (abbreviated to only show relevant portions) is shown below. For this example, I'm using a Nagios config that has 25 hosts defined and just over 10,000 services.
167
<pre style="padding: 0 0 0 50px;">
169
/usr/local/nagios/bin/nagios -s /usr/local/nagios/etc/nagios.cfg
175
Copyright (c) 1999-2007 Ethan Galstad (http://www.nagios.org)
177
Last Modified: 01-27-2007
183
Timing information on object configuration processing is listed
185
below. You can use this information to see if precaching your
187
object configuration would be useful.
191
Object Config Source: Config files (uncached)
195
OBJECT CONFIG PROCESSING TIMES (* = Potential for precache savings with -u option)
197
----------------------------------
201
Resolve: 0.004106 sec *
203
Recomb Contactgroups: 0.000077 sec *
205
Recomb Hostgroups: 0.000172 sec *
207
Dup Services: 0.028801 sec *
209
Recomb Servicegroups: 0.010358 sec *
211
Duplicate: 5.666932 sec *
213
Inherit: 0.003770 sec *
215
Recomb Contacts: 0.030085 sec *
219
Register: 2.654628 sec
225
TOTAL: 11.555925 sec * = 8.393170 sec (72.63%) estimated savings
231
Timing information on configuration verification is listed below.
235
CONFIG VERIFICATION TIMES (* = Potential for speedup with -x option)
237
----------------------------------
239
Object Relationships: 1.400807 sec
241
Circular Paths: 54.676622 sec *
247
TOTAL: 56.084353 sec * = 54.676622 sec (97.5%) estimated savings
255
Okay, lets see what happened. Looking at the totals, it took roughly <b>11.6</b> seconds to process the configuration files and another <b>56</b> seconds to verify the config. That means that every time I start or restart Nagios with this configuration, it will take nearly <b>68 seconds</b> of startup work before it can monitor anything! That's not acceptable if I have to restart Nagios on a semi-regular basis.
263
What can I do about this? Take another look at the output and you'll see that Nagios estimates that I could save about <b>8.4</b> seconds off the configuration processing time and another <b>54.7</b> off the verification times. In total, Nagios thinks I could save <b>63 seconds</b> of the normal startup time if some optimizations were taken.
271
Whoa! From <b>68 seconds</b> to just <b>5 seconds</b>? Yep, read on for how to do it.
283
<strong><u>Pre-Caching Object Configuration</u></strong>
291
Nagios 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 Nagios pre-process and pre-cache your config files for future use.
297
<table border="0" class="Default">
305
When you run nagios with the <b>-p</b> command line option, Nagios will read your config files in, process them, and save them to a pre-cached object config file (specified by the <a href="configmain.html#precached_object_file">precached_object_file</a> directive). This pre-cached config file will contain pre-processed configuration entries that are easier/faster for Nagios to process in the future.
313
You must use the <b>-p</b> command line option along with either the <b>-v</b> or <b>-s</b> command line options, as shown below. This ensures that your configuration is verified before the precached file is created.
319
<pre style="padding: 0 0 0 50px;">
321
/usr/local/nagios/bin/nagios -pv /usr/local/nagios/etc/nagios.cfg
329
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.
337
<div style="float: right; clear: right; padding: 0 0 25px 25px;">
339
<img src="images/fast-startup1.png" alt="Pre-Caching Object Config Files" title="Pre-Caching Object Config Files" border="0">
355
Once the precached object configuration file have been created, you can start Nagios and tell it to use the precached config file instead of your object config file(s) by using the <b>-u</b> command line option.
361
<pre style="padding: 0 0 0 50px;">
363
/usr/local/nagios/bin/nagios -ud /usr/local/nagios/etc/nagios.cfg
369
<p><img src="images/important.gif" border="0" align="bottom" alt="Important" title="Important"> If you modify your configuration files, you will need to re-verify and re-cache your configuration files before restarting Nagios. If you don't re-generate the precached object file, Nagios will continue to use your old configuration because it is now reading from the precached file, rather than your source configuration files.
379
<div style="float: right; padding: 0 0 0 25px;">
381
<img src="images/fast-startup2.png" alt="Pre-Caching Object Config Files" title="Pre-Caching Object Config Files" border="0">
395
<strong><u>Skipping Circular Path Tests</u></strong>
403
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.
411
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, Nagios could end up in a deadlock situation. The most likely reason for the check taking so long is that I'm 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 Nagios can contribute some code back. :-)
419
If you want to skip the circular path check when Nagios starts, you can add the -x command line option like this:
425
<pre style="padding: 0 0 0 50px;">
427
/usr/local/nagios/bin/nagios -xd /usr/local/nagios/etc/nagios.cfg
433
<p><img src="images/important.gif" border="0" align="bottom" alt="Important" title="Important"> It is of utmost importance that you verify your configuration before starting/restarting Nagios when skipping circular path checks. Failure to do so could lead to deadlocks in the Nagios logic. You have been warned.
441
<strong><u>Putting It All Together</u></strong>
449
Follow these steps if you want to make use of potential speedups from pre-caching your configuration and skipping circular path checks.
457
1. Verify your configuration and create the precache file with the following command:
463
<pre style="padding: 0 0 0 50px;">
465
/usr/local/nagios/bin/nagios -vp /usr/local/nagios/etc/nagios.cfg
473
2. Stop Nagios if it is currently running.
481
3. Start Nagios like so to use the precached config file and skip circular path checks:
487
<pre style="padding: 0 0 0 50px;">
489
/usr/local/nagios/bin/nagios -uxd /usr/local/nagios/etc/nagios.cfg
499
4. When you modify your original configuration files in the future and need to restart Nagios 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 Nagios through the web interface or by sending a SIGHUP signal. If you don't re-generate the precached object file, Nagios will continue to use your old confguration because it is now reading from the precached file, rather than your source configuration files.
507
5. That's it! Enjoy the increased startup speed.