"; $in=""; $running=""; $stopped=""; $log=""; $start=""; $stop=""; $clients=array(); $clientstraffic=array(); $statistics = haproxy_get_statistics(); $frontends = $statistics['frontends']; $backends = $statistics['backends']; $servers = $statistics['servers']; if ($show_clients == "YES") { $clients = haproxy_get_clients(); } echo ""; print ""; print ""; print ""; foreach ($frontends as $fe => $fedata){ print ""; print ""; if ($fedata['status'] == "OPEN") { $fedata['status'] = $running." ".$fedata['status']; } else { $fedata['status'] = $stopped." ".$fedata['status']; } print ""; } print ""; } #Backends/Servers w/o clients print ""; print ""; print ""; print ""; foreach ($backends as $be => $bedata) { if ($bedata['status'] == "UP") { $statusicon = $in; $besess = $bedata['scur']." / ".$bedata['slim']; $bename = $bedata['pxname']; } else { $statusicon = $out; $besess = "".$bedata['status'].""; $bename = "".$bedata['pxname'].""; } $icondetails = " onmouseover=\"this.title='".$bedata['status']."'\""; print ""; print ""; print ""; print ""; print ""; foreach ($servers as $srv => $srvdata) { if ($srvdata['pxname'] == $bedata['pxname']) { if ($srvdata['status'] == "UP") { $nextaction = "stop"; $statusicon = $in; $acticon = $stop; $srvname = $srvdata['svname']; } elseif ($srvdata['status'] == "no check") { $nextaction = "stop"; $statusicon = $in; $acticon = $stop; $srvname = $srvdata['svname']; $srvdata['scur'] = "no check"; } elseif ($srvdata['status'] == "MAINT") { $nextaction = "start"; $statusicon = $out; $acticon = $start; $srvname = "".$srvdata['svname'].""; $srvdata['scur'] = "".$srvdata['status'].""; } else { $nextaction = "stop"; $statusicon = $out; $acticon = $stop; $srvname = "".$srvdata['svname'].""; $srvdata['scur'] = "".$srvdata['status'].""; } $icondetails = " onmouseover=\"this.title='".$srvdata['status']."'\""; print ""; print ""; print ""; print ""; if ($show_clients == "YES") { foreach ($clients as $cli => $clidata) { if ($clidata['be'] == $bedata['pxname'] && $clidata['srv'] == $srvdata['svname']) { print ""; if ($show_clients_traffic == "YES") { $clisessoutput=exec("/bin/echo 'show sess ".$clidata['sessid']."' | /usr/local/bin/socat unix-connect:/tmp/haproxy.socket stdio | /usr/bin/grep 'total=' | /usr/bin/awk '{print $5}'",$clidebug); $i=0; foreach($clidebug as $cliline) { $clibytes = explode("=", $cliline); if ($clibytes[1] >= 1024 and $clibytes[1] <= 1048576) { $clibytes = (int)($clibytes[1]/1024)."Kb"; } elseif ($clibytes[1] >= 1048576 and $clibytes[1] <= 10485760) { $clibytes = round(($clibytes[1]/1048576),2)."Mb"; } elseif ($clibytes[1] >= 10485760) { $clibytes = round(($clibytes[1]/1048576),1)."Mb"; } else { $clibytes = $clibytes[1]."B"; } $clientstraffic[$i] = $clibytes; $i++; } $clidebug=""; print ""; } else { print ""; } } } } } } } echo"
FrontEnd(s)
NameSessions
(cur/max)
Status
".$fedata['pxname']."".$fedata['scur']." / ".$fedata['slim']."
".$fedata['status']."
Backend(s)/Server(s)
Backend(s)
 Server(s)"; if ($show_clients == "YES") { print "
  Client(s) addr:port"; } print "
Sessions
(cur/max)
"; if ($show_clients == "YES" and $show_clients_traffic != "YES") { print "age/id"; } elseif ($show_clients == "YES" and $show_clients_traffic == "YES") { print "age/traffic i/o"; } print "
Status
/
Actions
".$bename."".$besess."
".$statusicon."
 
 ".$srvname."".$srvdata['scur']."
".$statusicon."
".$acticon."
  ".$clidata['src']." ".$log."".$clidata['age']." / ".$clientstraffic[0]." / ".$clientstraffic[1]."
".$clidata['age']." / ".$clidata['sessid']."
"; ?>