Author: justi9
Date: 2007-10-25 10:09:30 -0400 (Thu, 25 Oct 2007)
New Revision: 1160
Added:
mgmt/cumin/python/cumin/charts.py
mgmt/misc/chart.py
Modified:
mgmt/cumin/python/cumin/__init__.py
mgmt/cumin/python/cumin/page.strings
mgmt/cumin/python/cumin/queue.py
mgmt/cumin/python/cumin/queue.strings
mgmt/notes/Todo
Log:
Adds a first rendition of charts for queue stats such as byte and
message depth.
Modified: mgmt/cumin/python/cumin/__init__.py
===================================================================
--- mgmt/cumin/python/cumin/__init__.py 2007-10-24 21:08:34 UTC (rev 1159)
+++ mgmt/cumin/python/cumin/__init__.py 2007-10-25 14:09:30 UTC (rev 1160)
@@ -11,6 +11,7 @@
from demo import DemoData
from page import CuminPage
from queue import QueueXmlPage
+from charts import QueueChartPage
class Cumin(Application):
def __init__(self, model):
@@ -34,6 +35,7 @@
self.add_page(RandomIntegerPage(self, "randint"))
self.add_page(DevelPage(self, "devel.html"))
self.add_page(QueueXmlPage(self, "queue.xml"))
+ self.add_page(QueueChartPage(self, "queue.png"))
class RandomIntegerPage(Page):
def __init__(self, app, name):
Added: mgmt/cumin/python/cumin/charts.py
===================================================================
--- mgmt/cumin/python/cumin/charts.py (rev 0)
+++ mgmt/cumin/python/cumin/charts.py 2007-10-25 14:09:30 UTC (rev 1160)
@@ -0,0 +1,66 @@
+from cairo import *
+from random import random
+from wooly import *
+
+from parameters import *
+
+class LineChart(object):
+ def __init__(self, width, height):
+ self.width = width
+ self.height = height
+ self.surface = ImageSurface(FORMAT_ARGB32, width, height)
+
+ def plot_values(self, values, interval=5, color=(0, 0, 0)):
+ max_value = max(100, max(values) * 1.2)
+
+ ctx = Context(self.surface)
+ ctx.set_line_width(2)
+ ctx.set_source_rgb(*color)
+
+ for x, value in zip(range(0, self.width, interval), values):
+ y = (value / float(max_value)) * self.height
+ ctx.line_to(x, y)
+
+ ctx.stroke()
+
+ def plot_intervals(self, interval=40):
+ ctx = Context(self.surface)
+ ctx.set_line_width(0.5)
+ ctx.set_source_rgb(0.8, 0.8, 0.8)
+
+ for x in range(0, self.width, interval):
+ ctx.move_to(x, 0)
+ ctx.line_to(x, self.height)
+
+ ctx.stroke()
+
+ def write(self, name):
+ self.surface.write_to_png(name)
+
+class QueueChartPage(Page):
+ def __init__(self, app, name):
+ super(QueueChartPage, self).__init__(app, name)
+
+ self.param = QueueParameter(app, "id")
+ self.add_parameter(self.param)
+
+ def get_object(self, session, object):
+ return self.param.get(session)
+
+ def get_content_type(self, session):
+ return "image/png"
+
+ def do_render(self, session, queue):
+ messages = queue.get_measurement("msgDepth")
+ bytes = queue.get_measurement("byteDepth")
+
+ chart = LineChart(600, 120)
+ chart.plot_intervals()
+ chart.plot_values(messages.values, color=(1, 0, 0))
+ chart.plot_values(bytes.values, color=(0, 0, 1))
+
+ name = "/tmp/whoa.png"
+ chart.write(name)
+ file = open(name, "r")
+
+ return file.read()
Modified: mgmt/cumin/python/cumin/page.strings
===================================================================
--- mgmt/cumin/python/cumin/page.strings 2007-10-24 21:08:34 UTC (rev 1159)
+++ mgmt/cumin/python/cumin/page.strings 2007-10-25 14:09:30 UTC (rev 1160)
@@ -98,7 +98,6 @@
h2 {
font-size: 1em;
- font-weight: normal;
margin: 0 0 0.5em 0;
}
@@ -379,6 +378,10 @@
width: 20%;
}
+.browser .nav h2 {
+ font-weight: normal;
+}
+
.browser .nav ul {
margin: 0 0 1em 0;
}
Modified: mgmt/cumin/python/cumin/queue.py
===================================================================
--- mgmt/cumin/python/cumin/queue.py 2007-10-24 21:08:34 UTC (rev 1159)
+++ mgmt/cumin/python/cumin/queue.py 2007-10-25 14:09:30 UTC (rev 1160)
@@ -379,6 +379,9 @@
def render_title(self, session, queue):
return "History"
+ def render_chart_url(self, session, queue):
+ return "queue.png?id=%i" % queue.id
+
class ConsumerSet(ItemSet):
def render_title(self, session, queue):
return "Consumers (%i)" % len(queue.consumer_items())
Modified: mgmt/cumin/python/cumin/queue.strings
===================================================================
--- mgmt/cumin/python/cumin/queue.strings 2007-10-24 21:08:34 UTC (rev 1159)
+++ mgmt/cumin/python/cumin/queue.strings 2007-10-25 14:09:30 UTC (rev 1160)
@@ -205,6 +205,22 @@
</tr>
</table>
+[StatisticsHistory.html]
+<h2>Queue Depth</h2>
+<div class="iblock">
+ <img src="{chart_url}"/>
+</div>
+
+<h2>Consumers</h2>
+<div class="iblock">
+ <img src="{chart_url}"/>
+</div>
+
+<h2>Transactions</h2>
+<div class="iblock">
+ <img src="{chart_url}"/>
+</div>
+
[ConsumerSet.html]
<select>
<option>Act on Selection...</option>
Added: mgmt/misc/chart.py
===================================================================
--- mgmt/misc/chart.py (rev 0)
+++ mgmt/misc/chart.py 2007-10-25 14:09:30 UTC (rev 1160)
@@ -0,0 +1,39 @@
+from cairo import *
+from random import random
+
+width, height = (600, 150)
+
+surface = ImageSurface(FORMAT_ARGB32, width, height)
+
+ctx = Context(surface)
+
+ctx.set_line_width(2)
+ctx.set_source_rgb(1, 0, 0)
+
+y = 0
+
+for x in range(0, width, 10):
+ change = 2 + (random() * 3)
+
+ if random() > 0.40:
+ if y < height - change:
+ y += change
+
+ else:
+ if y > change:
+ y -= change
+
+ ctx.line_to(x, y)
+
+ctx.stroke()
+
+ctx.set_line_width(0.8)
+ctx.set_source_rgb(0.8, 0.8, 0.8)
+
+for x in range(0, width, 50):
+ ctx.move_to(x, 0)
+ ctx.line_to(x, height)
+
+ctx.stroke()
+
+surface.write_to_png("chart.png")
Modified: mgmt/notes/Todo
===================================================================
--- mgmt/notes/Todo 2007-10-24 21:08:34 UTC (rev 1159)
+++ mgmt/notes/Todo 2007-10-25 14:09:30 UTC (rev 1160)
@@ -107,3 +107,6 @@
* model: get rid of the old *_count stat fields and use the new ones
* Add rates to stats views
+
+ * Right now, non cumin pages don't print their stack traces in the
+ log