On Tue, May 04, 2010 at 10:58:21AM -0400, Bennett, Ron wrote: > Ron, > > Thanks, this is what we need. In case we decide not to count rrd files, is > there equivalent > code to the following to count all hosts in a single cluster? > > #print_r($grid); > $mygrid=array_shift($grid); > print "<br>".$mygrid["NAME"]."<br>"; > $x=($mygrid["HOSTS_UP"] + $mygrid["HOSTS_DOWN"]); > print $x; > Something like $grid[$cluster] ?
Probably the next thing to do would be parse the XML stream from gmetad, and count <HOST> tags.... > > thanks, > Ron > > > > ----------------------------------------------------------------------------------------------- > > From: Ron Wellnitz [mailto:[email protected]] > Sent: Tuesday, May 04, 2010 1:57 AM > To: Bennett, Ron > Cc: [email protected] > Subject: Re: [Ganglia-general] counting all hosts > 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 > [1][email protected] > [2]https://lists.sourceforge.net/lists/listinfo/ganglia-general > > >References > > Visible links > 1. mailto:[email protected] > 2. https://lists.sourceforge.net/lists/listinfo/ganglia-general Content-Description: ATT00001..txt >------------------------------------------------------------------------------ Content-Description: ATT00002..txt >_______________________________________________ >Ganglia-general mailing list >[email protected] >https://lists.sourceforge.net/lists/listinfo/ganglia-general -- Jesse Becker NHGRI Linux support (Digicon Contractor) ------------------------------------------------------------------------------ _______________________________________________ Ganglia-general mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ganglia-general

