Hi Ron,
one possibility in php is
test.php:
<?php
include_once "./conf.php";
include_once "./get_context.php";
include_once "./functions.php";
include_once "./ganglia.php";
include_once "./get_ganglia.php";
Gmetad();
#print_r($grid);
$mygrid=array_shift($grid);
print "<br>".$mygrid["NAME"]."<br>";
$x=($mygrid["HOSTS_UP"] + $mygrid["HOSTS_DOWN"]);
print $x;
?>
if you are already in a "orginal" ganglia php script, you do not need
the "include"-lines.
when a host is down and you restart the gmetad daemon, this down host
will not be longer recognize by ganglia !
so it can be usefull to write a little script (php/ksh), which count the
number of a uniqe rrd file ... something like this:
$base="/var/lib/ganglia/rrds";
$hosts=0;
foreach (glob("${base}/*/*/cpu_idle.rrd") as $filepath) {
$array = split("/",$filepath);
$x = count($array);
$server = $array[$x-2];
$cluster = $array[$x-3];
if ( $server != "__SummaryInfo__" && $cluster != "__SummaryInfo__" ) {
$hosts++;
}
}
}
if you need to seperate between up and down, you can check the last
update of an rrd file
$cmd = "/usr/bin/rrdtool lastupdate $filepath 2>/dev/null";
$last_line = exec($cmd, $dummy, $retval);
if ( $retval == 0 ) {
$content = split(":",$last_line);
$timestamp = $content[0];
$idle = $content[1];
$diff = time() - $timestamp;
if ( $diff >= 120 ) { #offline;}
else {#online;}
}
greets
Ron
Am 03.05.2010 20:09, schrieb Bennett, Ron:
The sample PHP code contains instructions like the following to count
nodes for computing averages:
$series =
"DEF:'num_nodes'='${rrd_dir}/cpu_user.rrd':'num':AVERAGE "
. "DEF:'cpu_user'='${rrd_dir}/cpu_user.rrd':'sum':AVERAGE "
. "CDEF:'ccpu_user'=cpu_user,num_nodes,/ "
This method appears to count "HOSTS UP" as the number of nodes. For a
new gmetric, we need to be able to count total hosts (UP and DOWN),
not just UP.
Is there a recommended method in PHP for getting the total number of
nodes (UP plus DOWN)?
Thanks,
Ron
------------------------------------------------------------------------------
_______________________________________________
Ganglia-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ganglia-general
------------------------------------------------------------------------------
_______________________________________________
Ganglia-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ganglia-general