Permalink
Browse files

kedge uses an anchor

  • Loading branch information...
0 parents commit 953858deca76d7b08731cb98f5524a4bbe92cda3 Kord Campbell committed Feb 16, 2011
@@ -0,0 +1 @@
+There is no README yet.
124 kedge.js
@@ -0,0 +1,124 @@
+var http = require('http');
+var io = require('socket.io');
+var loggly = require('loggly');
+var path = require('path');
+var paperboy = require('paperboy');
+
+// connect up to loggly
+var config = {
+ subdomain: "geekceo",
+ auth: {
+ username: "kordless",
+ password: "password"
+ }
+};
+var geekceo = loggly.createClient(config);
+
+// data for all currently connected clients, their searches, and the current bucket value
+// {"12345": {"searches": {"404": 99, "inputname:web": 99} } }
+var clients = {};
+var numclients = 0;
+
+// a list of searches we're currently running + results
+// { '404': [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], 'error': [ 1, 0, 0, 1, 2, 0, 0, 4, 1, 0 ] }
+var stashes = {};
+
+// triggered by setInterval directly below
+var fetch = function () {
+ // build our search list from all the client searches
+ for (var client in clients) {
+ // each search stored in each client
+ for (var search in clients[client].searches) {
+ if (!(search in stashes)) {
+ // create array for results if not made
+ stashes[search] = [];
+ }
+ }
+ }
+ // start retrieving each search
+ for (var stash in stashes) {
+ if (stashes[stash].length < 5) {
+ // only if the array for the search is running low, do we get new results
+ geekceo.facet('date', stash)
+ .context({ buckets: 15, from: "NOW-2MINUTES", until: "NOW-1MINUTES" })
+ .run(function (err, results) {
+ //console.log(results);
+ // we're asnyc in here, so don't use non-unique externals
+ // use the query in the response for finding the stash search term
+ var query = results.context.query;
+ // quick list so we can sort by date
+ var ud = [];
+ for (var x in results.data) {
+ ud.push(x);
+ }
+ for (var x in ud.sort()) {
+ // push on to stashes array for query/term/search
+ stashes[query].push(results.data[ud[x]]);
+ }
+ });
+ }
+ }
+}
+
+// run fetch above to check and/or populate stashes
+// make this interval * # of buckets above ~= 60K
+setInterval(fetch, 4000);
+
+// triggered by setInterval below
+// shifts data from each stash and dunks it into the the client's search values
+var dunk = function() {
+ for (var stash in stashes) {
+ // shift off the next entry for this search
+ try {
+ var foo = stashes[stash].shift();
+ } catch(err) {
+ var foo = 0;
+ }
+ for (var client in clients) {
+ // if client has this search/stash, update it
+ if (stash in clients[client].searches) {
+ clients[client].searches[stash] = foo;
+ }
+ // put in the number of currently connected clients
+ clients[client].searches['numclients'] = numclients+"";
+ }
+ }
+}
+setInterval(dunk, 4000);
+
+// serve static content
+var server = http.createServer(function(req, res){
+ paperboy.deliver(path.join(path.dirname(__filename), 'static'), req, res);
+});
+server.listen(80);
+
+// Create a Socket.IO instance, passing it our server
+var socket = io.listen(server);
+
+// Add a connect listener
+socket.on('connection', function(csock){
+ // put all of this client's searches in the clients struct
+ var interval = null;
+ var client_id = csock.sessionId+'';
+ numclients++;
+ clients[client_id]={"searches": {}};
+ csock.on('message',function(search){
+ clients[client_id].searches[search] = 0;
+ geekceo.log('a3e839e9-4827-49aa-9d28-e18e5ba5a818', 'kedge: connect client-'+client_id, function (err, result) { });
+ });
+ csock.on('disconnect',function(){
+ delete clients[client_id];
+ numclients--;
+ clearInterval(interval);
+ geekceo.log('a3e839e9-4827-49aa-9d28-e18e5ba5a818', 'kedge: disconnect client-'+client_id, function (err, result) { });
+ });
+
+ // push data to client every second
+ var ping = function() {
+ //console.log(clients[client_id]);
+ csock.send(clients[client_id]);
+ }
+ var interval = setInterval(ping, 1000);
+
+});
+
@@ -0,0 +1,48 @@
+/* http://meyerweb.com/eric/tools/css/reset/
+ v2.0 | 20110126
+ License: none (public domain)
+*/
+
+html, body, div, span, applet, object, iframe,
+h1, h2, h3, h4, h5, h6, p, blockquote, pre,
+a, abbr, acronym, address, big, cite, code,
+del, dfn, em, img, ins, kbd, q, s, samp,
+small, strike, strong, sub, sup, tt, var,
+b, u, i, center,
+dl, dt, dd, ol, ul, li,
+fieldset, form, label, legend,
+table, caption, tbody, tfoot, thead, tr, th, td,
+article, aside, canvas, details, embed,
+figure, figcaption, footer, header, hgroup,
+menu, nav, output, ruby, section, summary,
+time, mark, audio, video {
+ margin: 0;
+ padding: 0;
+ border: 0;
+ font-size: 100%;
+ font: inherit;
+ vertical-align: baseline;
+}
+/* HTML5 display-role reset for older browsers */
+article, aside, details, figcaption, figure,
+footer, header, hgroup, menu, nav, section {
+ display: block;
+}
+body {
+ line-height: 1;
+}
+ol, ul {
+ list-style: none;
+}
+blockquote, q {
+ quotes: none;
+}
+blockquote:before, blockquote:after,
+q:before, q:after {
+ content: '';
+ content: none;
+}
+table {
+ border-collapse: collapse;
+ border-spacing: 0;
+}
@@ -0,0 +1,11 @@
+a:link, a:visited {
+ color: #1485CC;
+ text-decoration: none;
+}
+body { background-color: #000000; color: #bbb; }
+h2 { color: #999; margin: 0px 0px 5px 0px; font-family: Helvetica, Arial, sans-serif; font-size: 24px; }
+p { color: #999; font-family: Helvetica, Arial, sans-serif; font-size: 14px; margin-bottom: 4px;}
+div { margin: 0px 20px 20px 20px; border-bottom: 1px dotted #333; }
+canvas { margin-bottom: 10px; border: 2px solid #333;}
+#logo { margin-top: 20px; padding-bottom: 10px;}
+.twitter-share-button { padding: 20px 0px 20px 4px; }
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,83 @@
+<html>
+<head>
+ <title>Smoothie Charts + #nodejs + #socketio + @loggly = Realtime WIN: </title>
+ <link rel="shortcut icon" href="/images/favicon.ico">
+ <link rel="stylesheet" href="/css/reset.css" type="text/css" />
+ <link rel="stylesheet" href="/css/style.css" type="text/css" />
+ <script type="text/javascript" src="/js/smoothie.js"></script>
+ <script type="text/javascript" src="/socket.io/socket.io.js"></script>
+ <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
+ <script type="text/javascript">
+ $(document).ready(function(){
+ var socket = new io.Socket("house.geekceo.com");
+ socket.connect();
+ var lines = {};
+ var graphs = [];
+ var searches = [];
+ socket.on('connect', function(){
+ // find our charts in the dom
+ $('canvas').each(function(i) {
+ graph_id = $(this).attr("id");
+ // the search is pulled from the title of the graph
+ search = $(this).attr("title");
+ // don't ask for numclients search
+ if (!(search == 'numclients')) {
+ searches.push(search);
+ }
+ // create new lines to stick in graphs
+ lines[search] = new TimeSeries();
+ lines[search].append(new Date().getTime(), 1);
+ console.log(lines);
+ gstyle = { grid: { strokeStyle:'rgb(0,125,0)', fillStyle:'rgb(0,60,0)', lineWidth: 1, millisPerLine: 500, verticalSections: 6, }, labels: { fillStyle:'rgb(200,200,200)'} };
+ graphs[i] = new SmoothieChart(gstyle);
+ lstyle = { strokeStyle:'rgb(150,255,150)', fillStyle:'rgba(150,255,150,0.4)', lineWidth: 2 };
+ graphs[i].addTimeSeries(lines[search], lstyle);
+ graphs[i].streamTo(document.getElementById(graph_id), 1000);
+ lines[search].append(new Date().getTime(), .0001);
+ });
+ socket.send(searches);
+ });
+ socket.on('message', function(data){
+ console.log(data);
+ $.each( data.searches, function(search) {
+ foo = data.searches[search];
+ // keep the graphs from breaking with 0
+ if (foo == 0) { foo = .0001; }
+ lines[search].append(new Date().getTime(), foo);
+ });
+ });
+ socket.on('disconnect', function(){
+ socket.connect();
+ });
+ });
+ </script>
+</head>
+<body>
+<div id='logo'><img src="/images/loggly.png"/></div>
+
+<!-- Number Client Connected -->
+<div>
+<h2>Number of Clients Connected to Kedge</h2>
+<canvas id="clients" title="numclients" width="1000" height="200"></canvas>
+</div>
+
+<!-- Fuck Tweets Graph -->
+<div>
+<h2>Tweets with 'Hacker News' or 'Reddit'</h2>
+<canvas id="hnreddit" title="hacker news OR reddit" width="1000" height="200"></canvas>
+</div>
+
+<!-- Visitor Graph -->
+<br clear="all">
+<div>
+<h2>Loggly Visitors</h2>
+<canvas id="visits" title="inputname:loggly_web" width="1000" height="200"></canvas>
+</div>
+
+<div>
+<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="loggly">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
+<p>Only works in Chrome, Safari and Opera. Props to <a href="http://twitter.com/joewalnes/">@joewalnes</a> for <a href="http://smoothiecharts.org">Smoothie Charts</a>, <a href="http://twitter.com/nodejs/">@nodejs</a> and <a href="http://socket.io/">socket.io</a>.</p>
+<p>© 2011 <a href="http://loggly.com/">Loggly, Inc.</a> You can <a href="http://github.com/kordless/kedge/">grab the code on Github</a>.<p>
+</div>
+</body>
+</html>
Oops, something went wrong.

0 comments on commit 953858d

Please sign in to comment.