Skip to content
Browse files

Got pygments+JSON messages on the dashboard.

  • Loading branch information...
1 parent 69b9d08 commit f70db78b28b2fb521e0b4a50b3d48db53324f68f @ralphbean committed Mar 23, 2012
View
31 busmon/consumers.py
@@ -1,12 +1,33 @@
-
+import pygments.lexers
+import pygments.formatters
from moksha.api.hub import Consumer
-class BusmonConsumer(Consumer):
+import fedmsg
+import fedmsg.json
+
+
+class MessageColorizer(Consumer):
app = "busmon" # hopefully this won't be necessary anymore
topic = "*"
+ destination_topic = "colorized-messages"
jsonify = False
- def consumer(self, message):
- # We may not actually need this.
- pass
+ def consume(self, message):
+ if self.destination_topic in message.topic:
+ return
+
+ html_args = {'full': False}
+ code = pygments.highlight(
+ fedmsg.json.pretty_dumps(fedmsg.json.loads(message.body)),
+ pygments.lexers.JavascriptLexer(),
+ pygments.formatters.HtmlFormatter(**html_args)
+ )
+
+ code = code.strip()
+
+ fedmsg.send_message(
+ topic=self.destination_topic,
+ msg=code,
+ validate=False,
+ )
View
2 busmon/controllers/root.py
@@ -11,6 +11,7 @@
from busmon.widgets import (
TopicsBarChart,
MessagesTimeSeries,
+ ColorizedMessagesWidget,
)
__all__ = ['RootController']
@@ -39,6 +40,7 @@ def index(self):
return dict(
barchart=TopicsBarChart,
timeseries=MessagesTimeSeries,
+ colorized_messages=ColorizedMessagesWidget,
)
@expose('busmon.templates.about')
View
59 busmon/public/css/monokai.css
@@ -0,0 +1,59 @@
+.hll { background-color: #49483e }
+.c { color: #75715e } /* Comment */
+.err { color: #960050; background-color: #1e0010 } /* Error */
+.k { color: #66d9ef } /* Keyword */
+.l { color: #ae81ff } /* Literal */
+.n { color: #f8f8f2 } /* Name */
+.o { color: #f92672 } /* Operator */
+.p { color: #f8f8f2 } /* Punctuation */
+.cm { color: #75715e } /* Comment.Multiline */
+.cp { color: #75715e } /* Comment.Preproc */
+.c1 { color: #75715e } /* Comment.Single */
+.cs { color: #75715e } /* Comment.Special */
+.ge { font-style: italic } /* Generic.Emph */
+.gs { font-weight: bold } /* Generic.Strong */
+.kc { color: #66d9ef } /* Keyword.Constant */
+.kd { color: #66d9ef } /* Keyword.Declaration */
+.kn { color: #f92672 } /* Keyword.Namespace */
+.kp { color: #66d9ef } /* Keyword.Pseudo */
+.kr { color: #66d9ef } /* Keyword.Reserved */
+.kt { color: #66d9ef } /* Keyword.Type */
+.ld { color: #e6db74 } /* Literal.Date */
+.m { color: #ae81ff } /* Literal.Number */
+.s { color: #e6db74 } /* Literal.String */
+.na { color: #a6e22e } /* Name.Attribute */
+.nb { color: #f8f8f2 } /* Name.Builtin */
+.nc { color: #a6e22e } /* Name.Class */
+.no { color: #66d9ef } /* Name.Constant */
+.nd { color: #a6e22e } /* Name.Decorator */
+.ni { color: #f8f8f2 } /* Name.Entity */
+.ne { color: #a6e22e } /* Name.Exception */
+.nf { color: #a6e22e } /* Name.Function */
+.nl { color: #f8f8f2 } /* Name.Label */
+.nn { color: #f8f8f2 } /* Name.Namespace */
+.nx { color: #a6e22e } /* Name.Other */
+.py { color: #f8f8f2 } /* Name.Property */
+.nt { color: #f92672 } /* Name.Tag */
+.nv { color: #f8f8f2 } /* Name.Variable */
+.ow { color: #f92672 } /* Operator.Word */
+.w { color: #f8f8f2 } /* Text.Whitespace */
+.mf { color: #ae81ff } /* Literal.Number.Float */
+.mh { color: #ae81ff } /* Literal.Number.Hex */
+.mi { color: #ae81ff } /* Literal.Number.Integer */
+.mo { color: #ae81ff } /* Literal.Number.Oct */
+.sb { color: #e6db74 } /* Literal.String.Backtick */
+.sc { color: #e6db74 } /* Literal.String.Char */
+.sd { color: #e6db74 } /* Literal.String.Doc */
+.s2 { color: #e6db74 } /* Literal.String.Double */
+.se { color: #ae81ff } /* Literal.String.Escape */
+.sh { color: #e6db74 } /* Literal.String.Heredoc */
+.si { color: #e6db74 } /* Literal.String.Interpol */
+.sx { color: #e6db74 } /* Literal.String.Other */
+.sr { color: #e6db74 } /* Literal.String.Regex */
+.s1 { color: #e6db74 } /* Literal.String.Single */
+.ss { color: #e6db74 } /* Literal.String.Symbol */
+.bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
+.vc { color: #f8f8f2 } /* Name.Variable.Class */
+.vg { color: #f8f8f2 } /* Name.Variable.Global */
+.vi { color: #f8f8f2 } /* Name.Variable.Instance */
+.il { color: #ae81ff } /* Literal.Number.Integer.Long */
View
15 busmon/public/css/site.css
@@ -9,6 +9,21 @@ body, p, a, li, div, input, button {
font-size: 12pt;
}
+pre {
+ margin: 0;
+}
+div.hll {
+ -moz-border-radius: 10px;
+ border-radius: 10px;
+ border: 1px solid black;
+ -webkit-box-shadow: 2px 2px 2px #333;
+ -moz-box-shadow: 2px 2px 2px #333;
+ box-shadow: 2px 2px 2px #333;
+ padding: 1.0em;
+}
+
+
+
#header h1 span#logo {
background:transparent url("../images/fedora-logo.png") no-repeat scroll 0px 0px;
height: 50px;
View
2 busmon/public/css/text.css
@@ -95,7 +95,7 @@ li {
margin-left:30px
}
-p,dl,hr,h1,h2,h3,h4,h5,h6,ol,ul,pre,table,address,fieldset {
+p,dl,hr,h1,h2,h3,h4,h5,h6,ol,ul,table,address,fieldset {
margin-bottom:20px
}
View
2 busmon/templates/colorized_messages.mak
@@ -0,0 +1,2 @@
+<%namespace name="tw" module="tw2.core.mako_util"/>\
+<div ${tw.attrs(attrs=w.attrs)}></div>
View
4 busmon/templates/index.mak
@@ -6,3 +6,7 @@
<div class="content">
${timeseries.display() | n}
</div>
+ <div class="clear spacer"></div>
+ <div class="content">
+ ${colorized_messages.display() | n}
+ </div>
View
18 busmon/widgets.py
@@ -8,6 +8,7 @@
global_width = 940
+
class TopicsBarChart(tw2.d3.BarChart, moksha.api.widgets.live.LiveWidget):
id = 'topics-bar-chart'
topic = "*" # zmq_strict = False :D
@@ -29,6 +30,7 @@ def prepare(self):
0.001,
))
+
class MessagesTimeSeries(tw2.d3.TimeSeriesChart,
moksha.api.widgets.live.LiveWidget):
id = 'messages-time-series'
@@ -42,3 +44,19 @@ class MessagesTimeSeries(tw2.d3.TimeSeriesChart,
n = 400
# Initialize to n zeros
data = [0] * n
+
+
+class ColorizedMessagesWidget(moksha.api.widgets.live.LiveWidget):
+ id = 'colorized-messages'
+ template = "mako:busmon.templates.colorized_messages"
+ resources = [twc.CSSLink(link="css/monokai.css")]
+ css_class = "hll"
+
+ topic = 'org.fedoraproject.busmon.colorized-messages'
+ onmessage = """
+ var container = $('#${id}');
+ if ( container.children().size() > 15 ) {
+ container.children().first().remove();
+ }
+ container.append(json.msg);
+ """
View
4 development.ini
@@ -45,8 +45,8 @@ moksha.livesocket.backend = websocket
moksha.livesocket.websocket.port = 9919
zmq_enabled = True
-zmq_publish_endpoints = tcp://*:5432
-zmq_subscribe_endpoints = tcp://127.0.0.1:5432,tcp://127.0.0.1:6543
+zmq_publish_endpoints=tcp://*:4321
+zmq_subscribe_endpoints=tcp://127.0.0.1:6543,tcp://127.0.0.1:5432,tcp://127.0.01:4321
zmq_strict = False
# If you'd like to fine-tune the individual locations of the cache data dirs
View
3 fedmsg.ini
@@ -0,0 +1,3 @@
+[fedmsg]
+# Have fedmsg send to an address where the moksha-hub is listening
+publish_endpoint = tcp://*:6543
View
3 setup.py
@@ -70,11 +70,12 @@
'main = pylons.util:PylonsInstaller',
),
'moksha.consumer': (
- #'wat = busmon.consumers:BusmonConsumer',
+ 'colorizer = busmon.consumers:MessageColorizer',
),
'moksha.widget': (
'topics_bar = busmon.widgets:TopicsBarChart',
'messages_series = busmon.widgets:MessagesTimeSeries',
+ 'colorized_msgs = busmon.widgets:ColorizedMessagesWidget',
),
},
dependency_links=[
View
2 tools/fake-bus.py
@@ -17,7 +17,7 @@
def main():
# Prepare our context and publisher
- fedmsg.init(publish_endpoint="tcp://*:6543")
+ fedmsg.init(publish_endpoint="tcp://*:5432")
# Probabilities of us emitting an event on each topic.
probs = {

0 comments on commit f70db78

Please sign in to comment.
Something went wrong with that request. Please try again.