Author: eallen
Date: 2009-07-13 13:31:38 -0400 (Mon, 13 Jul 2009)
New Revision: 3487
Modified:
mgmt/trunk/cumin/python/cumin/model.py
Log:
Change the way samples() ensures it gets at least 2 sampels for rate charts.
Modified: mgmt/trunk/cumin/python/cumin/model.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/model.py 2009-07-10 20:10:34 UTC (rev 3486)
+++ mgmt/trunk/cumin/python/cumin/model.py 2009-07-13 17:31:38 UTC (rev 3487)
@@ -582,12 +582,16 @@
nname.append(c)
return "".join(nname)
- def avg_samples(self, object, secs, interval):
+ def avg_samples(self, object, secs, interval, secs2):
conn = self.get_connection()
- when = "(qmf_update_time >= now() - interval '%i seconds')"
% int(secs + 12)
- where = "%s and %s" % (object.stats.clause, when)
+ when = "(qmf_update_time >= now() - interval '%i seconds')"
% int(secs + secs2)
+ when2 = ""
+ if secs2:
+ when2 = " and (qmf_update_time <= now() - interval '%i
seconds')" % int(secs2)
+ where = "%s and %s%s" % (object.stats.clause, when, when2)
+
table_name = self.cumin_class.mint_stats_class.q.tableName
field_name = self.get_db_name()
@@ -608,21 +612,24 @@
cursor.execute(sql)
return cursor.fetchall()
- def samples(self, object, secs, interval, method):
+ def samples(self, object, secs, interval, method, secs2=0):
if method == "avg":
- return self.avg_samples(object, secs, interval)
+ return self.avg_samples(object, secs, interval, secs2)
stats = object.stats
now = datetime.now()
+ upper_limit = now - timedelta(seconds=int(secs2))
+ lower_limit = now - timedelta(seconds=int(secs + secs2))
+ col = self.cumin_class.mint_stats_class.q.qmfUpdateTime
+ stats = stats.filter(col <= upper_limit)
- col = self.cumin_class.mint_stats_class.q.qmfUpdateTime
def ensure_at_least(min_count, more_time):
- dt = now - timedelta(seconds=int(secs + more_time))
+ dt = now - timedelta(seconds=int(secs + secs2 + more_time))
stats2 = stats.filter(col >= dt)
if stats2.count() < min_count:
- more_time += 30
- if more_time <= 24 * 60 * 60:
+ more_time += 60
+ if more_time <= 60 * 60:
return ensure_at_least(min_count, more_time)
return stats2
@@ -631,17 +638,19 @@
samples = list()
- limit = now - timedelta(seconds=secs)
next_is_last = False
for stat in stats:
+ if (stat.qmfUpdateTime > upper_limit):
+ continue
+
value = getattr(stat, self.name, 0)
samples.append((stat.qmfUpdateTime, value))
if next_is_last:
break
- if stat.qmfUpdateTime < limit:
+ if stat.qmfUpdateTime < lower_limit:
next_is_last = True
return samples
Show replies by date