improve status page
authorChristian Weiske <cweiske@cweiske.de>
Fri, 11 Nov 2016 20:13:56 +0000 (21:13 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 11 Nov 2016 20:13:56 +0000 (21:13 +0100)
data/templates/status.htm
src/phinde/Elasticsearch.php
www/status.php

index a5699ef..79e875e 100644 (file)
 <table class="table table-striped">
  <thead>
   <tr>
+   <th>Group</th>
    <th>Item</th>
-   <th>Number</th>
+   <th style="text-align: right">Number</th>
   </tr>
  </thead>
  <tbody>
   <tr>
-   <td>Elasticsearch documents</td>
-   <td>{{esDocs}}</td>
+   <td rowspan="2">Elasticsearch</td>
+   <td>Documents</td>
+   <td style="text-align: right">{{esStatus.documents}}</td>
   </tr>
   <tr>
+   <td>Index size</td>
+   <td style="text-align: right">{{esStatus.size_human}}</td>
+  </tr>
+  <tr>
+   <td rowspan="3">Gearman</td>
    <td>Open tasks</td>
-   <td>{{gearStatus.tasks}}</td>
+   <td style="text-align: right">{{gearStatus.tasks}}</td>
   </tr>
   <tr>
    <td>Tasks being processed</td>
-   <td>{{gearStatus.processing}}</td>
+   <td style="text-align: right">{{gearStatus.processing}}</td>
   </tr>
   <tr>
    <td>Task workers</td>
-   <td>{{gearStatus.workers}}</td>
+   <td style="text-align: right">{{gearStatus.workers}}</td>
   </tr>
  </tbody>
 </table>
index 069cf1f..6c90480 100644 (file)
@@ -58,14 +58,18 @@ class Elasticsearch
         $r->send();
     }
 
-    public function countDocuments()
+    public function getIndexStatus()
     {
         $r = new Elasticsearch_Request(
-            $this->baseUrl . 'document/_count',
+            $this->baseUrl . '_stats/docs,store',
             \HTTP_Request2::METHOD_GET
         );
         $res = $r->send();
-        return json_decode($res->getBody())->count;
+        $data = json_decode($res->getBody());
+        return array(
+            'documents' => $data->_all->total->docs->count,
+            'size'      => $data->_all->total->store->size_in_bytes,
+        );
     }
 
     public function search($query, $filters, $site, $page, $perPage, $sort)
index 3bc52cf..08e2a0d 100644 (file)
@@ -3,15 +3,28 @@ namespace phinde;
 require 'www-header.php';
 
 $es = new Elasticsearch($GLOBALS['phinde']['elasticsearch']);
-$esDocs = $es->countDocuments();
+$esStatus = $es->getIndexStatus();
 
 $queue = new Queue();
 $gearStatus = $queue->getServerStatus();
 
+/**
+ * @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']);
+
 render(
     'status',
     array(
-        'esDocs' => $esDocs,
+        'esStatus'   => $esStatus,
         'gearStatus' => $gearStatus,
     )
 );