show subscriptions on status page
authorChristian Weiske <cweiske@cweiske.de>
Thu, 24 Nov 2016 22:11:52 +0000 (23:11 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Thu, 24 Nov 2016 22:11:52 +0000 (23:11 +0100)
data/templates/status.htm
src/phinde/Subscriptions.php
www/status.php

index 86c39fe..fb8daf3 100644 (file)
@@ -30,6 +30,7 @@
    <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>Task workers</td>
    <td style="text-align: right">{{gearStatus.workers}}</td>
   </tr>
+
+  <tr>
+   <td rowspan="{{subCount|length + 1}}">Subscriptions</td>
+   <td>Total</td>
+   <td style="text-align: right">{{subSum}}</td>
+  </tr>
+  {% for key, number in subCount %}
+  <tr>
+   <td>{{key}}</td>
+   <td style="text-align: right">{{number}}</td>
+  </tr>
+  {% endfor %}
  </tbody>
 </table>
 
index 4d00ab8..5aac9b2 100644 (file)
@@ -38,6 +38,28 @@ class Subscriptions
     }
 
     /**
+     * Count number of subscriptions
+     *
+     * @return array Array of keys with different status, number as value
+     */
+    public function count()
+    {
+        $stmt = $this->db->prepare(
+            'SELECT COUNT(*) as count, sub_status FROM subscriptions'
+            . ' GROUP BY sub_status'
+            . ' ORDER BY sub_status'
+        );
+        $stmt->execute();
+
+        $res = [];
+        foreach ($stmt as $row) {
+            $res[$row['sub_status']] = $row['count'];
+        }
+
+        return $res;
+    }
+
+    /**
      * Create a new subscription entry in database.
      * Automatically generates secret, capkey and lease seconds.
      *
index 4118c9c..a57c121 100644 (file)
@@ -8,6 +8,9 @@ $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
  */
@@ -29,6 +32,8 @@ render(
     array(
         'esStatus'   => $esStatus,
         'gearStatus' => $gearStatus,
+        'subCount'   => $subCount,
+        'subSum'     => array_sum($subCount),
     )
 );
 ?>