Permalink
Browse files

.

  • Loading branch information...
1 parent 0678a2c commit 0487e17b53cc2aa943c02450c7eb39a36e29c677 @jordansissel jordansissel committed Dec 19, 2012
Showing with 25 additions and 18 deletions.
  1. +5 −5 test/logstash.conf
  2. +19 −11 test/view.coffee
  3. +1 −2 test/view.html
View
@@ -23,10 +23,10 @@ output {
port => 3232
}
- stdout {
- tags => metric
- debug => true
- debug_format => json
- }
+ #stdout {
+ #tags => metric
+ #debug => true
+ #debug_format => json
+ #}
}
View
@@ -4,17 +4,19 @@ class Graph
constructor: () ->
@data = []
@element = document.createElement("div")
- @rickshaw = new Rickshaw.Graph({
- element: @element,
- width: 700,
- height: 100,
- series: @data
- })
- document.body.appendChild(@element)
+ console.log("New graph")
record: (value) ->
time = (new Date()).getTime() / 1000.0;
@data.append({ x: time, y: value })
+ if !@rickshaw
+ @rickshaw = new Rickshaw.Graph({
+ element: @element,
+ width: 700,
+ height: 100,
+ series: @data
+ })
+ document.body.appendChild(@element)
@rickshaw.render
# class Graph
@@ -24,6 +26,7 @@ class GraphList
record: (identity, value) ->
@graphs[identity] ||= new Graph
+ console.log(identity)
@graphs[identity].record(value)
# GraphList
@@ -38,18 +41,23 @@ class LogStashSocket
socket.onopen = (event) => console.log("Connected!")
socket.onerror = (event) =>
console.log("websocket error: " + event)
+ socket.close()
retry = () => @connect()
setTimeout(retry, 1000)
- socket.close()
socket.onmessage = (event) =>
obj = JSON.parse(event.data)
- @callback(obj);
+ @callback(obj)
graphlist = new GraphList()
-socket = new LogStashSocket("ws://demo.logstash.net:3232/", (event) =>
+callback = (event) =>
+ console.log(event)
metrics = event["@fields"]
- for key, value in metrics
+ for key, value of metrics
[root, name, metric] = key.split(".")
continue if root != "age" && metric != "mean"
+ console.log(name + ": " + value)
graphlist.record(name, value)
+
+socket = new LogStashSocket("ws://" + document.location.hostname + ":3232/",
+ callback)
View
@@ -6,8 +6,7 @@
</head>
<body>
<div id="chart"></div>
- <script src="coffee-script.js"></script>
- <script src="view.coffee" type="text/coffeescript"></script>
+ <script src="view.js"></script>
</body>
</html>

0 comments on commit 0487e17

Please sign in to comment.