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 86c39fe195a2dd17fc862c52790b83424f546c23..fb8daf3aa583f8191e0d7b75dfd274849e5fba4b 100644 (file)
@@ -30,6 +30,7 @@
    <td>Index size</td>
    <td style="text-align: right">{{esStatus.size_human}}</td>
   </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>
   <tr>
    <td rowspan="3">Gearman</td>
    <td>Open tasks</td>
    <td>Task workers</td>
    <td style="text-align: right">{{gearStatus.workers}}</td>
   </tr>
    <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>
 
  </tbody>
 </table>
 
index 4d00ab806056d56e185007433a607a2c2ac4b5b6..5aac9b25d1200d7b99c4cf0b371f7474b29f8f97 100644 (file)
@@ -37,6 +37,28 @@ class Subscriptions
         return $stmt->fetchObject();
     }
 
         return $stmt->fetchObject();
     }
 
+    /**
+     * 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.
     /**
      * Create a new subscription entry in database.
      * Automatically generates secret, capkey and lease seconds.
index 4118c9cc19ab77b3cea2d9867a9e3df0849b337a..a57c121a2ae1d42bd9340a549dc2bd44c8ae1170 100644 (file)
@@ -8,6 +8,9 @@ $esStatus = $es->getIndexStatus();
 $queue = new Queue();
 $gearStatus = $queue->getServerStatus();
 
 $queue = new Queue();
 $gearStatus = $queue->getServerStatus();
 
+$subDb = new Subscriptions();
+$subCount = $subDb->count();
+
 /**
  * @link http://jeffreysambells.com/2012/10/25/human-readable-filesize-php
  */
 /**
  * @link http://jeffreysambells.com/2012/10/25/human-readable-filesize-php
  */
@@ -29,6 +32,8 @@ render(
     array(
         'esStatus'   => $esStatus,
         'gearStatus' => $gearStatus,
     array(
         'esStatus'   => $esStatus,
         'gearStatus' => $gearStatus,
+        'subCount'   => $subCount,
+        'subSum'     => array_sum($subCount),
     )
 );
 ?>
     )
 );
 ?>