Skip to content

Commit

Permalink
More cleanup adding statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
christkv committed Jun 28, 2012
1 parent e7701c9 commit dcf838e
Show file tree
Hide file tree
Showing 20 changed files with 358 additions and 4,324 deletions.
15 changes: 0 additions & 15 deletions index.ejs
Expand Up @@ -18,21 +18,6 @@
<style>BODY { -webkit-user-select:none; margin:0px}</style> <style>BODY { -webkit-user-select:none; margin:0px}</style>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" /> <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />


<!-- BSON -->
<script type="text/javascript" src="bson/binary.js"></script>
<script type="text/javascript" src="bson/binary_parser.js"></script>
<script type="text/javascript" src="bson/long.js"></script>
<script type="text/javascript" src="bson/code.js"></script>
<script type="text/javascript" src="bson/db_ref.js"></script>
<script type="text/javascript" src="bson/double.js"></script>
<script type="text/javascript" src="bson/float_parser.js"></script>
<script type="text/javascript" src="bson/max_key.js"></script>
<script type="text/javascript" src="bson/min_key.js"></script>
<script type="text/javascript" src="bson/objectid.js"></script>
<script type="text/javascript" src="bson/symbol.js"></script>
<script type="text/javascript" src="bson/timestamp.js"></script>
<script type="text/javascript" src="bson/bson.js"></script>

<!-- Actual game --> <!-- Actual game -->
<script type="text/javascript" src="communication.js"></script> <script type="text/javascript" src="communication.js"></script>
<script type="text/javascript" src="game.js"></script> <script type="text/javascript" src="game.js"></script>
Expand Down
35 changes: 35 additions & 0 deletions lib/stat_collector.js
@@ -0,0 +1,35 @@
var cluster = require('cluster');

var StatCollector = function(db) {
var self = this;
this.db = db;
this.collection = db.collection('statistics');
this.dataLength = 0;
this.byEvent = {};
this.resolution = 1000;

// Set up the set Interval that is used to save stats
this.intervalId = setInterval(function() {
if(self.db.serverConfig.isConnected() && cluster.isWorker) {
self.collection.insert({data: self.dataLength, ts: new Date(), e:self.byEvent, pid:process.pid});
self.dataLength = 0;
self.byEvent = {};
}
}, this.resolution);
}

StatCollector.prototype.passThroughWrite = function(event, data) {
// console.log("=========================================== " + event + " :: " + data.length)
// Just add the amount of data
this.dataLength = this.dataLength + data.length;
if(this.byEvent[event] == null) this.byEvent[event] = 0;
this.byEvent[event] = this.byEvent[event] + data.length;
// Return the data for usage
return data;
}

StatCollector.prototype.findLast = function(callback) {
this.collection.findOne({}, {sort:{ts:-1}, fields:{_id:0}}, callback);
}

exports.StatCollector = StatCollector;
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -13,8 +13,8 @@
"dependencies": { "dependencies": {
"websocket" : "1.0.4", "websocket" : "1.0.4",
"mongodb" : "1.1.0-beta", "mongodb" : "1.1.0-beta",
"express" : "2.5.8", "express" : "2.5.10",
"connect": "2.0.0", "connect": "2.3.4",
"ejs" : "0.6.1", "ejs" : "0.6.1",
"async" : "0.1.18" "async" : "0.1.18"
}, },
Expand Down
190 changes: 0 additions & 190 deletions public/bson/binary.js

This file was deleted.

0 comments on commit dcf838e

Please sign in to comment.