[rhmessaging-commits] rhmessaging commits: r1530 - mgmt/cumin/python/cumin.
rhmessaging-commits at lists.jboss.org
rhmessaging-commits at lists.jboss.org
Thu Jan 3 08:08:02 EST 2008
Author: justi9
Date: 2008-01-03 08:08:02 -0500 (Thu, 03 Jan 2008)
New Revision: 1530
Modified:
mgmt/cumin/python/cumin/charts.py
mgmt/cumin/python/cumin/client.py
mgmt/cumin/python/cumin/model.py
mgmt/cumin/python/cumin/queue.py
mgmt/cumin/python/cumin/util.py
mgmt/cumin/python/cumin/widgets.py
Log:
Avoid extra queries in chart generation.
Fix chart display.
Make stat.samples return values over a time range.
Render the "" named exchange as "Default" in the queue binding list.
Protect calc_rate from null values.
Modified: mgmt/cumin/python/cumin/charts.py
===================================================================
--- mgmt/cumin/python/cumin/charts.py 2008-01-02 16:43:50 UTC (rev 1529)
+++ mgmt/cumin/python/cumin/charts.py 2008-01-03 13:08:02 UTC (rev 1530)
@@ -1,8 +1,9 @@
from cairo import *
from random import random
-from time import mktime, time
+from time import time
from formats import *
+from util import *
class LineChart(object):
def __init__(self, width, height):
@@ -25,12 +26,12 @@
tzero = time()
- for datetime, value in samples:
+ for dt, value in samples:
if value is None:
print "Warning: unexpected null value" #XXX
value = 0
- t = mktime(datetime.timetuple())
+ t = secs(dt)
x = self.width + (t - tzero)
y = self.height - (value / float(self.max_value)) * self.height
cr.line_to(x, y)
Modified: mgmt/cumin/python/cumin/client.py
===================================================================
--- mgmt/cumin/python/cumin/client.py 2008-01-02 16:43:50 UTC (rev 1529)
+++ mgmt/cumin/python/cumin/client.py 2008-01-03 13:08:02 UTC (rev 1530)
@@ -296,7 +296,7 @@
return "Expires"
def do_render(self, session, data):
- return "<td>%s</td>" % fmt_datetime(data[self.name])
+ return "<td>%s</td>" % data[self.name]
class StatusColumn(ItemTableColumn):
def get_title(self, session, object):
Modified: mgmt/cumin/python/cumin/model.py
===================================================================
--- mgmt/cumin/python/cumin/model.py 2008-01-02 16:43:50 UTC (rev 1529)
+++ mgmt/cumin/python/cumin/model.py 2008-01-03 13:08:02 UTC (rev 1530)
@@ -1,6 +1,7 @@
from mint import *
from wooly import *
from time import mktime
+from datetime import datetime, timedelta
from util import *
from formats import *
@@ -81,13 +82,18 @@
self.cumin_class.add_stat(self)
- def samples(self, object, limit=None):
- stats = object.stats[:limit]
+ def samples(self, object, secs=600):
+ stats = object.stats
+
+ col = self.cumin_class.mint_stats_class.q.recTime
+ dt = datetime.now() - timedelta(seconds=secs)
+ stats = stats.filter(col > dt)
+
stats = stats.orderBy("-recTime")
samples = list()
- for stat in object.stats[:limit]:
+ for stat in stats:
value = getattr(stat, self.name, 0)
samples.append((stat.recTime, value))
Modified: mgmt/cumin/python/cumin/queue.py
===================================================================
--- mgmt/cumin/python/cumin/queue.py 2008-01-02 16:43:50 UTC (rev 1529)
+++ mgmt/cumin/python/cumin/queue.py 2008-01-03 13:08:02 UTC (rev 1530)
@@ -304,7 +304,7 @@
return branch.marshal()
def render_item_name(self, session, binding):
- return binding.exchange.name
+ return binding.exchange.name or "<em>Default</em>"
class QueueForm(CuminForm):
def __init__(self, app, name):
Modified: mgmt/cumin/python/cumin/util.py
===================================================================
--- mgmt/cumin/python/cumin/util.py 2008-01-02 16:43:50 UTC (rev 1529)
+++ mgmt/cumin/python/cumin/util.py 2008-01-03 13:08:02 UTC (rev 1530)
@@ -13,10 +13,12 @@
return expr1
def calc_rate(curr, prev, csecs, psecs):
- return (curr - prev) / float(csecs - psecs)
+ if None not in (curr, prev, csecs, psecs):
+ return (curr - prev) / float(csecs - psecs)
def secs(dt):
- return mktime(dt.timetuple())
+ if dt is not None:
+ return mktime(dt.timetuple())
class Identifiable(object):
def __init__(self, id=None):
Modified: mgmt/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/cumin/python/cumin/widgets.py 2008-01-02 16:43:50 UTC (rev 1529)
+++ mgmt/cumin/python/cumin/widgets.py 2008-01-03 13:08:02 UTC (rev 1530)
@@ -192,11 +192,18 @@
cls = self.app.model.get_class(object)
stats = [cls.get_stat(x) for x in self.stats.get(session)]
+ samples = dict()
+ times = dict()
+ values = dict()
+
+ for stat in stats:
+ samples[stat] = stat.samples(object)
+ values[stat] = [x[1] for x in samples[stat]]
+
max_value = 0
for stat in stats:
- for x in stat.samples(object, 300):
- max_value = max(x[1], max_value)
+ max_value = max(max(values[stat]), max_value)
max_value = max_value * 1.1
max_value = max_value + (10 - max_value % 100)
@@ -208,7 +215,7 @@
colors = ((1,0,0), (0,0,1), (0,1,0))
for stat, color in zip(stats, colors):
- chart.plot_values(stat.samples(object, 300), color=color)
+ chart.plot_values(samples[stat], color=color)
chart.plot_frame()
More information about the rhmessaging-commits
mailing list