Author: justi9
Date: 2008-01-02 11:43:50 -0500 (Wed, 02 Jan 2008)
New Revision: 1529
Modified:
mgmt/cumin/python/cumin/client.py
mgmt/cumin/python/cumin/formats.py
mgmt/cumin/python/cumin/model.py
mgmt/cumin/python/cumin/util.py
mgmt/cumin/python/cumin/widgets.py
Log:
Corrects rate calculation in the client list.
Adds a calc_rate() with rate computation logic.
Adds a secs() with the slightly tedious python code for going from a
datetime to seconds since epoch.
Formatting fix in fmt_rate.
Changes the initial max range in charts to 10, from 100.
Modified: mgmt/cumin/python/cumin/client.py
===================================================================
--- mgmt/cumin/python/cumin/client.py 2008-01-02 14:41:35 UTC (rev 1528)
+++ mgmt/cumin/python/cumin/client.py 2008-01-02 16:43:50 UTC (rev 1529)
@@ -30,10 +30,12 @@
self.add_sql_column("cfsent", "c.frames_from_client")
self.add_sql_column("cbrecv", "c.bytes_to_client")
self.add_sql_column("cfrecv", "c.frames_to_client")
+ self.add_sql_column("ctime", "c.rec_time")
self.add_sql_column("pbsent", "p.bytes_from_client")
self.add_sql_column("pfsent", "p.frames_from_client")
self.add_sql_column("pbrecv", "p.bytes_to_client")
self.add_sql_column("pfrecv", "p.frames_to_client")
+ self.add_sql_column("ptime", "p.rec_time")
col = self.AddressColumn(app, "addr")
self.add_column(col)
@@ -88,11 +90,14 @@
def do_render(self, session, data):
unit = self.parent.unit.get(session)
-
+
+ csecs = secs(data["ctime"])
+ psecs = secs(data["ptime"])
+
if unit == "b":
- value = data["cbsent"] - data["pbsent"] / float(1)
+ value = calc_rate(data["cbsent"], data["pbsent"],
csecs, psecs)
else:
- value = data["cfsent"] - data["pfsent"] / float(1)
+ value = calc_rate(data["cfsent"], data["pfsent"],
csecs, psecs)
content = fmt_rate(value, unit == "b" and "byte" or
"frame", "sec")
return "<td>%s</td>" % content
@@ -104,10 +109,13 @@
def do_render(self, session, data):
unit = self.parent.unit.get(session)
+ csecs = secs(data["ctime"])
+ psecs = secs(data["ptime"])
+
if unit == "b":
- value = data["cbrecv"] - data["pbrecv"] / float(1)
+ value = calc_rate(data["cbrecv"], data["pbrecv"],
csecs, psecs)
else:
- value = data["cfrecv"] - data["pfrecv"] / float(1)
+ value = calc_rate(data["cfrecv"], data["pfrecv"],
csecs, psecs)
content = fmt_rate(value, unit == "b" and "byte" or
"frame", "sec")
return "<td>%s</td>" % content
Modified: mgmt/cumin/python/cumin/formats.py
===================================================================
--- mgmt/cumin/python/cumin/formats.py 2008-01-02 14:41:35 UTC (rev 1528)
+++ mgmt/cumin/python/cumin/formats.py 2008-01-02 16:43:50 UTC (rev 1529)
@@ -59,10 +59,14 @@
return sign + "".join(elems)
-def fmt_rate(value, unit1, unit2):
- #return "%i <small>%s/%s</small>" % (value, unit1, unit2)
- return "%.0f<small>/%s</small>" % (float(nvl(value, 0)),
unit2)
+def fmt_rate(rate, unit1, unit2):
+ if rate == 0:
+ str = "0"
+ else:
+ str = "%0.2f" % float(nvl(rate, 0))
+ return "%s<small>/%s</small>" % (str, unit2)
+
def fmt_predicate(predicate):
return predicate and "Yes" or "No"
Modified: mgmt/cumin/python/cumin/model.py
===================================================================
--- mgmt/cumin/python/cumin/model.py 2008-01-02 14:41:35 UTC (rev 1528)
+++ mgmt/cumin/python/cumin/model.py 2008-01-02 16:43:50 UTC (rev 1529)
@@ -156,7 +156,7 @@
psecs = mktime(ptime.timetuple())
if curr is not None and prev is not None:
- return (curr - prev) / (csecs - psecs)
+ return calc_rate(curr, prev, csecs, psecs)
except AttributeError:
pass
Modified: mgmt/cumin/python/cumin/util.py
===================================================================
--- mgmt/cumin/python/cumin/util.py 2008-01-02 14:41:35 UTC (rev 1528)
+++ mgmt/cumin/python/cumin/util.py 2008-01-02 16:43:50 UTC (rev 1529)
@@ -1,3 +1,5 @@
+from time import mktime
+
def sorted_by(seq, attr="name"):
return sorted(seq, cmp, lambda x: getattr(x, attr))
@@ -10,6 +12,12 @@
else:
return expr1
+def calc_rate(curr, prev, csecs, psecs):
+ return (curr - prev) / float(csecs - psecs)
+
+def secs(dt):
+ return mktime(dt.timetuple())
+
class Identifiable(object):
def __init__(self, id=None):
self.id = id
Modified: mgmt/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/cumin/python/cumin/widgets.py 2008-01-02 14:41:35 UTC (rev 1528)
+++ mgmt/cumin/python/cumin/widgets.py 2008-01-02 16:43:50 UTC (rev 1529)
@@ -199,7 +199,7 @@
max_value = max(x[1], max_value)
max_value = max_value * 1.1
- max_value = max_value + (100 - max_value % 100)
+ max_value = max_value + (10 - max_value % 100)
chart.set_max_value(int(max_value))
chart.plot_x_axis()