Showing posts with label statistics. Show all posts
Showing posts with label statistics. Show all posts

Tuesday 9 April 2013

How to display multiple memcache servers statistics

To display multiple memcache servers statistics, you can run below php script.


<?php
$servers = array(
    array('127.0.0.1', 11211, 33),
    array('192.168.0.55', 11211, 67)
);

$memcache = new Memcache;
$memcache->addServer('192.168.0.23',11211);
$memcache->addServer('192.168.0.55',11211);
$return = $memcache->getExtendedStats();
$unique_key=array();
foreach ($return as $key => $value) {
    foreach ($value as $key2 => $value2) {       
        array_push($unique_key,$key2);
    }
}

$unique_key=array_unique($unique_key);   
echo "<table border='2' align=\"center\" width=\"100%\" >";
echo "<tr><th/>";
foreach ($return as $key => $value) {   
    echo "<th>$key</th>";   
}

echo "</tr>";
foreach ($unique_key as $key0) {   
    echo "<tr align=\"center\"><td>$key0</td>";   
    foreach ($return as $key => $value) {
        echo "<td>".$return[$key][$key0]."</td>";       
    }
    echo "</tr>";
}
echo "</table>";

?>

Monday 8 April 2013

How to display memcache statistics at bash shell

To display memcache statistics at command prompt, you can enter below command. This command will display memcache statistics like "top", updating the statistic every 2s.

watch "echo stats|nc 127.0.0.1 11211"

How to display memcache statistics with php

To display memcache statistics, you can create a php script as shown below. This scripts uses "getStats" command to display the statistics. You can also format it into a html table.

<?php
$memcache_host="127.0.0.1";
$memcache_port="11211";
$memcache = new Memcache;
$memcache->connect($memcache_host,$memcache_port) or die ("Cannot connect");
$return=($memcache->getStats());
foreach ($return as $key => $value) {
    echo $key." : ".$value."<br>";   
}
?>

search iomeweekly