From e91468e8030ce33963826eab07601aa882f2ba0d Mon Sep 17 00:00:00 2001 From: ndarshan Date: Tue, 6 Jan 2015 16:45:20 +0530 Subject: graph-templates: disk and brick utilization graph template modification. This patch modifies the graph template for brick utilization and disk utilization to handle the changes made by check_disk _and_inode plugin revamp. Now separate graphs for data, inode, thinpool and thinpool-metadata utilization are shown. Change-Id: Iad7da8ab3fede89bb528ceadfd817646c018795e Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1167771 Signed-off-by: ndarshan Reviewed-on: http://review.gluster.org/9394 Reviewed-by: Bala FA Reviewed-by: Sahina Bose --- templates/Makefile.am | 3 ++ templates/check_brick_usage.php | 52 -------------------------- templates/check_disk_and_inode.php | 75 +++++++++++++++++--------------------- 3 files changed, 36 insertions(+), 94 deletions(-) delete mode 100644 templates/check_brick_usage.php diff --git a/templates/Makefile.am b/templates/Makefile.am index 6d93fd7..c2c491f 100644 --- a/templates/Makefile.am +++ b/templates/Makefile.am @@ -21,3 +21,6 @@ EXTRA_DIST = \ $(pnp4nagioscheckcommand_DATA) \ $(pnp4nagiostemplate_DATA) \ $(NULL) + +check_brick_usage.php: + ln -sf check_disk_and_inode.php check_brick_usage.php diff --git a/templates/check_brick_usage.php b/templates/check_brick_usage.php deleted file mode 100644 index 9c926b8..0000000 --- a/templates/check_brick_usage.php +++ /dev/null @@ -1,52 +0,0 @@ -DS as $KEY=>$VAL) { - # $VAL['NAME'] = str_replace("_","/",$VAL['NAME']); - $ds_name[$KEY] = "Brick Utilization "; - $graph_type = $VAL['LABEL']; - if ($graph_type == "Thin-pool" ) { - $ds_name[$KEY] .= "(Thin-pool)"; - } - $name[$KEY] = "Brick Path: " . $NAGIOS__SERVICEBRICK_DIR; - - # set graph labels - $max_limit = $VAL['MAX']; - $opt[$KEY] = "--vertical-label \"%(Total: $max_limit GB) \" --lower-limit 0 --upper-limit 100 -r --title \"$name[$KEY]\" "; - - # Graph Definitions - $def[$KEY] = rrd::def( "var1", $VAL['RRDFILE'], $VAL['DS'], "AVERAGE" ); - - # disk graph rendering - $def[$KEY] .= rrd::area( "var1", "#008000", "Brick Usage" ); - $def[$KEY] .= rrd::gprint ("var1", array("LAST","MAX","AVERAGE"), "%3.4lf %S%%"); - $i = 1; - $k = $KEY; - - # create warning line and legend - $def[$k] .= rrd::line2( $VAL['WARN'], "#FFA500", "Warning\\n"); - -# create critical line and legend - $def[$k] .= rrd::line2( $VAL['CRIT'], "#FF0000", "Critical\\n"); - $def[$k] .= rrd::comment (" \\n"); -} -?> diff --git a/templates/check_disk_and_inode.php b/templates/check_disk_and_inode.php index 6146a6a..bdd988c 100644 --- a/templates/check_disk_and_inode.php +++ b/templates/check_disk_and_inode.php @@ -18,53 +18,44 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # -# -# set graph labels -$i = 0; -$k = 0; +function endsWith($haystack, $needle) +{ + return $needle === "" || substr($haystack, -strlen($needle)) === $needle; +} + foreach ($this->DS as $KEY=>$VAL) { - if ($i == 0) { - $VAL['NAME'] = str_replace("_","/",$VAL['NAME']); + if ($VAL['TEMPLATE'] == "check_brick_usage") { + $ds_name[$KEY] = "Brick Utilization"; + } else { $ds_name[$KEY] = "Disk Utilization"; - $name[$KEY] = "Disk Utilization for mount: " . $VAL['NAME']; - - # set graph labels - $max_limit = $VAL['MAX']; - $opt[$KEY] = "--vertical-label \"%(Total: $max_limit GB) \" --lower-limit 0 --upper-limit 100 --title \"$name[$KEY]\" "; - # Graph Definitions - $def[$KEY] = rrd::def( "var1", $VAL['RRDFILE'], $VAL['DS'], "AVERAGE" ); - - # disk graph rendering - if ($VAL['ACT'] >= $VAL['CRIT']) { - $def[$KEY] .= rrd::line1( "var1", "#008000", "Disk Usage" ); - } elseif ($VAL['ACT'] >= $VAL['WARN']) { - $def[$KEY] .= rrd::line1( "var1", "#008000", "Disk Usage" ); - }else { - $def[$KEY] .= rrd::line1( "var1", "#008000", "Disk Usage" ); - } - $def[$KEY] .= rrd::gprint ("var1", array("LAST","MAX","AVERAGE"), "%3.4lf %S%%"); - $i = 1; - $k = $KEY; } - else { - # inode graph rendering - $def[$k] .= rrd::def( "var2", $VAL['RRDFILE'], $VAL['DS'], "AVERAGE" ); - if ($VAL['ACT'] >= $VAL['CRIT']) { - $def[$k] .= rrd::line1( "var2", "#0000FF", "Inode Usage" ); - } elseif ($VAL['ACT'] >= $VAL['WARN']) { - $def[$k] .= rrd::line1( "var2", "#0000FF", "Inode Usage" ); - }else { - $def[$k] .= rrd::line1( "var2", "#0000FF", "Inode Usage" ); + $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 = ""; } - $def[$k] .= rrd::gprint ("var2", array("LAST","MAX","AVERAGE"), "%3.4lf %S%%"); - $i = 0; + } 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]\" "; - # create warning line and legend - $def[$k] .= rrd::line2( $VAL['WARN'], "#FFA500", "Warning\\n"); + $def[$KEY] = rrd::def( "var1", $VAL['RRDFILE'], $VAL['DS'], "AVERAGE" ); - # create critical line and legend - $def[$k] .= rrd::line2( $VAL['CRIT'], "#FF0000", "Critical\\n"); - $def[$k] .= rrd::comment (" \\n"); - } + $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"); } ?> -- cgit