summaryrefslogtreecommitdiffstats
path: root/templates/check_disk_and_inode.php
blob: bdd988c6d785bb93b85cc6e71782742a63dd021f (plain)
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
<?php
#
# check_interfaces -- template to generate RRD graph
# Copyright (C) 2014 Red Hat Inc
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#

function endsWith($haystack, $needle)
{
  return $needle === "" || substr($haystack, -strlen($needle)) === $needle;
}

foreach ($this->DS as $KEY=>$VAL) {
  if ($VAL['TEMPLATE'] == "check_brick_usage") {
    $ds_name[$KEY] = "Brick Utilization";
  } else {
    $ds_name[$KEY] = "Disk Utilization";
  }
  $name[$KEY] = "Mount Path: ";
  $graph_type = $VAL['LABEL'];
  $max_limit = $VAL['MAX'];
  $unit = "GiB";
  if (endsWith($graph_type,".inode") || endsWith($graph_type,".thinpool") || endsWith($graph_type,".thinpool-metadata")) {
    list ($brick,$data_type) = explode (".", $graph_type);
    $ds_name[$KEY] .= "(";
    $ds_name[$KEY] .= $data_type;
    $ds_name[$KEY] .= ")";
    $name[$KEY] .= $brick ;
    if ($data_type == "inode"){
      $unit = "";
    }
  } else {
    $name[$KEY] .= $graph_type;
    $ds_name[$KEY] .= "(space)";
  }
  $opt[$KEY] = "--vertical-label \"%(Total: $max_limit $unit) \"  --lower-limit 0 --upper-limit 100 -r --title \"$name[$KEY]\" ";

  $def[$KEY]     = rrd::def( "var1", $VAL['RRDFILE'], $VAL['DS'], "AVERAGE" );

  $def[$KEY]    .= rrd::area( "var1", "#008000", "Brick Usage" );
  $def[$KEY] .= rrd::gprint  ("var1", array("LAST","MAX","AVERAGE"), "%.3lf %%");

  $def[$KEY] .= rrd::line2( $VAL['WARN'], "#FFA500", "Warning\\n");

  $def[$KEY] .= rrd::line2( $VAL['CRIT'], "#FF0000", "Critical\\n");
  $def[$KEY] .= rrd::comment ("   \\n");
}
?>