Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / pnp-templates / check_mk-df.php
blobfd63f5f4d3be958704607aa5eed6ca0436bc2523
1 <?php
2 # +------------------------------------------------------------------+
3 # | ____ _ _ __ __ _ __ |
4 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
5 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
6 # | | |___| | | | __/ (__| < | | | | . \ |
7 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
8 # | |
9 # | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
10 # +------------------------------------------------------------------+
12 # This file is part of Check_MK.
13 # The official homepage is at http://mathias-kettner.de/check_mk.
15 # check_mk is free software; you can redistribute it and/or modify it
16 # under the terms of the GNU General Public License as published by
17 # the Free Software Foundation in version 2. check_mk is distributed
18 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
19 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
20 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
21 # tails. You should have received a copy of the GNU General Public
22 # License along with GNU Make; see the file COPYING. If not, write
23 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
24 # Boston, MA 02110-1301 USA.
26 setlocale(LC_ALL, "POSIX");
28 // Make data sources available via names
29 $RRD = array();
30 foreach ($NAME as $i => $n) {
31 $RRD[$n] = "$RRDFILE[$i]:$DS[$i]:MAX";
32 $RRD_MIN[$n] = "$RRDFILE[$i]:$DS[$i]:MIN";
33 $RRD_AVG[$n] = "$RRDFILE[$i]:$DS[$i]:AVERAGE";
34 $WARN[$n] = $WARN[$i];
35 $CRIT[$n] = $CRIT[$i];
36 $MIN[$n] = $MIN[$i];
37 $MAX[$n] = $MAX[$i];
38 $ACT[$n] = $ACT[$i];
41 # RRDtool Options
42 #$servicedes=$NAGIOS_SERVICEDESC
44 if (substr($servicedesc, 0, 3) == 'fs_') {
45 $fsname = str_replace("_", "/", substr($servicedesc,3));
46 } else {
47 $fsname = str_replace("_", "/", substr($servicedesc,11));
50 $fstitle = $fsname;
52 # Hack for windows: replace C// with C:\
53 if (strlen($fsname) == 3 && substr($fsname, 1, 2) == '//') {
54 $fsname = $fsname[0] . "\:\\\\";
55 $fstitle = $fsname[0] . ":\\";
58 $sizegb = sprintf("%.1f", $MAX[1] / 1024.0);
59 $maxgb = $MAX[1] / 1024.0;
60 $warngb = $WARN[1] / 1024.0;
61 $critgb = $CRIT[1] / 1024.0;
62 $warngbtxt = sprintf("%.1f", $warngb);
63 $critgbtxt = sprintf("%.1f", $critgb);
65 $opt[1] = "--vertical-label GB -l 0 -u $maxgb --title '$hostname: Filesystem $fstitle ($sizegb GB)' ";
67 # First graph show current filesystem usage. If there is a "reserved" RRD
68 # then substract that and show as extra area
69 $def[1] = "DEF:mb=$RRDFILE[1]:$DS[1]:MAX ";
70 if (isset($RRD['reserved']))
72 $def[1] .= "DEF:reserved=$RRD[reserved] ";
73 $def[1] .= "CDEF:used=mb,reserved,- ";
74 $def[1] .= "CDEF:var1=used,1024,/ ";
75 $def[1] .= "AREA:var1#00ffc6:\"used space on $fsname\" ";
76 $def[1] .= "CDEF:reserved_gb=reserved,1024,/ ";
77 $def[1] .= "AREA:reserved_gb#B748B2:\"reserved for root\\n\" ";
79 else {
80 $def[1] .= "CDEF:var1=mb,1024,/ ";
81 $def[1] .= "AREA:var1#00ffc6:\"used space on $fsname\\n\" ";
84 # Optional size of fs plotted
85 if(isset($RRD['fs_size'])) {
86 $def[1] .= "DEF:size_plotted_mb=".$RRD['fs_size']." ";
87 $def[1] .= "CDEF:size_plotted_gb=size_plotted_mb,1024,/ ";
88 $def[1] .= "LINE:size_plotted_gb#003300:\"Size $sizegb GB \" ";
89 } else {
90 $def[1] .= "HRULE:$maxgb#003300:\"Size ($sizegb GB) \" ";
93 # Optional uncommitted usage e.g. for esx hosts
94 if (isset($RRD['uncommitted'])) {
95 $def[1] .= "DEF:uncommitted_mb=".$RRD['uncommitted']." ";
96 $def[1] .= "CDEF:uncommitted_gb=uncommitted_mb,1024,/ ";
97 $def[1] .= "CDEF:total_gb=uncommitted_gb,var1,+ ";
99 else {
100 $def[1] .= "CDEF:total_gb=var1 ";
103 $def[1] .= "HRULE:$warngb#ffff00:\"Warning at $warngbtxt GB \" ";
104 $def[1] .= "HRULE:$critgb#ff0000:\"Critical at $critgbtxt GB \\n\" ";
105 $def[1] .= "GPRINT:var1:LAST:\"current\: %6.2lf GB\" ";
106 $def[1] .= "GPRINT:var1:MAX:\"max\: %6.2lf GB \" ";
107 $def[1] .= "GPRINT:var1:AVERAGE:\"avg\: %6.2lf GB\\n\" ";
109 if(isset($RRD['uncommitted'])) {
110 $def[1] .= "AREA:uncommitted_gb#eeccff:\"Uncommited\":STACK ";
111 $def[1] .= "GPRINT:uncommitted_gb:MAX:\"%6.2lf GB\l\" ";
114 $def[1] .= "LINE1:total_gb#226600 ";
116 # Second graph is optional and shows trend. The MAX field
117 # of the third variable contains (size of the filesystem in MB
118 # / range in hours). From that we can compute the configured range.
119 if (isset($RRD['growth'])) {
120 $size_mb_per_hours = floatval($MAX['trend']); // this is size_mb / range(hours)
121 $size_mb = floatval($MAX[1]);
122 $hours = 1.0 / ($size_mb_per_hours / $size_mb);
123 $range = sprintf("%.0fh", $hours);
125 // Current growth / shrinking. This value is give as MB / 24 hours.
126 // Note: This has changed in 1.1.13i3. Prior it was MB / trend_range!
127 $opt[2] = "--vertical-label '+/- MB / 24h' -l -1 -u 1 -X0 --title '$hostname: Growth of $fstitle' ";
128 $def[2] = "DEF:growth_max=${RRD['growth']} ";
129 $def[2] .= "DEF:growth_min=${RRD_MIN['growth']} ";
130 $def[2] .= "DEF:trend=${RRD_AVG['trend']} ";
131 $def[2] .= "CDEF:growth_pos=growth_max,0,MAX ";
132 $def[2] .= "CDEF:growth_neg=growth_min,0,MIN ";
133 $def[2] .= "CDEF:growth_minabs=0,growth_min,- ";
134 $def[2] .= "CDEF:growth=growth_minabs,growth_max,MAX ";
135 $def[2] .= "HRULE:0#c0c0c0 ";
136 $def[2] .= "AREA:growth_pos#3060f0:\"Grow\" ";
137 $def[2] .= "AREA:growth_neg#30f060:\"Shrink \" ";
138 $def[2] .= "GPRINT:growth:LAST:\"Current\: %+9.2lfMB / 24h\" ";
139 $def[2] .= "GPRINT:growth:MAX:\"Max\: %+9.2lfMB / 24h\\n\" ";
141 // Trend
142 $opt[3] = "--vertical-label '+/- MB / 24h' -l -1 -u 1 -X0 --title '$hostname: Trend for $fstitle' ";
143 $def[3] = "DEF:trend=${RRD_AVG['trend']} ";
144 $def[3] .= "HRULE:0#c0c0c0 ";
145 $def[3] .= "LINE1:trend#000000:\"Trend\:\" ";
146 $def[3] .= "GPRINT:trend:LAST:\"%+7.2lf MB/24h\" ";
147 if ($WARN['trend']) {
148 $warn_mb = sprintf("%.2fMB", $WARN['trend'] * $hours / 24.0);
149 $def[3] .= "LINE1:${WARN['trend']}#ffff00:\"Warn\: $warn_mb / $range\" ";
151 if ($CRIT['trend']) {
152 $crit_mb = sprintf("%.2fMB", $CRIT['trend'] * $hours / 24.0);
153 $def[3] .= "LINE1:${CRIT['trend']}#ff0000:\"Crit\: $crit_mb / $range\" ";
155 $def[3] .= "COMMENT:\"\\n\" ";
158 if (isset($RRD['trend_hoursleft'])) {
159 // Trend
160 $opt[4] = "--vertical-label 'Days left' -l -1 -u 365 -X0 --title '$hostname: Days left for $fstitle' ";
161 $def[4] = "DEF:hours_left=${RRD_AVG['trend_hoursleft']} ";
162 $def[4] .= "DEF:hours_left_min=${RRD_MIN['trend_hoursleft']} ";
163 // negative hours indicate no growth
164 // the dataset hours_left_isneg stores this info for each point as True/False
165 $def[4] .= "CDEF:hours_left_isneg=hours_left_min,-1,EQ ";
166 $def[4] .= "CDEF:hours_left_unmon=hours_left_min,400,0,IF ";
167 $def[4] .= "CDEF:days_left=hours_left,24,/ ";
168 $def[4] .= "CDEF:days_left_cap=days_left,400,MIN ";
169 // Convert negative points to 400 (y-axis cap)
170 $def[4] .= "CDEF:days_left_cap_positive=hours_left_isneg,400,days_left_cap,IF ";
171 // The AREA has a rendering problem. Points are too far to the right
172 $def[4] .= "AREA:hours_left_unmon#AA2200: ";
174 $def[4] .= "AREA:days_left_cap_positive#22AA44:\"Days left\:\" ";
175 if ($ACT[4] == -1)
177 $def[4] .= "COMMENT:\"Not growing\" ";
179 else {
180 $def[4] .= "GPRINT:days_left:LAST:\"%7.2lf days\" ";
184 if (isset($RRD['inodes_used'])) {
185 $opt[5] = "--vertical-label 'Inode usage' -l 0 -u $MAX[inodes_used] --title '$hostname: Inodes usage for $fstitle' ";
186 $def[5] = "DEF:inodes_used=${RRD['inodes_used']} ";
187 $def[5] .= "AREA:inodes_used#a0608f:\"Inodes used\:\" ";
188 $def[5] .= "GPRINT:inodes_used:LAST:\"%2.0lf\" ";
189 $def[5] .= "LINE1:inodes_used#c00080:\"\" ";
190 $def[5] .= "GPRINT:inodes_used:MAX:\"Max\: %2.0lf\" ";
191 $def[5] .= "GPRINT:inodes_used:AVERAGE:\"Average\: %2.0lf\\n\" ";
192 $def[5] .= "HRULE:$MAX[inodes_used]#000000:\"Total Inodes \" ";
193 if (isset($WARN['inodes_used']) && $WARN['inodes_used']) {
194 $def[5] .= "HRULE:$WARN[inodes_used]#ffff00:\"Warning at $WARN[inodes_used] \" ";
195 $def[5] .= "HRULE:$CRIT[inodes_used]#ff0000:\"Critical at $CRIT[inodes_used]\\n\" ";