Example #1
0
 /** show databases **/
 public function doDatabases()
 {
     $ret = $this->_server->listDbs();
     $this->dbs = $ret["databases"];
     foreach ($this->dbs as $index => $db) {
         $mongodb = $this->_mongo->selectDB($db["name"]);
         $ret = $mongodb->command(array("dbstats" => 1));
         $ret["collections"] = count(MDb::listCollections($mongodb));
         if (isset($db["sizeOnDisk"])) {
             $ret["diskSize"] = r_human_bytes($db["sizeOnDisk"]);
             $ret["dataSize"] = r_human_bytes($ret["dataSize"]);
         } else {
             $ret["diskSize"] = "-";
             $ret["dataSize"] = "-";
         }
         $ret["storageSize"] = r_human_bytes($ret["storageSize"]);
         $ret["indexSize"] = r_human_bytes($ret["indexSize"]);
         $this->dbs[$index] = array_merge($this->dbs[$index], $ret);
     }
     $this->dbs = rock_array_sort($this->dbs, "name");
     $this->display();
 }
Example #2
0
 /** database **/
 public function doIndex()
 {
     $this->db = trim(xn("db"));
     $dbs = $this->_server->listDbs();
     $ret = array();
     foreach ($dbs["databases"] as $db) {
         if ($db["name"] == $this->db) {
             $ret = $db;
         }
     }
     //collections
     $db = $this->_mongo->selectDB($this->db);
     $collections = MDb::listCollections($db);
     $ret = array_merge($ret, $db->command(array("dbstats" => 1)));
     $ret["diskSize"] = "-";
     if (isset($ret["sizeOnDisk"])) {
         $ret["diskSize"] = r_human_bytes($ret["sizeOnDisk"]);
     }
     if (isset($ret["dataSize"])) {
         $ret["dataSize"] = r_human_bytes($ret["dataSize"]);
     }
     if (isset($ret["storageSize"])) {
         $ret["storageSize"] = r_human_bytes($ret["storageSize"]);
     }
     if (isset($ret["indexSize"])) {
         $ret["indexSize"] = r_human_bytes($ret["indexSize"]);
     }
     $this->stats = array();
     $this->stats["Size"] = $ret["diskSize"];
     $this->stats["Is Empty?"] = $ret["empty"] ? "Yes" : "No";
     if (empty($collections)) {
         $this->stats["Collections"] = count($collections) . " collections:";
         $this->stats["Collections"] .= "<br/>No collections yet";
     } else {
         $key = "Collections<br/>[<a href=\"" . $this->path("db.dropDbCollections", array("db" => $this->db)) . "\" onclick=\"return window.confirm('Are you sure to drop all collections in the db?')\"><u>Drop All</u></a>]<br/>[<a href=\"" . $this->path("clearDbCollections", array("db" => $this->db)) . "\" onclick=\"return window.confirm('Are you sure to clear all records in all collections?')\"><u>Clear All</u></a>]";
         $this->stats[$key] = count($collections) . " collections:";
         foreach ($collections as $collection) {
             $this->stats[$key] .= "<br/><a href=\"" . $this->path("collection.index", array("db" => $this->db, "collection" => $collection->getName())) . "\">" . $collection->getName() . "</a>";
         }
     }
     if (isset($ret["objects"])) {
         $this->stats["Objects"] = $ret["objects"];
     }
     if (isset($ret["avgObjSize"])) {
         $this->stats["Avg Object Size"] = r_human_bytes($ret["avgObjSize"]);
     }
     if (isset($ret["dataSize"])) {
         $this->stats["Data Size"] = $ret["dataSize"];
     }
     if (isset($ret["storageSize"])) {
         $this->stats["Storage Size"] = $ret["storageSize"];
     }
     if (isset($ret["numExtents"])) {
         $this->stats["Extents"] = $ret["numExtents"];
     }
     if (isset($ret["indexes"])) {
         $this->stats["Indexes"] = $ret["indexes"];
     }
     if (isset($ret["indexSize"])) {
         $this->stats["Index Size"] = r_human_bytes($ret["indexSize"]);
     }
     if (isset($ret["fileSize"])) {
         $this->stats["Total File Size"] = r_human_bytes($ret["fileSize"]);
     }
     if (isset($ret["nsSizeMB"])) {
         $this->stats["Namespace Size"] = $ret["nsSizeMB"] . "m";
     }
     if (isset($ret["dataFileVersion"])) {
         $this->stats["Data File Version"] = $this->_highlight($ret["dataFileVersion"], "json");
     }
     if (isset($ret["extentFreeList"])) {
         $this->stats["Extent Free List"] = $this->_highlight($ret["extentFreeList"], "json");
     }
     $this->display();
 }
Example #3
0
.stats()</td>
	</tr>
<?php 
foreach ($stats as $name => $stat) {
    ?>
	<tr bgcolor="#ffffff">
		<td width="150" bgcolor="#fffeee" valign="top"><?php 
    h($name);
    ?>
</td>
		<td><?php 
    if (is_array($stat)) {
        h("<xmp>" . var_export($stat, true) . "</xmp>");
    } else {
        if (in_array($name, array("size", "storageSize", "lastExtentSize", "totalIndexSize", "avgObjSize"))) {
            $stat = "<span title=\"{$stat}bytes\">" . r_human_bytes($stat) . "</span>";
        }
        h($stat);
    }
    ?>
</td>
	</tr>
<?php 
}
if (!empty($top)) {
    ?>
 	<tr bgcolor="#cfffff">
		<td colspan="2">{top:1}</td>
	</tr>
	<?php 
    foreach ($top as $name => $stat) {