LVS Web Monitor - script em php

Script para monitor e facilitar a visualização das estatísticas do cluster LVS Linux


Script php para monitorar cluster linux - LVS Web Monitor

O script trará as seguintes informações:


Necessário adicionar o usuário do apache no grupo wheel para executar os comandos via php.

Usermod -G whell apache

Para que o Visudo não reclame a falta de tty para executar os comandos adicionar ao /etc/sudoers

Defaults:apache !requiretty


Salvar o script como index.php no caminho do seu servidor web, ex.: /var/www/html/index.php



<?php
// Simple script to monitor LVS
// --liuk -at- linux.it
//
// extract vars...
$p1=0;
$p2=0;
if ( $_GET['resolve_dns']) $p1 = $_GET['resolve_dns'] ; else $p1=0;
if ( $_GET['refresh_int']) $p2 = $_GET['refresh_int'] ; else $p2=10;
if ( $p2 == "" || $p2 < 2) { $p2="2"; };
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html><head>
<meta http-equiv="refresh" content="<?php echo $p2; ?>">
<style type="text/css"><!--
body {background-color: #ffffff; color: #000000;}
body, td, th, h1, h2 {font-family: sans-serif;}
pre {margin: 0px; font-family: courier;}
a:link {color: #000099; text-decoration: none; background-color: #ffffff;}
a:hover {text-decoration: underline;}
table {border-collapse: collapse;}
.center {text-align: center;}
.center table { margin-left: auto; margin-right: auto; text-align: left;}
.center th { text-align: center !important; }
td, th { border: 1px solid #000000; font-size: 75%; vertical-align: baseline;}
h1 {font-size: 150%;}
h2 {font-size: 125%;}
.p {text-align: left;}
.e {background-color: #ccccff; font-weight: bold; color: #000000;}
.h {background-color: #9999cc; font-weight: bold; color: #000000;}
.v {background-color: #cccccc; color: #000000;}
.vv {background-color: #cccccc; color: #000000; font-family: courier; }
i {color: #666666; background-color: #cccccc;}
img {float: right; border: 0px;}
hr {width: 600px; background-color: #cccccc; border: 0px; height: 1px;
color: #000000;}
//--></style>
<title>LVS - Monitor</title></head>
<body><div class="center">
<table border="0" cellpadding="3" width="300">
<tr class="h"><td>
<h1 align="center">LVS - Web Monitor </h1>
</td></tr>
</table><br />

<table border="0" cellpadding="3" width="800">
<tr><td class="e">Monitor Options: </td>
<td class="v">
<form method="GET" action="">
<?php if(isset($resolve_dns)) { $curr_dns="$p1"; } else { $curr_dns="1"; }; ?>
<input type="checkbox" name="resolve_dns" value="<?php echo $curr_dns;?>"
<?php if($p1) { echo "checked=\"checked\""; } else { $dns_flag=" -n "; }; ?>
> Resolve DNS Names -
Refresh every
<input type="text" name="refresh_int" size="2" value="<?php echo $p2; ?>">
seconds -
<input type="submit" value="Update">
</form>
</td></tr>

<tr><td class="e">Active node: </td>
<td class="vv"><?php passthru("hostname"); ?></td></tr>

<tr><td class="e">Status: </td>
<td class="vv"><pre><?php $cmd="sudo /sbin/ipvsadm -L ".$dns_flag;
passthru($cmd); ?></pre></td></tr>

<tr><td class="e">Statistics: </td>
<td class="vv"><pre><?php $cmd="sudo /sbin/ipvsadm -L --stats
".$dns_flag; passthru($cmd); ?></pre></td></tr>

<tr><td class="e">Active<br>connections: </td>
<td class="vv"><pre><?php $cmd="sudo /sbin/ipvsadm -L -c ".$dns_flag;
passthru($cmd); ?></pre></td></tr>

<tr><td class="e">Rate<br>statistics: </td>
<td class="vv"><pre><?php $cmd="sudo /sbin/ipvsadm -L --rate ".$dns_flag;
passthru($cmd); ?></pre></td></tr>

<tr><td class="e">Sync<br>daemon: </td>
<td class="vv"><pre><?php passthru("sudo /sbin/ipvsadm -L --daemon");
?></pre></td></tr>

</table><br />

</div></body></html>






Comentários

Postagens mais visitadas