Main PHP program ( mm.php ) :-
[root@MyLabBox v8]# pwd
/var/www/html/mongo/v8
[root@MyLabBox v8]# cat mm.php
<?php
#############################################################
#############################################################
header('Refresh:120');
include("mm_data.php");
$data_cfg_file = "datanode.cfg";
$fd = fopen($data_cfg_file, 'r');
$node=fgets($fd);
$count=1;
echo " <tr>";
while ( $node != "")
{
$out = shell_exec("/var/www/html/mongo/rs.sh ".$node);
$outPrimary = shell_exec("/var/www/html/mongo/getPrimary.sh ".$node);
if ($out == 1)
{
if($outPrimary==0)
{
echo " <td style=\"text-align: center; font-size:18px;\" bgcolor=\"#00FF00\">";
echo " $node <b> (S) </b></td>";
}
else
{
echo " <td style=\"text-align: center; font-size:18px;\" bgcolor=\"#088A08\">";
echo " $node<b> (P) </b></td>";
}
}
else {
echo " <td style=\"text-align: center; font-size:18px;\" bgcolor=\"#ff0000\">";
echo " <span style=\"color:#ffffff;\">$node</span></td>";
}
echo " <td></td>";
echo " <td></td>";
$count = $count + 1;
if ($count == 17) {
echo " </tr>";
echo " <tr>";
}
$node=fgets($fd);
}
echo " </tr>";
fclose($fd);
echo " </tbody>";
echo "</table>";
echo " </tbody>";
echo "</table>";
include("mm_config.php");
function ping($host,$port=80,$timeout=6)
{
$fsock = fsockopen($host, $port, $errno, $errstr, $timeout);
if ( ! $fsock )
{
return FALSE;
}
else
{
return TRUE;
}
}
$config_cfg_file = "config.cfg";
$fc = fopen($config_cfg_file, 'r');
$config=fgets($fc);
while ( $config != "")
{
$out = ping("$config",29010,5);
if ($out == TRUE) {
echo " <td style=\"text-align: center; font-size:22px;\" bgcolor=\"#33cc33\">";
echo " $config</td>";
} else {
echo " <td style=\"text-align: center; font-size:22px;\" bgcolor=\"#ff0000\">";
echo " <span style=\"color:#ffffff;\">$config</span></td>";
}
echo " <td></td>";
echo " <td></td>";
$config=fgets($fc);
}
fclose($fc);
echo "</tr></tr></table></table>";
echo "<hr />";
include("mm_router.php");
$router_cfg_file = "routers.cfg";
$fr = fopen($router_cfg_file, 'r');
$router=fgets($fr);
$var=0;
while ( $router != "")
{$var++;
$out = ping("$router",10000,8);
if ($out == TRUE) {
if($var==13)echo "<tr></tr><tr></tr>";
echo " <td style=\"text-align: center; font-size:20px;\" bgcolor=\"#33cc33\">";
echo " <font style=\"text-align: center; font-size:20px; color:black\"><b>Router$var</b></font><br/>$router</td>";
} else {
echo " <td style=\"text-align: center; font-size:20px;\" bgcolor=\"#ff0000\">";
echo " <span style=\"color:#ffffff;\"><font style=\"text-align: center; font-size:20px; color:black\"><b>Router$var</b></font><br/>$router</span></td>";
}
echo " <td></td>";
echo " <td></td>";
$router=fgets($fr);
}
fclose($fr);
echo "</tr></tr></table></table>";
include("solrenroll.php");
echo "<p style=\"text-align: center; color: white\">";
echo " Last updated : <span style=\"color:#ff9933; font-size:20px;\">".date("d-M-Y H:i:s", time())."</span></p>";
echo "</body>";
echo "</html>";
?>
[root@MyLabBox v8]#
To check & get the Primary node ( getPrimary.sh ) :-
[root@MyLabBox v8]# cat getPrimary.sh
#!/bin/sh
#############################################################
#############################################################
server=$1
value=`./bin/mongo $server:27010/uid_db --eval 'printjson(db.isMaster())' | grep ismaster | cut -d':' -f2 | awk '{$0=substr($0,1,length($0)-1); print $0}'`
if [ $value = 'true' ]
then
echo "1"
else
echo "0"
fi
[root@MyLabBox v8]#
Data Nodes config file where we need to put all our IP addresses ( datanode.cfg ) :-
[root@MyLabBox v8]# cat datanode.cfg
xx.xx.xx.xx
xx.xx.xx.x
xx.xx.xx.xx
xx.xx.xx.x
xx.xx.xx.xx
xx.xx.xx.xx
xx.xx.xx.x
xx.xx.xx.x
xx.xx.xx.x
[root@MyLabBox v8]#
To check & get the Replica set status ( rs.sh ) :-
[root@MyLabBox v8]# cat rs.sh
#!/bin/sh
#############################################################
#############################################################
server=$1
./bin/mongo ${server}:27010/uid_db --eval "printjson(rs.status())" | tac | grep -A 1 "^}" | grep ok | cut -d':' -f2 | bc
[root@MyLabBox v8]#
Other required PHPs & cfgs :-
[root@MyLabBox v8]# cat mm_router.php mm_data.php routers.cfg solrenroll.php
<html>
<head>
<title>Mongo Monitoring</title>
<meta http-equiv="refresh" content="300" >
</head>
<body bgcolor="#2E2E2E">
<table align="center" border="0" cellpadding="1" cellspacing="1" style="width: 100%; height: 70px;">
<tbody>
<tr>
<td>
<table align="center" border="0" cellpadding="1" cellspacing="1" style="width: 60%; height: 80px;">
<tbody>
</tr>
</tbody>
</table>
</tr>
</tbody>
</table>
<p style="text-align: center; color:white;">
<span style="font-size:35px;"><u><b>Demographic Service Monitoring</b></u></span></span></p>
<hr />
<table align="center" border="0" cellpadding="1" cellspacing="1" style="width: 100%; height: 170px;">
<tbody>
<tr>
<td style="text-align: left; font-size:26px; color:white; width: 100px;">Shards : </td>
<td>
<table align="center" border="0" cellpadding="1" cellspacing="1" style="width: 80%; height: 170px;">
<tbody>
<tr>
<td style="text-align: center; font-size:22px; color:#40e0d0;">Shard 1</td>
<td></td>
<td></td>
<td style="text-align: center; font-size:22px; color:#40e0d0;">Shard 2</td>
<td></td>
<td></td>
<td style="text-align: center; font-size:22px; color:#40e0d0;">Shard 3</td>
<td></td>
<td></td>
<td style="text-align: center; font-size:22px; color:#40e0d0;">Shard 4</td>
<td></td>
<td></td>
<td style="text-align: center; font-size:22px; color:#40e0d0;">Shard 5</td>
<td></td>
<td></td>
<td style="text-align: center; font-size:22px; color:#40e0d0;">Shard 6</td>
<td></td>
<td></td>
<td style="text-align: center; font-size:22px; color:#40e0d0;">Shard 7</td>
<td></td>
<td></td>
<td style="text-align: center; font-size:22px; color:#40e0d0;">Shard 8</td>
<td></td>
<td></td>
<td style="text-align: center; font-size:22px; color:#40e0d0;">Shard 9</td>
<td></td>
<td></td>
<td style="text-align: center; font-size:22px; color:#40e0d0;">Shard 10</td>
<td></td>
<td></td>
<td style="text-align: center; font-size:22px; color:#40e0d0;">Shard 11</td>
<td></td>
<td></td>
<td style="text-align: center; font-size:22px; color:#40e0d0;">Shard 12</td>
<td></td>
<td></td>
<td style="text-align: center; font-size:22px; color:#40e0d0;">Shard 13</td>
<td></td>
<td></td>
<td style="text-align: center; font-size:22px; color:#40e0d0;">Shard 14</td>
<td></td>
<td></td>
<td style="text-align: center; font-size:22px; color:#40e0d0;">Shard 15</td>
<td></td>
<td></td>
<td style="text-align: center; font-size:22px; color:#40e0d0;">Shard 16</td>
<td></td>
</tr>
xx.xx.xx.xx
xx.xx.xx.xx
xx.xx.xx.xx
<?php
#header('Refresh:120');
echo "<hr/>";
$servers=array("DC1EnrSOLRN1","DC1EnrSOLRN2","DC1EnrSOLRN3","DC1EnrSOLRN4","DC1EnrSOLRN5","DC1EnrSOLRN6","DC1EnrSOLRN7","DC1EnrSOLRN8","DC1EnrSOLRN10","DC1EnrSOLRN11","DC1EnrSOLRN12","DC1EnrSOLRN13","DC1EnrSOLRN14","DC1EnrSOLRN15","DC1EnrSOLRN16");
$serverStatus = "<body bgcolor='#2E2E2E'><center><br><b><font color ='#40E0D0'>Solr Search Services : </font></b><br><table border='0' cellpadding='2' cellSpacing='2'><tr>";
$count=0;
foreach($servers as $server)
{
# Determine Port Status.
$status = @fsockopen($server, "9090", $errno, $errstr, 5);
$count++;
# echo $count;
# What is the result.
if( !$status )
{
if($count==9) #echo "<tr></tr><tr></tr>";
$statusText="<tr></tr><tr></tr><td height='30' width='80' align='center' bgcolor='#FF6A00' style='text-decoration:blink'><b>$server</b></td>";
else
$statusText="<td height='30' width='80' align='center' bgcolor='#FF6A00' style='text-decoration:blink'><b>$server</b></td>";
#$statusText = "Down";
}
else
{
if($count==9)#echo "<tr></tr><tr></tr>";
$statusText="<tr></tr><tr></tr><td height='30' width='80' align='center' bgcolor='#00FF00'><b>$server</b></td>";
else
$statusText="<td height='30' width='80' align='center' bgcolor='#00FF00'><b>$server</b></td>";
#$statusText = "Up";
}
# Set the status Row.
$serverStatus .= "{$statusText}";
}
$serverStatus .= "</tr></table>";
# Finish service status table.
//$serverStatus .= "</table>";
$servers=array("xx.xx.xx.162","xx.xx.xx.225","xx.xx.xx.229","xx.xx.xx.116","xx.xx.xx.119");
#$serverStatus .= "<br>";
$serverStatus .= "<br><b><font color ='#40E0D0'>Enroll Search Services : </font></b><br><table border='0' cellpadding='10' cellSpacing='15'><tr>";
foreach($servers as $server)
{
#$serverStatus .= "<b><font color ='#40E0D0'>Enroll Search Services : </font></b><br><hr><table border='0' cellpadding='10' cellSpacing='15'><tr>";
if($server=="xx.xx.xx.116"||$server=="xx.xx.xx.119")
$status = @fsockopen($server, "8010", $errno, $errstr, 5);
else
$status = @fsockopen($server, "8080", $errno, $errstr, 5);
//echo $status;
# What is the result.
if( !$status )
{
$statusText="<td align='center' bgcolor='#FF6A00' style='text-decoration:blink'><b>[T]: $server</b></td>";
#$statusText = "Down";
}
else
{
$statusText="<td align='center' bgcolor='#00FF00'><b>[T]: $server</b></td>";
#$statusText = "Up";
}
# Set the status Row.
$serverStatus .= "{$statusText}";
}
$servers=array("xx.xx.xx.225");
#$serverStatus .= "<br>";
#$serverStatus .= "<br><b><font color ='#40E0D0'>Enroll Search Services : </font></b><br><hr><table border='0' cellpadding='10' cellSpacing='15'><tr>";
foreach($servers as $server)
{
#$serverStatus .= "<b><font color ='#40E0D0'>Enroll Search Services : </font></b><br><hr><table border='0' cellpadding='10' cellSpacing='15'><tr>";
$status = @fsockopen($server, "11001", $errno, $errstr, 5);
//echo $status;
# What is the result.
if( !$status )
{
$statusText="<td align='center' bgcolor='#FF6A00' style='text-decoration:blink'><b>A: $server</b></td>";
#$statusText = "Down";
}
else
{
$statusText="<td align='center' bgcolor='#00FF00'><b>[A]: $server</b></td>";
#$statusText = "Up";
}
# Set the status Row.
$serverStatus .= "{$statusText}";
}
$serverStatus .= "</tr></table></center></body>";
# File Complete.
echo $serverStatus;
?>
[root@MyLabBox v8]#
Ask Question