[rhmessaging-commits] rhmessaging commits: r3974 - in mgmt/newdata: mint/python/mint and 1 other directory.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Mon May 17 14:25:44 EDT 2010


Author: justi9
Date: 2010-05-17 14:25:44 -0400 (Mon, 17 May 2010)
New Revision: 3974

Modified:
   mgmt/newdata/cumin/bin/cumin-data
   mgmt/newdata/mint/python/mint/tools.py
   mgmt/newdata/mint/python/mint/update.py
   mgmt/newdata/mint/python/mint/util.py
Log:
Bring back mint stat reporting

Modified: mgmt/newdata/cumin/bin/cumin-data
===================================================================
--- mgmt/newdata/cumin/bin/cumin-data	2010-05-17 18:17:45 UTC (rev 3973)
+++ mgmt/newdata/cumin/bin/cumin-data	2010-05-17 18:25:44 UTC (rev 3974)
@@ -15,6 +15,7 @@
     values = config.parse()
 
     parser = CuminOptionParser(values.data)
+    parser.add_option("--print-stats", action="store_true")
 
     opts, args = parser.parse_args()
 
@@ -33,10 +34,24 @@
     mint.start()
 
     try:
-        while True:
-            # print_threads()
+        stats = mint.update_thread.stats
+        count = 0
 
-            sleep(5)
+        if opts.print_stats:
+            print "[Reported values are the number of events per second]"
+
+            while True:
+                if count % 24 == 0:
+                    stats.print_headings()
+
+                count += 1
+
+                stats.print_rates()
+
+                sleep(5)
+        else:
+            while True:
+                sleep(86400)
     finally:
         mint.stop()
 

Modified: mgmt/newdata/mint/python/mint/tools.py
===================================================================
--- mgmt/newdata/mint/python/mint/tools.py	2010-05-17 18:17:45 UTC (rev 3973)
+++ mgmt/newdata/mint/python/mint/tools.py	2010-05-17 18:25:44 UTC (rev 3974)
@@ -325,185 +325,3 @@
             subject.syncUpdate()
 
             print "Password of user '%s' is changed" % subject.name
-
-class MintServerTool(BaseMintTool):
-    def __init__(self, name):
-        super(MintServerTool, self).__init__(name)
-
-    def init(self):
-        super(MintServerTool, self).init()
-
-        # get better thread switching performance
-        sys.setcheckinterval(200)
-
-    def do_run(self, opts, args):
-        app = Mint(self.config)
-
-        app.check()
-        app.init()
-        app.start()
-
-        try:
-            for arg in args[1:]:
-                app.model.add_broker(arg)
-
-            while True:
-                sleep(2)
-        finally:
-            app.stop()
-
-class MintTestTool(BaseMintTool):
-    def __init__(self, name):
-        super(MintTestTool, self).__init__(name)
-
-    def do_run(self, opts, args):
-        app = Mint(self.config)
-
-        app.check()
-        app.init()
-        app.start()
-
-        try:
-            for arg in args[1:]:
-                app.model.add_broker(arg)
-
-            sleep(2)
-
-            cls = app.model.org_apache_qpid_broker.Broker
-
-            conn = app.database.get_connection()
-            cursor = conn.cursor()
-
-            for obj in cls.get_selection(cursor):
-                try:
-                    agent = app.model.agents[obj._qmf_agent_id]
-                except KeyError:
-                    continue
-
-                break
-
-            print "TTT", obj.port, obj, agent
-
-            def completion(status_code, output_args):
-                print "YYY", status_code, output_args
-
-            agent.call_method(completion, obj, "echo", 1, "ggoo!")
-
-            while True:
-                sleep(2)
-        finally:
-            app.stop()
-
-class MintBenchTool(BaseMintTool):
-    def __init__(self, name):
-        super(MintBenchTool, self).__init__(name)
-
-    def init(self):
-        super(MintBenchTool, self).init()
-
-        # get better thread switching performance
-        sys.setcheckinterval(200)
-
-    def do_run(self, opts, args):
-        app = Mint(self.config)
-
-        app.check()
-        app.init()
-        app.start()
-
-        head = "%8s %8s %8s %8s %8s %8s %8s %8s %8s" % \
-            ("enqs", "deqs", "depth", "update", "delete", "drop",
-             "s.update", "s.expire", "s.drop")
-        row = "%8i %8i %8i %8i %8i %8i %8i %8i %8i"
-
-        try:
-            for arg in args[1:]:
-                try:
-                    app.model.add_broker(arg)
-                except socket.error, e:
-                    print "Warning: Failed connecting to broker at '%s'" % arg
-
-            try:
-                enq = 0
-                deq = 0
-
-                upd = 0
-                dlt = 0
-                drp = 0
-
-                supd = 0
-                sexp = 0
-                sdrp = 0
-
-                enq_last = 0
-                deq_last = 0
-
-                upd_last = 0
-                dlt_last = 0
-                drp_last = 0
-
-                supd_last = 0
-                sexp_last = 0
-                sdrp_last = 0
-
-                samples = 0
-
-                while True:
-                    if samples % 24 == 0:
-                        print head
-
-                    samples += 1
-
-                    sleep(1)
-
-                    stats = app.update_thread.stats
-
-                    enq = stats.enqueued
-                    deq = stats.dequeued
-
-                    upd = stats.updated
-                    dlt = stats.deleted
-                    drp = stats.dropped
-
-                    supd = stats.samples_updated
-                    sexp = stats.samples_expired
-                    sdrp = stats.samples_dropped
-
-                    print row % (enq - enq_last,
-                                 deq - deq_last,
-                                 enq - deq,
-                                 upd - upd_last,
-                                 dlt - dlt_last,
-                                 drp - drp_last,
-                                 supd - supd_last,
-                                 sexp - sexp_last,
-                                 sdrp - sdrp_last)
-
-                    enq_last = enq
-                    deq_last = deq
-
-                    upd_last = upd
-                    dlt_last = dlt
-                    drp_last = drp
-
-                    supd_last = supd
-                    sexp_last = sexp
-                    sdrp_last = sdrp
-            finally:
-                print "Totals:"
-
-                print row % (enq,
-                             deq,
-                             enq - deq,
-                             upd,
-                             dlt,
-                             drp,
-                             supd,
-                             sexp,
-                             sdrp)
-        finally:
-            #from threading import enumerate
-            #for item in enumerate():
-            #    print item
-
-            app.stop()

Modified: mgmt/newdata/mint/python/mint/update.py
===================================================================
--- mgmt/newdata/mint/python/mint/update.py	2010-05-17 18:17:45 UTC (rev 3973)
+++ mgmt/newdata/mint/python/mint/update.py	2010-05-17 18:25:44 UTC (rev 3974)
@@ -1,3 +1,4 @@
+import copy
 import pickle
 
 from psycopg2 import IntegrityError, TimestampFromTicks
@@ -51,6 +52,13 @@
             update.process(self.conn, self.stats)
 
 class UpdateStats(object):
+    names = ("Enqueued", "Dequeued", "Updated", "Deleted", "Dropped")
+    headings = ("%8s  " * 5) % names
+    rates_fmt = "%8.1f  " * 5
+
+    then = None
+    now = None
+
     def __init__(self):
         self.enqueued = 0
         self.dequeued = 0
@@ -63,6 +71,36 @@
         self.samples_expired = 0
         self.samples_dropped = 0
 
+        self.time = None
+
+    def capture(self):
+        now = copy.copy(self)
+        now.time = time.time()
+
+        UpdateStats.then = UpdateStats.now
+        UpdateStats.now = now
+
+    def print_headings(self):
+        print self.headings
+
+    def print_rates(self):
+        self.capture()
+
+        if not self.then:
+            return
+
+        values = (self.now.enqueued - self.then.enqueued,
+                  self.now.dequeued - self.then.dequeued,
+                  self.now.updated - self.then.updated,
+                  self.now.deleted - self.then.deleted,
+                  self.now.dropped - self.then.dropped)
+
+        secs = self.now.time - self.then.time
+
+        rates = tuple(map(lambda x: x / secs, values))
+
+        print self.rates_fmt % rates
+        
 class Update(object):
     def __init__(self, model):
         self.model = model

Modified: mgmt/newdata/mint/python/mint/util.py
===================================================================
--- mgmt/newdata/mint/python/mint/util.py	2010-05-17 18:17:45 UTC (rev 3973)
+++ mgmt/newdata/mint/python/mint/util.py	2010-05-17 18:25:44 UTC (rev 3974)
@@ -2,6 +2,7 @@
 import os
 import random
 import sys
+import time
 
 from Queue import Queue as ConcurrentQueue, Full, Empty
 from crypt import crypt



More information about the rhmessaging-commits mailing list