[42] | 1 | map file |
---|
| 2 | -------- |
---|
| 3 | |
---|
| 4 | File: $Id: README.map,v 1.3 2005/10/08 05:55:08 sauber Exp $ |
---|
| 5 | Author: (c) Soren Dossing, 2005 |
---|
| 6 | License: OSI Artistic License |
---|
| 7 | http://www.opensource.org/licenses/artistic-license.php |
---|
| 8 | |
---|
| 9 | This describes how to work with the map file. |
---|
| 10 | |
---|
| 11 | The file called 'map' contains regular expressions to identify services |
---|
| 12 | and define content in RRD databases. All entries are written in perl, so |
---|
| 13 | editing, adding or deleting entries requires some perl programming |
---|
| 14 | knowledge. Knowledge of RRD is also necessary. |
---|
| 15 | |
---|
| 16 | There has to be one entry for each type of service. The distributed map |
---|
| 17 | file already have several examples for cpu, memory, disk, network etc. |
---|
| 18 | Most examples follow the same schema of identifying data from either |
---|
| 19 | Nagios output or Nagios perfdata and defining a number of rrd data |
---|
| 20 | sources. |
---|
| 21 | |
---|
| 22 | insert.pl is the script receiving data from Nagios. It format data for map |
---|
| 23 | file by creating one string consisting of three lines of text. This string |
---|
| 24 | might look like this: |
---|
| 25 | |
---|
| 26 | servicedesc:ping |
---|
| 27 | output:PING OK - Packet loss = 0%, RTA = 0.00 ms |
---|
| 28 | perfdata: |
---|
| 29 | |
---|
| 30 | Or like this: |
---|
| 31 | |
---|
| 32 | servicedescr:CPU Load |
---|
| 33 | output:OK - load average: 0.06, 0.12, 0.10 |
---|
| 34 | perfdata:load1=0;15;30;0 load5=0;10;25;0 load15=0;5;20;0 |
---|
| 35 | |
---|
| 36 | perfdata is not always set, so depending on type of service, the most |
---|
| 37 | useful data can be in either the output or perfdata line. |
---|
| 38 | |
---|
| 39 | For the ping example above, data can be extracted from the output line |
---|
| 40 | with a regular expression like this: |
---|
| 41 | |
---|
| 42 | /output:PING.*?(\d+)%.+?([.\d]+)\sms/ |
---|
| 43 | |
---|
| 44 | In this case, two values are extracted and available in $1 and $2. We can |
---|
| 45 | then create a data structure describing the content of the database. The |
---|
| 46 | general format is |
---|
| 47 | |
---|
| 48 | [ db-name, |
---|
| 49 | [ DS-name, TYPE, DS-value ], |
---|
| 50 | [ DS-name, TYPE, DS-value ], |
---|
| 51 | ... |
---|
| 52 | ] |
---|
| 53 | |
---|
| 54 | Where DS-name is the name that will be assigned to a line showing on rrd |
---|
| 55 | graphs. TYPE is either GAUGE or DERIVE. the DS value is the data |
---|
| 56 | extracted in the regular expression. The DS value can be an expression, |
---|
| 57 | for example to normalize to SI units. |
---|
| 58 | |
---|
| 59 | Each database definition must be added to the @s array. |
---|
| 60 | |
---|
| 61 | So the complete code to define and insert into and rrd database for the |
---|
| 62 | PING example above, becomes: |
---|
| 63 | |
---|
| 64 | /output:PING.*?(\d+)%.+?([.\d]+)\sms/ |
---|
| 65 | and push @s, [ ping, |
---|
| 66 | [ losspct, GAUGE, $1 ], |
---|
| 67 | [ rta, GAUGE, $2/1000 ] ]; |
---|
| 68 | |
---|
| 69 | In this case the database name is called 'ping' and the DS-names stored |
---|
| 70 | are losspct and rta. The Nagios output reports round trip time in |
---|
| 71 | milliseconds, so the value is multiplied by 1000 to convert to seconds. |
---|
| 72 | Both DS type are GAUGE. |
---|
| 73 | |
---|
| 74 | Be careful about the database names and DS names. In the code example |
---|
| 75 | above the names are barewords, which only works as long as the don't |
---|
| 76 | conflict with perl functions or subroutines. For example the word 'sleep' |
---|
| 77 | will not work without quoting. |
---|
| 78 | |
---|
| 79 | A safer version of the above example is |
---|
| 80 | |
---|
| 81 | /output:PING.*?(\d+)%.+?([.\d]+)\sms/ |
---|
| 82 | and push @s, [ 'ping', |
---|
| 83 | [ 'losspct', 'GAUGE', $1 ], |
---|
| 84 | [ 'rta', 'GAUGE', $2/1000 ] ]; |
---|
| 85 | |
---|
| 86 | After editing map file, the syntax can be checked with |
---|
| 87 | |
---|
| 88 | perl -c map |
---|
| 89 | |
---|
| 90 | Again a word of caution. If map file has syntax errors, nothing will be |
---|
| 91 | inserted into rrd files until the file is fixed. So don't edit production |
---|
| 92 | map files. Instead do something like this: |
---|
| 93 | |
---|
| 94 | cp map map.edit |
---|
| 95 | vi map.edit |
---|
| 96 | perl -c map.edit |
---|
| 97 | mv map.edit map |
---|
| 98 | |
---|
| 99 | Share your work. If you have a good map file entry for standard Nagios |
---|
| 100 | plugins, then please post it on the forum, or send it to me. |
---|