[icinga-checkins] icinga.org: icingaweb2-module-director/feature-ddo-playground: EventstreamCommand: count and report total events

git at icinga.org git at icinga.org
Tue Jul 19 10:31:53 CEST 2016


Module: icingaweb2-module-director
Branch: feature-ddo-playground
Commit: 485fd560acb5c4e7332ea288332c43f6e0cc75d4
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=485fd560acb5c4e7332ea288332c43f6e0cc75d4

Author: Thomas Gelf <thomas at gelf.net>
Date:   Sat Jun 25 09:00:16 2016 +0200

EventstreamCommand: count and report total events

---

 application/clicommands/EventstreamCommand.php |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/application/clicommands/EventstreamCommand.php b/application/clicommands/EventstreamCommand.php
index d9d23dd..659e2e5 100644
--- a/application/clicommands/EventstreamCommand.php
+++ b/application/clicommands/EventstreamCommand.php
@@ -36,6 +36,7 @@ class EventstreamCommand extends DdoCommand
         $redis = Redis::instance();
         $time = time();
         $cnt = 0;
+        $cntEvents = 0;
         $hasTransaction = false;
         $ddo = $this->ddo();
         $db = $ddo->getDbAdapter();
@@ -45,13 +46,14 @@ class EventstreamCommand extends DdoCommand
         while (true) {
 
             while ($res = $redis->brpop('icinga2::events', 1)) {
+                $cntEvents++;
                 // res = array(queuename, value)
                 $object = $list->processCheckResult(json_decode($res[1]));
                 if ($object === false) {
                     continue;
                 }
 
-                if ($object->hasBeenModified()) {
+                if ($object->hasBeenModified() && $object->state !== null) {
                     printf("%s has been modified\n", $object->getUniqueName());
 
                     if (! $hasTransaction) {
@@ -68,8 +70,9 @@ class EventstreamCommand extends DdoCommand
                     || ($cnt > 0 && (($newtime = time()) - $time > 1))
                 ) {
                     $time = $newtime;
-                    echo "Committing $cnt events\n";
+                    echo "Committing $cnt events ($cntEvents total)\n";
                     $cnt = 0;
+                    $cntEvents = 0;
                     $db->commit();
                     $hasTransaction = false;
                 }
@@ -79,8 +82,9 @@ class EventstreamCommand extends DdoCommand
 
             if ($cnt > 0) {
                 $time = time();
-                echo "Committing $cnt events\n";
+                echo "Committing $cnt events ($cntEvents total)\n";
                 $cnt = 0;
+                $cntEvents = 0;
                 $db->commit();
                 $hasTransaction = false;
             }



More information about the icinga-checkins mailing list