-
Notifications
You must be signed in to change notification settings - Fork 2
/
README
1578 lines (1139 loc) · 56.6 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Nagiosgraph
Nagiosgraph is an add-on to Nagios. Nagios monitors one or more services
on each host. nagiosgraph extracts information from the Nagios output,
processes it, then inserts it into one or more round-robin database (RRD)
files. CGI scripts display data from the RRD files as web pages. The CGI
output can be embedded directly into Nagios so that graphs show up like
other trend reports.
Installation is a three-step process. First install the nagiosgraph files,
then configure Nagios for data collection, and finally customize the
graphs and links as needed. Installation can be done manually by copying
files and modifying configuration files, or automatically using the
install.pl script.
The INSTALL file contains basic installation instructions.
This README file contains detailed instructions for installing, upgrading,
customizing, troubleshooting, and managing performance data.
Answers to frequently asked questions are at:
<https://sourceforge.net/apps/mediawiki/nagiosgraph>
For help, visit the forum at:
<http://sourceforge.net/projects/nagiosgraph/forums/forum/394748>
Copyright and License
License: OSI Artistic License 2.0
http://www.opensource.org/licenses/artistic-license-2.0
Author: (c) 2005 Soren Dossing
Author: (c) 2008 Alan Brenner, Ithaka Harbors
Author: (c) 2010 Matthew Wall
Nagios is a registered trademark of Ethan Galstad.
Contents
Principles of Operation
Installation Preliminaries
Prerequisites
Layout and Location
Installation Methods
Manual Installation
Install Script
Installation Using Packages
Installing nagiosgraph Files
Upgrade Notes
Configuring Data Processing
Batch Processing
Immediate Processing
Configuring Graphing and Display
Graph Icons and Links in Nagios
For Nagios 2.6 and Earlier
For Nagios 2.9 and Nagios 3
Graphs in Nagios Mouseovers
Graphs in Nagios Frames
Customizing the Graphs
Adding Service Types
Managing Data and RRD Files
Managing RRD Parameters
Configuring Access Controls
Troubleshooting
Internationalization
Enumeration of Files
Sample Installation Layouts
Sample Web Server Configuration
Platform Specific Notes
Nagios Embedded PERL (ePN)
CentOS 5 and Nagiosgraph 0.9
MacOSX 10.5 and Nagios 2.12
Fedora Core 6 and HTTP output parsing
Notes For Developers
Project Testing/Code Summary
Principles of Operation
nagiosgraph is a simple interface between Nagios and RRD files.
nagiosgraph operates in two modes. One is to collect performance data from
Nagios servicechecks, and the other is to display graphs of the
performance data collected.
All the data collected are stored in RRD files using rrdtool. A file
called 'map' defines how to identify the data from Nagios and how to store
them in the RRD files. Nagios passes all the service data to a nagiosgraph
script called 'insert.pl'. This script uses the file 'map' to determine
how to name the data and into which RRD files to insert the data. The map
file also processes the data, for example by changing units or applying
scaling factors.
The 'map' file is actually perl code, that is eval'ed by 'insert.pl'. The
map file contains a general rule that will capture the performance data
from most plugins. However, it may be necessary to add entries to match
the output of some Nagios plugins. Several examples of servicechecks are
included in the distributed map file. Knowing perl regular expression is
helpful, but the examples supplied should cover most types of performance
data.
For graphing, nagiosgraph includes cgi scripts. 'show.cgi' looks up
performance data for a single host and service, and generates line charts
accordingly. Other scripts display all hosts for a specific service, all
services for a specific host, or arbitrary groups of hosts and services.
These run out-of-the-box with minimal configuration, or they can be
customized, using a configuration file or interactively.
Graphs can be integrated into Nagios using Nagios' extended information
for services and hosts. By specifying nagiosgraph cgi scripts in the
Nagios configuration, individual graphs and collections of graphs can be
linked directly to hosts and services in Nagios web pages.
By default, all available data for a servicecheck will be displayed in the
same graph. With extra configuration, either embedded in the url,
specified in a configuration file, or using controls in a web page, it is
possible to display less data or to split values into multiple graphs.
There is also a general method for specifying arbitrary RRD graph options
such as line style, color, and scaling for individual hosts or services.
Installation Preliminaries
Before installing, ensure that the prerequisite software has been
installed then decide upon a layout and location.
Prerequisites
Nagiosgraph will not function without a working Nagios installation, so
first ensure that Nagios works. Version 3.2 or later is recommended, but
older versions will also work.
Nagiosgraph requires rrdtool. Version 1.4 or later is recommended, but
older versions will also work.
Nagiosgraph requires the CGI and RRDs perl modules. The RRDs perl module
is part of rrdtool but is often distributed as a separate package. The GD
perl module is optional, but recommended. The Nagios::Object perl module
is optional, but useful for automatic configuration of showgroup.cgi.
Debian/Ubuntu:
apt-get install libcgi-pm-perl librrds-perl
apt-get install libgd-gd2-perl libnagios-object-perl
Redhat/Fedora/CentOS:
yum install perl-rrdtool perl-GD
SUSE:
rrdtool, perl-GD
Solaris:
rrdtool, gd
FreeBSD:
rrdtool, gd
OpenBSD:
p5-RRD, p5-GD
The install.pl script includes an option to check for pre-requisites:
install.pl --check-prereq
Layout and Location
There are two standard layouts: separate or overlay. The separated layout
has nagiosgraph and Nagios in separate directories. The overlay places
nagiosgraph components with Nagios components.
Nagios and nagiosgraph can be installed in just about any location, for
example /opt or /usr/local.
Redhat (Fedora, CentOS), SUSE, and Debian (Ubuntu) systems have their own
layouts. If you installed Nagios from a package, you can overlay
nagiosgraph or you can install nagiosgraph to its own standalone location.
When installing from source, the standalone layout is highly recommended
since it makes updates much easier.
Decide upon a location and layout before you start the installation.
Examples are in the Sample Installation Layouts section.
Installation Methods
There are a few ways to install nagiosgraph: manual, script, and package.
On most systems the installation requires root permissions, so either do
the installation as root or preface commands with sudo.
Manual Installation
Copy and edit files directly. Follow the recipe in the INSTALL file, or
the instructions in these sections of this file:
* "Installing nagiosgraph Files" - nagiosgraph installation
* "Configuring Data Processing" - Nagios configuration
* "Configuring Graphing and Display" - Apache and Nagios configuration
Install Script
Run the install.pl script. It will prompt you for the parameters it needs,
then it will copy and configure nagiosgraph files. It will also prompt you
to modify apache and Nagios configuration files.
install.pl --prefix=/usr/local/nagiosgraph
install.pl --help
Installation Using Packages
The nagiosgraph packages assume that Nagios and apache were installed from
packages. Do not use a nagiosgraph package if you installed Nagios or
apache from source!
Debian, Ubuntu
dpkg -i nagiosgraph-x.y.z.deb
Redhat, Fedora, CentOS, SUSE
rpm -i nagiosgraph-x.y.z.rpm
Installing nagiosgraph Files
These instructions assume a standalone layout, with Nagios at
/usr/local/nagios and nagiosgraph at /usr/local/nagiosgraph
1. Create destination directories:
mkdir /usr/local/nagiosgraph
mkdir /usr/local/nagiosgraph/bin
mkdir /usr/local/nagiosgraph/cgi-bin
mkdir /usr/local/nagiosgraph/etc
mkdir /usr/local/nagiosgraph/share
2. Extract nagiosgraph into a temporary location:
cd /tmp
tar xzvf nagiosgraph-x.y.z.tgz
3. Copy the contents of etc into your preferred configuration location:
cp etc/* /usr/local/nagiosgraph/etc
4. Edit the perl scripts in the cgi and lib directories, modifying the
"use lib" line to point to the directory from the previous step.
vi cgi/*.cgi lib/insert.pl
5. Copy insert.pl to a location from which it can be executed:
cp lib/insert.pl /usr/local/nagiosgraph/bin
6. Copy CGI scripts to a script directory served by the web server:
cp cgi/*.cgi /usr/local/nagiosgraph/cgi-bin
7. Copy CSS and JavaScript files to a directory served by the web server:
cp share/nagiosgraph.css /usr/local/nagiosgraph/share
cp share/nagiosgraph.js /usr/local/nagiosgraph/share
8. Edit nagiosgraph.conf. Set at least the following:
logfile = /var/log/nagiosgraph.log
cgilogfile = /var/log/nagiosgraph-cgi.log
perflog = /var/nagios/perfdata.log
rrddir = /var/nagios/rrd
mapfile = /usr/local/nagiosgraph/etc/map
nagiosgraphcgiurl = /nagiosgraph/cgi-bin
javascript = /nagiosgraph/nagiosgraph.js
stylesheet = /nagiosgraph/nagiosgraph.css
9. Set permissions of "rrddir" (as defined in nagiosgraph.conf) so that
the *nagios* user can write to it and the *www* user can read it:
mkdir /var/nagios/rrd
chown nagios /var/nagios/rrd
chmod 755 /var/nagios/rrd
10. Set permissions of "logfile" so that the *nagios* user can write to
it:
touch /var/log/nagiosgraph.log
chown nagios /var/log/nagiosgraph.log
chmod 644 /var/log/nagiosgraph.log
11. Set permissions of "cgilogfile" so that the *www* user can write to
it:
touch /var/log/nagiosgraph-cgi.log
chown www /var/log/nagiosgraph-cgi.log
chmod 644 /var/log/nagiosgraph-cgi.log
12. Ensure that the *nagios* user can create and delete perfdata files:
chown nagios /var/nagios
chmod 755 /var/nagios
Upgrade Notes
* Follow the steps for a new installation, but keep your customizations.
Your changes should be limited to the map file (map), configuration
files (nagiosgraph.conf and other .conf files), and the stylesheet
(nagiosgraph.css).
* Use diff, or a similar tool, to update your nagiosgraph.conf with any
new fields from etc/nagiosgraph.conf
* Use diff, or a similar tool, to update your nagiosgraph.css with
changes from share/nagiosgraph.css.
* You may want to look at etc/map or the files in the examples directory
to see if there are any map rules or CSS useful to your configuration.
* If you change from immediate processing to batch processing, be sure
to comment out service_perfdata_command in the Nagios configuration.
* Be sure to install the nagiosgraph.js and nagiosgraph.css files,
especially if you are upgrading from nagiosgraph older than 1.2.
* If you are upgrading from nagiosgraph 1.4.1 or earlier, move your
service and database/datasource labels from nagiosgraph.conf to
labels.conf.
* If you are upgrading from nagiosgraph 1.4.3 or earlier and you were
using nagios3 for the authzmethod, you must replace authz_nagios_cfg
and authz_cgi_cfg with authzfile. All of the Nagios authorization
parameters should be in the Nagios CGI configuration file (typically
cgi.cfg).
* If you are upgrading from nagiosgraph 1.4.3 or earlier, you might want
to add the generic map rule to the end of your map file. This rule
will catch performance data from any additional plugins you add. Using
the generic rule results in RRD files with the following structure,
one file per named performance data element, with one or more data
sources:
host0/service___label (data[,warn][,crit][,min][,max])
* If you are upgrading from nagiosgraph 1.4.3 or earlier, you should
make any ignore map rules explicit. For example, in the map file
change this:
/output:CHECK_NRPE: Socket timeout/
and return;
to this:
/output:CHECK_NRPE: Socket timeout/
and return ('ignore');
Configuring Data Processing
Before nagiosgraph can graph anything it must first collect data. There
are two ways to process data - batch and immediate. Batch processing is
usually appropriate for most Nagios deployments. Immediate processing
typically requires more CPU and I/O.
In batch processing, performance data are appended to a file, then Nagios
invokes insert.pl at a regular interval to update the RRD files.
In immediate processing, Nagios invokes insert.pl immediately after each
service check, thus updating the corresponding RRD files.
Batch Processing
1. In the Nagios configuration file (nagios.cfg) set:
process_performance_data=1
service_perfdata_file=/var/nagios/perfdata.log
service_perfdata_file_template=$LASTSERVICECHECK$||$HOSTNAME$||$SERVICEDESC$||$SERVICEOUTPUT$||$SERVICEPERFDATA$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=30
service_perfdata_file_processing_command=process-service-perfdata
Make sure that service_perfdata_command is either commented out or not
defined.
Make sure that location of service_perfdata_file matches that of
perflog defined in nagiosgraph.conf.
2. In the Nagios commands file (commands.cfg) define the
process-service-perfdata command:
define command {
command_name process-service-perfdata
command_line /usr/local/nagiosgraph/bin/insert.pl
}
Make sure there is only one definition for process-service-perfdata.
Older versions of Nagios used checkcommands.cfg or misccommands.cfg.
3. Check the Nagios configuration
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
4. Restart Nagios
/etc/init.d/nagios restart
Immediate Processing
1. In nagios.cfg:
process_performance_data=1
service_perfdata_command=process-service-perfdata
Make sure that service_perfdata_file_processing_command is either
commented out or not defined.
2. In commands.cfg:
define command{
command_name process-service-perfdata
command_line /usr/local/nagiosgraph/bin/insert.pl "$LASTSERVICECHECK$||$HOSTNAME$||$SERVICEDESC$||$SERVICEOUTPUT$||$SERVICEPERFDATA$"
}
3. Check the Nagios configuration
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
4. Restart Nagios
/etc/init.d/nagios restart
Configuring Graphing and Display
First configure the web server to run the nagiosgraph CGI scripts. For
example, with Apache do something like this in the Apache configuration:
ScriptAlias /nagiosgraph/cgi-bin /usr/local/nagiosgraph/cgi-bin
<Directory "/usr/local/nagiosgraph/cgi-bin">
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Alias /nagiosgraph "/usr/local/nagiosgraph/share"
<Directory "/usr/local/nagiosgraph/share">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Restart the web server:
/etc/init.d/apache2 restart
Verify that nagiosgraph is working by running showconfig.cgi
http://server/nagiosgraph/cgi-bin/showconfig.cgi
Try graphing some data by running show.cgi
http://server/nagiosgraph/cgi-bin/show.cgi
This should display a web page with a list of your hosts and services.
Note that it might take a few minutes for data to collect, so at first the
list of hosts and services might be sparse and the graphs might be empty.
There are a few ways to embed graphs into Nagios. In the service and host
listings, Nagios will display graph icons that, when clicked, will open a
new web page with graphs. These icons are typically per-host (linked to
the showhost.cgi script) or per-host-service (linked to the show.cgi
script). Nagios will display graph data when the mouse is moved over the
graph icon for each host/service. Finally, graphs can be displayed
directly in the Nagios frames. The following sections explain how to do
each of these.
Graph Icons and Links in Nagios
Links to graphs can be embedded in Nagios status pages using the notes or
actions fields. The specifics depend on the Nagios version as well as how
you have configured your host and service definitions. Nagios 2 uses the
serviceextinfo and hostextinfo construct. In Nagios 3 the nagiosgraph
additions go directly in the host and service definitions.
To display a graph icon instead of the Nagios action icon, replace
nagios/images/action.gif with graph.gif from the nagiosgraph distribution.
In its default configuration, Nagios will create a new window for each
action or notes link. To display graphs in the Nagios frame instead of a
new window, set action_url_target=main in the Nagios cgi.cfg file.
For Nagios 2.6 and Earlier
If you have these lines in nagios.cfg, un-comment the 2 cfg_file= lines:
# Extended host/service info definitions are now stored along with
# other object definitions:
# cfg_file=/etc/nagios/hostextinfo.cfg
# cfg_file=/etc/nagios/serviceextinfo.cfg
Otherwise, define in cgi.cfg the following:
xedtemplate_config_file=/usr/local/nagios/etc/serviceextinfo.cfg
Edit/Create hostextinfo.cfg
define hostextinfo {
host_name your-host
action_url /nagiosgraph/cgi-bin/showhost.cgi?host=$HOSTNAME$
}
This must be the host you will use in serviceextinfo.cfg
Edit/Create serviceextinfo.cfg
define serviceextinfo {
service_description DNS
hostgroup servers
notes_url /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$
icon_image graph.gif
icon_image_alt View graphs
}
For Nagios 2.9 and Nagios 3
Use the action_url for any existing host or service definition. For
example,
define service {
name NTP
use local-service
action_url /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$
...
}
define host {
host_name web-server
action_url /nagiosgraph/cgi-bin/showhost.cgi?host=$HOSTNAME$
...
}
To apply graph links to multiple services, define a template such as this:
define service {
name graphed-service
action_url /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$
register 0
}
Then use it in services like this:
define service {
name NTP
use local-service,graphed-service
...
}
Graphs in Nagios Mouseovers
To display graphs as mouseovers for each host and/or service, do the
following:
1. Edit the file share/nagiosgraph.ssi to contain the URL to the
nagiosgraph javascript file (e.g. /nagiosgraph/nagiosgraph.js)
2. If you have not customized the Nagios SSI, copy share/nagiosgraph.ssi
to the Nagios ssi directory, and rename it so that Nagios will insert
it into each page. For example:
cp share/nagiosgraph.ssi /usr/local/nagios/share/ssi/common-header.ssi
If you have customized Nagios SSI, add the contents of
share/nagiosgraph.ssi to your customized SSI header file.
3. Configure services to display graphs on mouseovers by adding some
JavaScript to action_url or notes_url. For example:
define service {
name NTP
use local-service
action_url /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagiosgraph/cgi-bin/showgraph.cgi?host=$HOSTNAME$&service=$SERVICEDESC$
...
}
This example displays a week of data in a popup with no legend:
define service {
name NTP
use local-service
action_url /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagiosgraph/cgi-bin/showgraph.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&period=week&rrdopts=-w+450+-j
...
}
You must restart Nagios for changes to service/host defintions to take
effect.
If a service includes multiple data sources, use the datasetdb file
(specified in nagiosgraph.conf) to indicate which data sources should be
displayed by default for each service, or specify the data source(s)
explicity in each action_url.
Graphs in Nagios Frames
To embed nagiosgraph graphs directly into Nagios, do the following:
Modify side.php (e.g. /usr/local/nagios/share/side.php) by inserting
bullets under the 'Trends' heading:
<li><a href="<?php echo $cfg["cgi_base_url"];?>/trends.cgi" target="<?php echo $link_target;?>">Trends</a>
<ul>
<li><a href="<?php echo $cfg["cgi_base_url"];?>/show.cgi" target="<?php echo $link_target;?>">Graphs</a></li>
<li><a href="<?php echo $cfg["cgi_base_url"];?>/showhost.cgi" target="<?php echo $link_target;?>">Graphs by Host</a></li>
<li><a href="<?php echo $cfg["cgi_base_url"];?>/showservice.cgi" target="<?php echo $link_target;?>">Graphs by Service</a></li>
<li><a href="<?php echo $cfg["cgi_base_url"];?>/showgroup.cgi" target="<?php echo $link_target;?>">Graphs by Group</a></li>
</ul>
</li>
If you keep the nagiosgraph cgi scripts in a location different than the
Nagios cgi scripts, then use 'ng_cgi_base_url' rather than 'cgi_base_url'
and make an entry in config.inc.php such as this:
$cfg['cgi_base_url']='/nagios/cgi-bin';
$cfg['ng_cgi_base_url']='/nagiosgraph/cgi-bin';
Some Nagios installations have side.html instead of side.php:
<li><a href="/nagios/cgi-bin/trends.cgi" target="main">Trends</a>
<ul>
<li><a href="/nagiosgraph/cgi-bin/show.cgi" target="main">Graphs</a></li>
<li><a href="/nagiosgraph/cgi-bin/showhost.cgi" target="main">Graphs by Host</a></li>
<li><a href="/nagiosgraph/cgi-bin/showservice.cgi" target="main">Graphs by Service</a></li>
<li><a href="/nagiosgraph/cgi-bin/showgroup.cgi" target="main">Graphs by Group</a></li>
</ul>
</li>
Customizing the Graphs
The look and feel of nagiosgraph is controlled by the cascading style
sheets defined in nagiosgraph.css. The examples directory contains a
stylesheet file with sample style sheets for fixing the controls to the
page, floating the controls above the graphs, or hiding the controls
altogether.
Graphs can be customized individually by specifying CGI arguments, or they
can be customized overall by specifying values in the configuration files.
Some parameters apply to each page, others apply to each service, and
others apply to each data source.
The following CGI arguments are recognized by show.cgi, showhost.cgi,
showservice.cgi, and showgroup.cgi:
hidengtitle Do not display the nagiosgraph title in the page.
geom=WxH Set the dimensions of all graphs to W pixels wide and H
pixels tall.
showtitle Display a title next to each graph.
showdesc Display a description of data sources next to each graph.
showgraphtitle Display a title in each graph.
graphonly Display only graph data, not axes, grid, or legend.
hidelegend Do not display the legend in each graph.
fixedscale Set the Y-axis to be in the same scale as the performance
data. This is useful to prevent a variety of vertical
scales when autoscaling results in different vertical
scaling for each graph.
The following options are available via configuration files:
rrdopts Use the rrdopts option to specify custom RRD graphing
options. These can be specified for all graphs using
rrdopts, or per-service using the rrdoptsfile.
lineformat Use lineformat to control the line thickness and line
color for individual data sources. The alpha channel is
respected if a recent version of rrdtool is installed.
plotas, plotasLINE1, plotasLINE2, plotasLINE3, plotasAREA, plotasTICK
Use plotas to control the line thickness/style for
individual data sources.
stack Create stacked area graphs using the stack directive for
individual data sources, the STACK directive in
lineformat, or by adjusting the alpha channel in specified
colors.
Some services emit multiple data sources with big differences in
magnitude. Others emit data with different units. In such cases, split the
data into seperate graphs by specifying one or more data sources. For
example, for the NTP service, jitter and offset are typically in the same
range, while stratum is orders of magnitude larger. So we specify two
different graphs:
show.cgi?host=HOST&service=NTP&db=ntp,jitter&db=ntp,offset
show.cgi?host=HOST&service=NTP&db=ntp,stratum
This assumes that jitter, offset, and stratum are all stored in a single
RRD file using a map entry such as:
/output:NTP.*Offset ([-.0-9]+).*jitter ([-.0-9]+).*stratum (\d+)/
and push @s, [ 'ntp',
[ 'offset', GAUGE, $1 ],
[ 'jitter', GAUGE, $2/1000 ],
[ 'stratum', GAUGE, $3+1 ] ];
Data are identified by host, service, database, and data source. It is
possible to graph all sources from a single database, a single source from
a database, selected sources from a single database, or selected sources
from multiple databases. In each case, the host and service must match.
For example:
showgraph.cgi?host=HOST&service=SERVICE&db=loss
showgraph.cgi?hsot=HOST&service=SERVICE&db=loss,losspct
showgraph.cgi?host=HOST&service=SERVICE&db=ntp,jitter,offset
showgraph.cgi?host=HOST&service=SERVICE&db=loss,losspct&db=rta,rta
These options apply to showgraph.cgi, show.cgi, and showservice.cgi and in
the configuration files hostdb.conf, groupdb.conf, and datasetdb.conf.
Use URLs as canned queries. For example, define a 'temperatures' group in
the groupdb.conf file that combines temperature data from multiple hosts
and service types, then create a link to that group:
http://server/cgi-bin/showgroup.cgi?group=temperatures
See the configuration files for more options and examples.
Adding Service Types
Service types are added by creating rules in the 'map' file. The map file
determines how data from Nagios will be stored. Each rule determines how
output and performance data should be recorded.
The map file contains regular expressions to identify service types and
define content in RRD files. All entries are written in perl, so editing,
adding or deleting entries requires some perl programming knowledge.
Knowledge of RRD is also helpful.
There has to be one entry for each type of service. The map file included
with nagiosgraph has several examples for cpu, memory, disk, network etc.
Most examples identify data from either Nagios output or Nagios perfdata
then define a number of RRD data sources. There is also a generic rule
that will capture output from any plugin that adheres to the Nagios
standards for plugin performance data.
insert.pl receives data from Nagios. It formats data into a string
consisting of four lines of text. This string might look like this:
hostname:host0
servicedesc:ping
output:PING OK - Packet loss = 0%, RTA = 0.00 ms
perfdata:
Or like this:
hostname:host0
servicedesc:CPU Load
output:OK - load average: 0.06, 0.12, 0.10
perfdata:load1=0;15;30;0 load5=0;10;25;0 load15=0;5;20;0
The official perfdata format is a space-delimited list of qualified
name-value pairs with this format:
name=value[units];[warn];[crit];[min];[max]
where units is one of:
- unitless
s,us,ms - time
% - percentage
B,KB,MB,GB,TB,PB - bytes
c - counter
However, the perfdata is not always set, and the format of perfdata varies
a great deal from plugin to plugin. So depending on type of service, the
most useful data can be in either the output or perfdata line.
For the ping example above, data can be extracted from the output line
with a regular expression like this:
/output:PING.*?(\d+)%.+?([.\d]+)\sms/
In this case, two values are extracted and available in $1 and $2. We can
then create a data structure describing the content of the database. The
general format is
[ db-name,
[ DS-name, TYPE, DS-value ],
[ DS-name, TYPE, DS-value ],
...
]
Where DS name is the name that will be assigned to a line showing on RRD
graphs. Each DS name must be no longer than 19 characters and must contain
only the characters A-Z, a-z, 0-9, or underscore. TYPE is either GAUGE or
DERIVE. the DS value is the data extracted in the regular expression. The
DS value can be an expression, for example to normalize to SI units.
Each database definition must be added to the @s array.
So the complete code to define and insert into an RRD file for the PING
example above, becomes:
/output:PING.*?(\d+)%.+?([.\d]+)\sms/
and push @s, [ ping,
[ losspct, GAUGE, $1 ],
[ rta, GAUGE, $2/1000 ] ];
In this case the database name is called 'ping' and the DS-names stored
are losspct and rta. The Nagios output reports round trip time in
milliseconds, so the value is divided by 1000 to convert to seconds. The
type for each DS is GAUGE.
Be careful about the database names and DS names. In the code example
above the names are barewords, which only works as long as the don't
conflict with perl functions or subroutines. For example the word 'sleep'
will not work without quoting.
A safer version of the above example is
/output:PING.*?(\d+)%.+?([.\d]+)\sms/
and push @s, [ 'ping',
[ 'losspct', 'GAUGE', $1 ],
[ 'rta', 'GAUGE', $2/1000 ] ];
After editing the map file, the syntax can be checked with
perl -c map
Again a word of caution. If the map file has syntax errors, nothing will
be inserted into RRD files until the file is fixed. So do not edit
production map files. Instead do something like this:
cp map map.edit
vi map.edit
perl -c map.edit
mv map.edit map
Use testentry.pl to test a rule before putting it into production. First
run the Nagios check command from the command line to see what is
returned. Copy this output and paste it into testentry.pl. Paste the rule
into testentry.pl. Run testentry.pl to see how the output will be handled.
Changes to the map file generally do not require a restart of Nagios.
It may take awhile for data from a map entry to show up in an RRD file.
This is partly due to the service check scheduling in Nagios, and partly
due to the perfdata buffering of service_perfdata_file_processing_interval
Increase debug level in nagiosgraph.conf to see what is happening. The
debug_insert parameter determines the log level for collecting data.
Output will go to the nagiosgraph log file. Keep an eye on the log file;
it can grow big. Perhaps rotate it, or decrease log level when everything
works.
Share your work. If you have a good map file entry for standard Nagios
plugins, then please post it on the forum.
Managing Data and RRD Files
nagiosgraph saves data in RRD files in the rrddir directory (specified in
nagiosgraph.conf). By default, nagiosgraph uses a directory for each host,
and the RRD files are named based on the service description (from Nagios)
and the data names (from the map file). For example, the default
configuration for the PING service results in RRD files like this:
/var/nagiosgraph/rrd/host/PING___pingloss.rrd
/var/nagiosgraph/rrd/host/PING___pingrta.rrd
Older versions of nagiosgraph kept all RRD files in a single directory.
This is controlled by the dbseparator variable in nagiosgraph.conf.
Use the 'dump' and 'restore' options to rrdtool if you need to restructure
RRD files. You might want to split data from a single RRD file into
multiple files, or you might want to combine data from multiple RRD files
into a single file. Or you might simply want to change the name of a data
source. The dump option will emit data in XML format:
rrdtool dump service___db.rrd > service_db.xml
You can modify the XML with any text editor, then convert to RRD format:
rrdtool restore service_db.xml service___db-new.rrd
Unfortunately the RRD file schema is not dynamic. If an RRD file is
created with 2 data sources, more data sources cannot be added
automatically. For example, you start recording UPS temperature to an RRD
file using the following map rule:
/perfdata:temperature=([.\d]+)/
and push @s, [ 'temp',
[ 'temperature', GAUGE, $1 ] ];
Later you decide to include critical and warning temperatures using this
map rule:
/perfdata:temperature=([.\d]+);([.\d]+);([.\d]+)/
and push @s, [ 'temp',
[ 'temperature', GAUGE, $1 ],
[ 'warn', GAUGE, $2 ],
[ 'crit', GAUGE, $3 ] ];
The new rule will still record temperature, but critical and warning
values will be discarded, because they are not defined in the RRD file.
You must do a dump/edit/restore on the RRD file if you want to add
critical/warning while maintaining existing temperature data.
Alternatively you can simply delete the existing RRD file and let the new
map rule create the new RRD file.
What is the 'right' way to configure RRD files? Should all data from a
single service go into a single RRD file? Should each RRD file contain a
single set of data? Some best practices have evolved over the past 10
years, but as of this writing (febrary 2010) there is no single 'right'
way.
Some people prefer to put all data from a single service into a single RRD
file, even if the data have different units. For example, for the PING
service their RRD files look something like this:
PING___ping.rrd (losspct, losswarn, losscrit, rta, rtawarn, rtacrit)
Others prefer a separate file for each data source:
PING___losspct.rrd (losspct)
PING___losswarn.rrd (losswarn)
PING___losscrit.rrd (losscrit)
PING___rta.rrd (rta)
PING___rtawarn.rrd (rtawarn)
PING___rtacrit.rrd (rtacrit)
And others prefer something in between:
PING___loss.rrd (losspct, losswarn, losscrit)
PING___rta.rrd (rta, rtawarn, rtacrit)
It is a good idea to plan your configuration before you start recording
data. Although it is possible to reconfigure data after the RRD files are
full, doing so is somewhat tedious, especially for large numbers of
hosts/services.
The 1.4.4 release of nagiosgraph added a generic map rule that matches any
standard performance data. This rule puts the data into RRD files using
this structure:
host0/service___label.rrd (data[,warn][,crit][,min][,max])
For example, for service0 with 3 perfdata labels and service1 with 1
perfdata labels, the rule generates the following RRD files:
host0/service0___label0.rrd (data[,warn][,crit][,min][,max])
host0/service0___label1.rrd (data[,warn][,crit][,min][,max])
host0/service0___label2.rrd (data[,warn][,crit][,min][,max])
host0/service1___label0.rrd (data[,warn][,crit][,min][,max])
There are a few rrdtool parameters that affect size of the RRD files and
the resolution of data:
stepsize
resolution
heartbeat
step
These parameters are used only when an RRD file is created. By default
they are the same for all hosts and services, but they can be specified
for individual hosts, services, and or databases in the nagiosgraph
configuration file. To modify these values for an existing RRD file you
must do a dump/edit/restore. See the rrdtool documentation for details.
Managing RRD Parameters
The most important parameters are stepsize, heartbeat, and sampling
interval. A typical sign that these parameters are not set correctly is
values of NaN in the RRD files, which manifests as gaps in the graphs or
empty graphs.
A good rule of thumb is to use a heartbeat that is twice the sampling
interval and a stepsize equal to the sampling interval.
In a default nagiosgraph configuration, the same parameters are applied to
all hosts and services. However, they can be specified for individual
hosts and services if necessary.
The stepsize, in seconds, defines the nominal amount of time between data
points. The default value is 300 (5 minutes). The heartbeat, in seconds,
defines the amount of time between updates before a data point should be
considered unknown. The default value is 600 (10 minutes). The resolution
defines how many data points should be kept. The step defines how data
points are consolidated. The xfiles factor defines how unknown data points
are considered when consolidating data. These parameters are specified in
the nagiosgraph configuration file.
The sampling interval is defined in Nagios (check_interval). This defines
how often a service will be checked.