add log file support
[phinde.git] / www / status.php
index 3bc52cf832a4385957e7e485bf82d9c0237b4234..a57c121a2ae1d42bd9340a549dc2bd44c8ae1170 100644 (file)
@@ -3,16 +3,37 @@ namespace phinde;
 require 'www-header.php';
 
 $es = new Elasticsearch($GLOBALS['phinde']['elasticsearch']);
-$esDocs = $es->countDocuments();
+$esStatus = $es->getIndexStatus();
 
 $queue = new Queue();
 $gearStatus = $queue->getServerStatus();
 
+$subDb = new Subscriptions();
+$subCount = $subDb->count();
+
+/**
+ * @link http://jeffreysambells.com/2012/10/25/human-readable-filesize-php
+ */
+function human_filesize($bytes, $decimals = 2)
+{
+    $size = array('B','kiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB');
+    $factor = floor((strlen($bytes) - 1) / 3);
+    return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor))
+        . ' ' . @$size[$factor];
+}
+
+$esStatus['size_human']      = human_filesize($esStatus['size']);
+$esStatus['documents_human'] = number_format(
+    $esStatus['documents'], 0, '.', ' '
+);
+
 render(
     'status',
     array(
-        'esDocs' => $esDocs,
+        'esStatus'   => $esStatus,
         'gearStatus' => $gearStatus,
+        'subCount'   => $subCount,
+        'subSum'     => array_sum($subCount),
     )
 );
 ?>