Author: eallen
Date: 2010-10-13 15:02:45 -0400 (Wed, 13 Oct 2010)
New Revision: 4385
Modified:
mgmt/trunk/cumin/python/cumin/stat.py
mgmt/trunk/cumin/resources/open-flash-chart.swf
Log:
BZ 639349 and 630881
- no longer passing in x value for charts. The action script code calculates the x value
based on the date/time of the sample.
- no longer passing in uid. The action script code now uses the date/time of the sample
for a unique id
- for full page graphs, don't draw the area between data points if there was no data
for more than 10 minutes
Modified: mgmt/trunk/cumin/python/cumin/stat.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/stat.py 2010-10-11 20:53:16 UTC (rev 4384)
+++ mgmt/trunk/cumin/python/cumin/stat.py 2010-10-13 19:02:45 UTC (rev 4385)
@@ -779,8 +779,8 @@
else:
append = True
- for sample, stat in zip(samples, stats):
- log.debug("samples in %s: %d" % (stat.name, len(samples[sample])))
+ #for sample, stat in zip(samples, stats):
+ # log.debug("samples in %s: %d" % (stat.name,
len(samples[sample])))
# create the chart dict
chart = self.get_chart(session, adapter, stats, samples, time_span, max_value,
min_value, append, end_seconds_ago)
@@ -860,7 +860,7 @@
samples = dict()
if mode == "rate":
for stat in stats:
- os = adapter.samples(stat, dur, interval, method, secs2=end_seconds_ago,
delta=delta)
+ os = adapter.samples(stat, dur+600, interval, method,
secs2=end_seconds_ago, delta=delta)
ns = list()
prev = None
@@ -876,7 +876,8 @@
samples[stat] = ns
else:
for stat in stats:
- samples[stat] = adapter.samples(stat, dur, interval, method,
secs2=end_seconds_ago, delta=delta)
+ # get more samples than needed to allow chart to clip correctly
+ samples[stat] = adapter.samples(stat, dur+600, interval, method,
secs2=end_seconds_ago, delta=delta)
return samples
@@ -900,12 +901,16 @@
def get_vals(self, session, samples, stat, text, duration, end_secs):
tnow = time()
- vals = [{"x":int(duration -(tnow - secs(dt)) + end_secs),
- "y":value,
- "uid": dt.strftime("%m%d%Y%H%M%S")}
- #"tip": "<br>%s: #val#<br>Time: %s" % (text,
dt.strftime("%m/%d/%Y %H:%M:%S"))
- for dt, value, dev in reversed(samples[stat])
- if value is not None]
+ vals = list()
+
+ min_dt = tnow - duration - end_secs
+ for dt, value, dev in samples[stat]:
+ if value is not None:
+ vals.append({"dt": secs(dt), "y": value})
+ if secs(dt) < min_dt:
+ break
+
+ vals.reverse()
return vals
def make_chart_lines(self, session, chart, line_type, stats, dot_size, halo_size,
line_width, samples, duration, end_secs, mode):
@@ -946,6 +951,10 @@
id = id.encode('ascii', 'replace')
chart.id = id
chart.bg_colour = "#FFFFFF"
+ chart.tnow = time()
+ chart.duration = duration
+ chart.end_secs = end_secs
+
self.make_chart_lines(session, chart, "area", stats, dot_size,
halo_size, line_width, samples, duration, end_secs, mode)
if append:
@@ -972,19 +981,40 @@
chart.control.x_axis = XAxis().get_x_axis(self.one_day, 0, tick_height=10)
chart.control.x_axis.labels.colour = "#333333"
chart.control.x_axis.grid_colour = "#FFFFFF"
- samples = self.fetch_samples(adapter, self.one_day, 60, "avg",
mode, False, stats, end_seconds_ago=0)
+ samples = self.fetch_samples(adapter, self.one_day, 180, "avg",
mode, False, stats, end_seconds_ago=0)
+ self.add_control_points(session, stats, samples)
max_value, min_value = self.get_max_min(session, stats, samples)
- self.make_chart_lines(session, chart.control, "line", stats, 1, 0,
1, samples, self.one_day, 0, mode)
+ self.make_chart_lines(session, chart.control, "area", stats, 1, 0,
0, samples, self.one_day, 0, mode)
chart.control.y_min = max(min_value, 0)
chart.control.y_max = max(max_value-2, 1)
chart.control.slider_low.value = float(self.page.control_min.get(session))
chart.control.slider_low.colour = "#666666"
chart.control.slider_high.value = float(self.page.control_max.get(session))
chart.control.slider_high.colour = "#666666"
+ chart.control.tnow = time()
+ chart.control.duration = self.one_day
+ chart.control.end_secs = 0
#print "sending entire sample set with y_axis.max=%i" %
chart.y_axis["max"]
return chart
+ def add_control_points(self, session, stats, samples):
+ new_samples = list()
+ threshold = timedelta(minutes=10)
+ for stat in stats:
+ last_dt = None
+ last_val = 0
+ for dt, value, dev in samples[stat]:
+ if last_dt and last_dt - dt > threshold:
+ if last_val:
+ new_samples.append((last_dt, 0, 0))
+ if value:
+ new_samples.append((dt, 0, 0))
+ last_dt = dt
+ last_val = value
+ new_samples.append((dt, value, dev))
+ samples[stat] = new_samples
+
class StackedAreaChart(AreaChart):
colors = ('#FFABAB', '#ABABFF', '#ABFFAB', '#FFABFF',
'#FFFFAB', '#ABFFFF', '#ABABAB')
def __init__(self, app, name, page):
@@ -1005,21 +1035,27 @@
for stat in stats:
last_dt = None
for dt, value, dev in samples[stat]:
- if dt == last_dt:
- continue
if value == None:
value = 0
- last_dt = dt
if stat not in points:
points[stat] = list()
if dt not in totals:
totals[dt] = 0
- totals[dt] += value
- points[stat].append((dt, value, totals[dt]))
- max_value = max(totals[dt], max_value)
- min_value = min(totals[dt], min_value)
+ if dt == last_dt:
+ if (totals[dt] > 0) and value > 0:
+ continue
+ points[stat].append((dt, 0, 0))
+ else:
+ last_dt = dt
+ totals[dt] += value
+ points[stat].append((dt, value, totals[dt]))
+
+ max_value = max(totals[dt], max_value)
+ min_value = min(totals[dt], min_value)
+
+
# save the accumulated values for each timestamp
self.points.set(session, points)
@@ -1031,29 +1067,20 @@
def get_vals(self, session, samples, stat, text, duration, end_secs):
tnow = time()
+ vals = list()
points = self.points.get(session)
- values = list()
if points:
- vals = [{"x":int(duration -(tnow - secs(dt)) + end_secs),
- "y":stacked_value,
- "uid": dt.strftime("%m%d%Y%H%M%S")}
- #"tip": "<br>%s: %s<br>Time: %s" % (text,
str(value), dt.strftime("%m/%d/%Y %H:%M:%S"))}
- for dt, value, stacked_value in reversed(points[stat])
- if value is not None]
+ min_dt = tnow - duration - end_secs
+ for dt, value, stacked_value in points[stat]:
+ if value is not None:
+ vals.append({"dt": secs(dt), "y":
stacked_value})
+ if secs(dt) < min_dt:
+ break
- log.debug("number of points before culling: %d" % len(vals))
- # allow only 1 value that has a -x
- first_positive = 0
- for i in range(len(vals)):
- if vals[i]['x'] >= 0:
- first_positive = i
- break
- values = [vals[i] for i in range(len(vals)) if i >= first_positive - 1]
- log.debug("number of points after culling: %d" % len(values))
+ vals.reverse()
+ return vals
- return values
-
class Points(Attribute):
def get_default(self, session):
return dict()
Modified: mgmt/trunk/cumin/resources/open-flash-chart.swf
===================================================================
(Binary files differ)