[rhmessaging-commits] rhmessaging commits: r1469 - mgmt/cumin/python/cumin.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Wed Dec 12 14:26:04 EST 2007


Author: justi9
Date: 2007-12-12 14:26:03 -0500 (Wed, 12 Dec 2007)
New Revision: 1469

Modified:
   mgmt/cumin/python/cumin/client.py
   mgmt/cumin/python/cumin/model.py
Log:
A bunch of fixes to make clients work again, now that we have real
client data from the broker.

Adds client stat ui metadata.



Modified: mgmt/cumin/python/cumin/client.py
===================================================================
--- mgmt/cumin/python/cumin/client.py	2007-12-12 19:24:20 UTC (rev 1468)
+++ mgmt/cumin/python/cumin/client.py	2007-12-12 19:26:03 UTC (rev 1469)
@@ -51,13 +51,13 @@
     def render_item_produced(self, session, client):
         unit = self.unit.get(session)
         key = unit == "b" and "bytesProduced" or "msgsProduced"
-        value = getattr(client.mintClientStats, key)
+        value = self.app.model.client.get_stat(key).rate(client)
         return fmt_rate(value, unit == "b" and "byte" or "msg", "sec")
         
     def render_item_consumed(self, session, client):
         unit = self.unit.get(session)
         key = unit == "b" and "bytesConsumed" or "msgsConsumed"
-        value = getattr(client.mintClientStats, key)
+        value = self.app.model.client.get_stat(key).rate(client)
         return fmt_rate(value, unit == "b" and "byte" or "msg", "sec")
         
     def render_item_status(self, session, client):
@@ -80,20 +80,20 @@
 
 class ClientStatus(CuminStatus):
     def render_messages_produced(self, session, client):
-        value = client.mintClientStats.msgsProduced
-        return fmt_rate(value, "msg", "sec")
+        stat = self.app.model.client.get_stat("msgsProduced")
+        return fmt_rate(stat.rate(client), "msg", "sec")
         
     def render_messages_consumed(self, session, client):
-        value = client.mintClientStats.msgsConsumed
-        return fmt_rate(value, "msg", "sec")
+        stat = self.app.model.client.get_stat("msgsConsumed")
+        return fmt_rate(stat.rate(client), "msg", "sec")
 
     def render_bytes_produced(self, session, client):
-        value = client.mintClientStats.bytesProduced
-        return fmt_rate(value, "byte", "sec")
+        stat = self.app.model.client.get_stat("bytesProduced")
+        return fmt_rate(stat.rate(client), "byte", "sec")
         
     def render_bytes_consumed(self, session, client):
-        value = client.mintClientStats.bytesConsumed
-        return fmt_rate(value, "byte", "sec")
+        stat = self.app.model.client.get_stat("bytesConsumed")
+        return fmt_rate(stat.rate(client), "byte", "sec")
 
 class ClientView(Widget):
     def __init__(self, app, name):
@@ -165,24 +165,28 @@
 
 class ClientSessionSet(ItemSet):
     def get_title(self, session, client):
-        return "Sessions %s" % fmt_count(len(client.session_items()))
+        return "Sessions %s" % fmt_count(self.get_item_count(session, client))
 
+    def get_item_count(self, session, client):
+        return Session.select(Session.q.clientID == client.id).count()
+
     def do_get_items(self, session, client):
-        return sorted_by(client.session_items())
+        return Session.select(Session.q.clientID == client.id)
 
     def render_item_name(self, session, session_):
         return session_.name
 
     def render_item_remaining_lifespan(self, session, session_):
-        value = session_.mintSessionStats.remainingLifespan
-        return fmt_duration(value)
+        stat = self.app.model.session.get_stat("remainingLifespan")
+        return fmt_duration(stat.value(session_))
 
     def render_item_frames_outstanding(self, session, session_):
-        return session_.mintSessionStats.framesOutstanding
+        stat = self.app.model.session.get_stat("framesOutstanding")
+        return stat.value(session_)
 
     def render_item_attached(self, session, session_):
-        value = session_.mintSessionStats.attached
-        return fmt_predicate(value)
+        stat = self.app.model.session.get_stat("attached")
+        return fmt_predicate(stat.value(session_))
 
     def render_item_status(self, session, session_):
         return fmt_ostatus(session_)

Modified: mgmt/cumin/python/cumin/model.py
===================================================================
--- mgmt/cumin/python/cumin/model.py	2007-12-12 19:24:20 UTC (rev 1468)
+++ mgmt/cumin/python/cumin/model.py	2007-12-12 19:26:03 UTC (rev 1469)
@@ -12,6 +12,8 @@
         self.queue = CuminQueue(self)
         self.exchange = CuminExchange(self)
         self.binding = CuminBinding(self)
+        self.client = CuminClient(self)
+        self.session = CuminSession(self)
         
     def add_class(self, cls):
         self.classes[cls.mint_class] = cls
@@ -65,7 +67,10 @@
         self.cumin_class.add_stat(self)
 
     def value(self, object):
-        return nvl(getattr(object.statsCurr, self.name, -1), -1)
+        try:
+            return nvl(getattr(object.statsCurr, self.name), -1)
+        except AttributeError:
+            return -1
 
     def samples(self, object, limit=None):
         name = self.cumin_class.name
@@ -85,20 +90,23 @@
         return samples
 
     def rate(self, object):
-        if object.statsCurr:
-            curr = getattr(object.statsCurr, self.name)
+        try:
+            if object.statsCurr:
+                curr = getattr(object.statsCurr, self.name)
 
-            if object.statsPrev:
-                prev = getattr(object.statsPrev, self.name)
+                if object.statsPrev:
+                    prev = getattr(object.statsPrev, self.name)
 
-                if curr is not None and prev is not None:
-                    return (curr - prev) / float(1)
+                    if curr is not None and prev is not None:
+                        return (curr - prev) / float(1)
+                    else:
+                        return 0
                 else:
                     return 0
             else:
                 return 0
-        else:
-            return 0
+        except AttributeError:
+            return -1
 
     def write_xml(self, object, writer):
         writer.write("<stat name=\"%s\" value=\"%i\" rate=\"%i\"/>" \
@@ -339,3 +347,49 @@
         stat.title = "Msgs. Matched"
         stat.unit = "message"
         stat.categories = ("general")
+
+class CuminClient(CuminClass):
+    def __init__(self, model):
+        super(CuminClient, self).__init__(model, "client", Client)
+
+        self.mint_stats_class = ClientStats
+
+        stat = CuminStat(self, "bytesProduced", "int")
+        stat.title = "Bytes Produced"
+        stat.unit = "byte"
+        stat.categories = ("general")
+
+        stat = CuminStat(self, "bytesConsumed", "int")
+        stat.title = "Bytes Consumed"
+        stat.unit = "byte"
+        stat.categories = ("general")
+
+        stat = CuminStat(self, "msgsProduced", "int")
+        stat.title = "Msgs. Produced"
+        stat.unit = "message"
+        stat.categories = ("general")
+
+        stat = CuminStat(self, "msgsConsumed", "int")
+        stat.title = "Msgs. Produced"
+        stat.unit = "message"
+        stat.categories = ("general")
+
+class CuminSession(CuminClass):
+    def __init__(self, model):
+        super(CuminSession, self).__init__(model, "session", Session)
+
+        self.mint_stats_class = SessionStats
+
+        stat = CuminStat(self, "remainingLifespan", "int")
+        stat.title = "Remaining Lifespan"
+        stat.unit = "second"
+        stat.categories = ("general")
+
+        stat = CuminStat(self, "framesOutstanding", "int")
+        stat.title = "Frames Outstanding"
+        stat.unit = "frame"
+        stat.categories = ("general")
+
+        stat = CuminStat(self, "attached", "bool")
+        stat.title = "Attached"
+        stat.categories = ("general")




More information about the rhmessaging-commits mailing list