[rhmessaging-commits] rhmessaging commits: r3392 - in mgmt/trunk/cumin: python/cumin/grid and 2 other directories.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Wed May 27 14:24:24 EDT 2009


Author: eallen
Date: 2009-05-27 14:24:23 -0400 (Wed, 27 May 2009)
New Revision: 3392

Modified:
   mgmt/trunk/cumin/python/cumin/grid/collector.py
   mgmt/trunk/cumin/python/cumin/grid/pool.py
   mgmt/trunk/cumin/python/cumin/messaging/queue.py
   mgmt/trunk/cumin/python/cumin/model.py
   mgmt/trunk/cumin/python/cumin/stat.py
   mgmt/trunk/cumin/python/cumin/stat.strings
   mgmt/trunk/cumin/resources/app.js
Log:
1st cut at averaging samples for Charts.
Consolidate stacked charts with line charts and simplify javascript.
Make some queue charts fullpageable.

Modified: mgmt/trunk/cumin/python/cumin/grid/collector.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/grid/collector.py	2009-05-21 13:04:17 UTC (rev 3391)
+++ mgmt/trunk/cumin/python/cumin/grid/collector.py	2009-05-27 18:24:23 UTC (rev 3392)
@@ -115,10 +115,12 @@
 
         chart = self.JobStackedChart(app, "jobs")
         chart.stats = ("RunningJobs", "IdleJobs")
+        chart.fullpageable = True
         self.add_child(chart)
 
         chart = self.SlotStackedChart(app, "slots")
         chart.stats = ("HostsClaimed", "HostsUnclaimed", "HostsOwner")
+        chart.fullpageable = True
         self.add_child(chart)
 
     def render_title(self, session):

Modified: mgmt/trunk/cumin/python/cumin/grid/pool.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/grid/pool.py	2009-05-21 13:04:17 UTC (rev 3391)
+++ mgmt/trunk/cumin/python/cumin/grid/pool.py	2009-05-27 18:24:23 UTC (rev 3392)
@@ -322,11 +322,13 @@
         self.add_child(slot_map)
 
         chart = self.JobStackedChart(app, "jobs")
+        chart.fullpageable = True
         chart.duration.param.default = "3600"
         chart.stats = ("RunningJobs", "IdleJobs")
         self.add_child(chart)
 
         chart = self.SlotStackedChart(app, "slots")
+        chart.fullpageable = True
         chart.duration.param.default = "3600"
         chart.stats = ("HostsClaimed", "HostsUnclaimed", "HostsOwner")
         self.add_child(chart)

Modified: mgmt/trunk/cumin/python/cumin/messaging/queue.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/messaging/queue.py	2009-05-21 13:04:17 UTC (rev 3391)
+++ mgmt/trunk/cumin/python/cumin/messaging/queue.py	2009-05-27 18:24:23 UTC (rev 3392)
@@ -835,13 +835,16 @@
         self.add_child(StatSet(app, "io", "io"))
 
         chart = self.EnqueueDequeueRateChart(app, "enqdeq")
+        chart.fullpageable = True
         self.add_child(chart)
 
         chart = self.DepthChart(app, "depth")
+        chart.fullpageable = True
         self.add_child(chart)
 
         chart = StatValueChart(app, "consumers")
         chart.stats = ("consumerCount",)
+        chart.fullpageable = True
         self.add_child(chart)
 
     def render_title(self, session):

Modified: mgmt/trunk/cumin/python/cumin/model.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/model.py	2009-05-21 13:04:17 UTC (rev 3391)
+++ mgmt/trunk/cumin/python/cumin/model.py	2009-05-27 18:24:23 UTC (rev 3392)
@@ -2,6 +2,8 @@
 from datetime import datetime, timedelta
 from mint import Mint, MintConfig
 from struct import unpack, calcsize
+from sqlobject import sqlhub
+from sqlobject.sqlbuilder import Select
 from types import *
 from wooly import *
 from wooly.parameters import *
@@ -370,7 +372,49 @@
         if stats.count():
             return stats[0].qmfUpdateTime
 
-    def samples(self, object, secs):
+    def get_connection(self):
+        return sqlhub.getConnection().getConnection()
+
+    def get_db_name(self):
+        name = self.name
+        nname = list()
+        for c in name:
+            if c.isupper():
+                if len(nname):
+                    nname.append("_")
+                c = c.lower()
+            nname.append(c)
+        return "".join(nname)
+
+    def avg_samples(self, object, secs, interval):
+        conn = self.get_connection()
+
+        when = "(qmf_update_time >= now() - interval '%i seconds')" % secs
+        where = "%s and %s" % (object.stats.clause, when)
+
+        table_name = self.cumin_class.mint_stats_class.q.tableName
+        field_name = self.get_db_name()
+
+        if conn:
+            cursor = conn.cursor()
+
+            sql = """select max(qmf_update_time) as interval_end, 
+            cast(avg(%s) as integer) as value
+            from %s
+            where %s
+            group by floor(extract(epoch from qmf_update_time) / %i)
+            order by interval_end desc;""" % (field_name, 
+                                              table_name, 
+                                              where, 
+                                              interval)
+            
+            cursor.execute(sql)
+            return cursor.fetchall()
+
+    def samples(self, object, secs, interval, method):
+        if method == "avg":
+            return self.avg_samples(object, secs, interval)
+
         stats = object.stats
 
         now = datetime.now()

Modified: mgmt/trunk/cumin/python/cumin/stat.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/stat.py	2009-05-21 13:04:17 UTC (rev 3391)
+++ mgmt/trunk/cumin/python/cumin/stat.py	2009-05-27 18:24:23 UTC (rev 3392)
@@ -104,6 +104,8 @@
         self.duration = JSDurationSwitch(app, "duration")
         self.add_child(self.duration)
 
+        self.fullpageable = False
+
     def get_args(self, session):
         return self.frame.get_args(session)
 
@@ -129,6 +131,9 @@
     def get_chart_name(self, session):
         return "stats.png"
 
+    def render_fullpageable(self, session, object):
+        return self.fullpageable and " fullpageable" or ""
+
     def render_title(self, session, object):
         cls = self.app.model.get_class_by_object(object)
         return getattr(cls, self.stats[0]).title
@@ -343,6 +348,22 @@
         self.duration.default = 600
         self.add_parameter(self.duration)
 
+        self.interval = IntegerParameter(app, "interval")
+        self.interval.default = -1
+        self.add_parameter(self.interval)
+
+        self.method = Parameter(app, "method")
+        self.method.default = "avg"
+        self.add_parameter(self.method)
+
+        self.container_width = IntegerParameter(app, "width")
+        self.container_width.default = 360
+        self.add_parameter(self.container_width)
+
+        self.container_height = IntegerParameter(app, "height")
+        self.container_height.default = 100
+        self.add_parameter(self.container_height)
+
         self.cache = ImageCache()
 
     def get_content_type(self, session):
@@ -370,6 +391,14 @@
         writer = self.cache.create_cache_file(filename, recent)
         chart.write(writer)
 
+    def get_interval(self, session, duration, width):
+        interval = self.interval.get(session)
+        if interval != -1:
+            return interval
+        else:
+            max_samples = int(width * 1.5)
+            return max(int(duration / max_samples), 1)
+
     def do_render(self, session, object):
         cls = self.class_.get(session)
         stats = [getattr(cls, x) for x in self.stats.get(session)]
@@ -382,16 +411,21 @@
                 if cached_png:
                     return cached_png
 
-        chart = TimeSeriesChart(360, 100)
+        width = self.container_width.get(session)
+        height = self.container_height.get(session)
+        chart = TimeSeriesChart(width, height)
 
         samples = dict()
         values = dict()
 
+        mode = self.mode.get(session)
         duration = self.duration.get(session)
+        interval = self.get_interval(session, duration, width)
 
-        if self.mode.get(session) == "rate":
+        if mode == "rate":
+            method = None # don't do averaging
             for stat in stats:
-                os = stat.samples(object, duration)
+                os = stat.samples(object, duration, interval, method)
                 ns = list()
                 prev = None
 
@@ -406,8 +440,9 @@
 
                 samples[stat] = ns
         else:
+            method = self.method.get(session)
             for stat in stats:
-                samples[stat] = stat.samples(object, duration)
+                samples[stat] = stat.samples(object, duration, interval, method)
 
         for stat in stats:
             values[stat] = [x[1] for x in samples[stat]]
@@ -467,17 +502,6 @@
         return writer.to_string()
 
 class StatStackedPage(StatChartPage):
-    def __init__(self, app, name):
-        super(StatStackedPage, self).__init__(app, name)
-
-        self.container_width = IntegerParameter(app, "width")
-        self.container_width.default = 360
-        self.add_parameter(self.container_width)
-
-        self.container_height = IntegerParameter(app, "height")
-        self.container_height.default = 100
-        self.add_parameter(self.container_height)
-
     def do_render(self, session, object):
         cls = self.class_.get(session)
         stats = [getattr(cls, x) for x in self.stats.get(session)]
@@ -492,11 +516,13 @@
 
         legend_height = len(stats) * 16 + 16
 
-        chart = StackedValueChart(self.container_width.get(session), 
-                                  self.container_height.get(session), 
-                                  legend_height)
+        width = self.container_width.get(session)
+        height = self.container_height.get(session)
+        chart = StackedValueChart(width, height, legend_height)
 
         duration = self.duration.get(session)
+        method = self.method.get(session)
+        interval = self.get_interval(session, duration, width)
 
         max_value = 1
         min_value = 999999
@@ -506,11 +532,11 @@
         collapsed = dict()
         values = dict()
         for stat in stats:
-            samples[stat] = stat.samples(object, duration)
+            samples[stat] = stat.samples(object, duration, interval, method)
             # we sometimes get multiple samples for the same qmf_update_time
             for sample in samples[stat]:
                 collapsed[sample[0]] = sample[1]
-                
+
             for t in collapsed:
                 if not t in points:
                     points[t] = list()
@@ -561,3 +587,11 @@
         writer = Writer()
         chart.write(writer)
         return writer.to_string()
+
+if __name__ == "__main__":
+    import sys
+
+    try:
+        pass
+    except:
+        sys.exit(1)

Modified: mgmt/trunk/cumin/python/cumin/stat.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/stat.strings	2009-05-21 13:04:17 UTC (rev 3391)
+++ mgmt/trunk/cumin/python/cumin/stat.strings	2009-05-27 18:24:23 UTC (rev 3392)
@@ -164,30 +164,20 @@
 
 
 [StatValueChart.html]
-<div class="StatValueChart" id="{id}">
+<div>
+<div class="StatValueChart{fullpageable}" id="{id}">
   <h2>{title}</h2>
 
   <div class="duration">{duration}</div>
 
   <img id="{id}" src="{href}" height="{height}" width="{width}" alt="stats" />
   <div class="loading" style="display:none;"><span>Loading...</span></div>
-</div>
+</div></div>
 <script type="text/javascript">
 //<![CDATA[
 (function() {
-    wooly.addPageUpdateListener( 
-        function () {
-            if (document.images["{id}"].className == "Loading")
-                return;
-            cumin.updateChart("{id}");
-        });
-    var oImg = document.images['{id}'];
-    $(oImg).addEvent('load', function () {
-        var loading = $("{id}").getElement(".loading");
-        loading.setStyle('display', 'none');
-        loading.setStyle('visibility', 'visible');
-        loading.loading = false
-    });
+    wooly.addPageUpdateListener(function () {if (document.images["{id}"].className == "Loading") return; cumin.updateChart("{id}");});
+    cumin.setupChart('{id}', {width});
 }())
 //]]>
 </script>
@@ -197,63 +187,3 @@
   <span class="swatch" style="background-color: {stat_color}">&nbsp;</span>
   &nbsp; <span class="ph" statname="{stat_name}" statmode="{mode}">{stat_value}</span>
 </li>
-
-[StatStackedChart.javascript]
-function stackedNotify(full, width, height, id) {
-    var oImg = document.images[id];
-    if (oImg) {
-        var src = oImg.src;
-        var branch = wooly.session.branch(src);
-        branch.width = Math.max(width - 100, 360);
-        branch.height = Math.max(height - 100, 100);
-        src = branch.marshal();
-
-        src = cumin.refreshTime(src);
-        oImg.className = "Loading";
-        oImg.width = width;
-        oImg.height = height;
-        oImg.style.visibility = "hidden";
-        oImg.src = src;
-    }
-}
-
-[StatStackedChart.html]
-<div class="StatValueChart fullpageable" id="{id}">
-  <h2>{title}</h2>
-
-  <div class="duration">{duration}</div>
-
-  <img id="{id}" src="{href}" alt="Stacked Value Chart" />
-  <div class="loading" style="display:none;"><span>Loading...</span></div>
-</div>
-<script type="text/javascript">
-//<![CDATA[
-(function() {
-    wooly.addPageUpdateListener( 
-        function () {
-            if (document.images["{id}"].className == "Loading")
-                return;
-            cumin.updateChart("{id}");
-        });
-
-    $('{id}').onfullpage = function (width, height) { stackedNotify(true, width, height, '{id}'); };
-    $('{id}').onrestore = function () { stackedNotify(false, {width}, 100, '{id}'); };
-    var oImg = document.images['{id}'];
-    $(oImg).addEvent('load', function () {
-        this.style.visibility = "visible";
-        this.removeAttribute("width");
-        this.removeAttribute("height");
-        this.className = "";
-    });
-    $(oImg).addEvent('mousedown', function(event){
-        event.stop();
-    });
-    $(oImg).addEvent('load', function () {
-        var loading = $("{id}").getElement(".loading");
-        loading.setStyle('display', 'none');
-        loading.setStyle('visibility', 'visible');
-        loading.loading = false
-    });
-}())
-//]]>
-</script>

Modified: mgmt/trunk/cumin/resources/app.js
===================================================================
--- mgmt/trunk/cumin/resources/app.js	2009-05-21 13:04:17 UTC (rev 3391)
+++ mgmt/trunk/cumin/resources/app.js	2009-05-27 18:24:23 UTC (rev 3392)
@@ -23,16 +23,9 @@
         this.runObjectListeners = runObjectListeners;
 
         this.refreshTime = function(src) {
-            var sep = src.lastIndexOf(";");
-            var time = new Date().getTime();
-
-            if (isNaN(parseInt(src.substring(sep + 1)))) {
-                src = src + ";" + time;
-            } else {
-                src = src.substring(0, sep) + ";" + time;
-            }
-
-            return src;
+            var branch = wooly.session.branch(src);
+            branch.ts = new Date().getTime();
+            return branch.marshal()
         }
 
         this.updateChart = function(id) {
@@ -94,6 +87,44 @@
             }
         }
 
+        this.setupChart = function (id, width) {
+            var chart = $(id);
+            chart.onfullpage = function (width, height) { cumin.chartNotify(true, width, height, id); };
+            chart.onrestore = function () { cumin.chartNotify(false, width, 100, id); };
+            var oImg = document.images[id];
+            $(oImg).addEvent('load', function () {
+                this.style.visibility = "visible";
+                this.removeAttribute("width");
+                this.removeAttribute("height");
+                this.className = "";
+                var loading = chart.getElement(".loading");
+                loading.setStyle('display', 'none');
+                loading.setStyle('visibility', 'visible');
+                loading.loading = false
+            });
+            $(oImg).addEvent('mousedown', function(event){
+                event.stop();
+            });
+        }
+
+        this.chartNotify = function (full, width, height, id) {
+            var oImg = document.images[id];
+            if (oImg) {
+                var src = oImg.src;
+                var branch = wooly.session.branch(src);
+                branch.width = Math.max(width - 100, 360);
+                branch.height = Math.max(height - 100, 100);
+                src = branch.marshal();
+
+                src = cumin.refreshTime(src);
+                oImg.className = "Loading";
+                oImg.width = width;
+                oImg.height = height;
+                oImg.style.visibility = "hidden";
+                oImg.src = src;
+            }
+        }
+
         this.makeFullPageable = function (element) {
             if (element.getElement(".fullpageTitle"))
                 return; // already fullpaged




More information about the rhmessaging-commits mailing list