From a46f939b8886ad4cb4860b26016a7b5f0b1a7e8b Mon Sep 17 00:00:00 2001 From: PiBa-NL Date: Wed, 1 May 2013 23:54:17 +0200 Subject: haproxy-devel, add widget files.. --- config/haproxy-devel/haproxy.widget.inc | 10 ++ config/haproxy-devel/haproxy.widget.php | 224 ++++++++++++++++++++++++++++ config/haproxy-devel/haproxy_socketinfo.inc | 129 ++++++++++++++++ 3 files changed, 363 insertions(+) create mode 100644 config/haproxy-devel/haproxy.widget.inc create mode 100644 config/haproxy-devel/haproxy.widget.php create mode 100644 config/haproxy-devel/haproxy_socketinfo.inc (limited to 'config/haproxy-devel') diff --git a/config/haproxy-devel/haproxy.widget.inc b/config/haproxy-devel/haproxy.widget.inc new file mode 100644 index 00000000..72113e1c --- /dev/null +++ b/config/haproxy-devel/haproxy.widget.inc @@ -0,0 +1,10 @@ + + diff --git a/config/haproxy-devel/haproxy.widget.php b/config/haproxy-devel/haproxy.widget.php new file mode 100644 index 00000000..b084cc62 --- /dev/null +++ b/config/haproxy-devel/haproxy.widget.php @@ -0,0 +1,224 @@ +
"; +$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']."
"; +?> + + diff --git a/config/haproxy-devel/haproxy_socketinfo.inc b/config/haproxy-devel/haproxy_socketinfo.inc new file mode 100644 index 00000000..117e7334 --- /dev/null +++ b/config/haproxy-devel/haproxy_socketinfo.inc @@ -0,0 +1,129 @@ + $pxname, + "scur" => $scur, + "slim" => $slim, + "status" => $status); + break; + case "BACKEND": + $backends[] = array( + "pxname" => $pxname, + "scur" => $scur, + "slim" => $slim, + "status" => $status); + break; + default: + $servers[] = array( + "pxname" => $pxname, + "svname" => $svname, + "scur" => $scur, + "status" => $status); + } + } + $result['frontends'] = $frontends; + $result['backends'] = $backends; + $result['servers'] = $servers; + return $result; +} + +function haproxy_get_clients(){// "show sess" + $clients=array(); + $sessions = haproxy_socket_command("show sess"); + foreach($sessions as $line) { + list($sessid,$proto,$src,$fe,$be,$srv,$ts,$age,$calls,$rq,$rp,$s0,$s1,$exp) = explode(" ", $line); + #Retrieve data + $sessid = explode(":", $sessid); + $src = explode("=", $src); + $srcip = explode(":", $src[1]); + $srcport = explode(":", $src[1]); + $be = explode("=", $be); + $srv = explode("=", $srv); + $age = explode("=", $age); + $calls = explode("=", $calls); + $exp = explode("=", $exp); + $clients[] = array( + "sessid" => $sessid[0], + "src" => $src[1], + "srcip" => $srcip[0], + "srcport" => $srcport[1], + "be" => $be[1], + "srv" => $srv[1], + "age" => $age[1], + "calls" => $calls[1], + "exp" => $exp[1]); + } + return $clients; +} + +?> + -- cgit v1.2.3