forked from mozilla/BrowserQuest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add client dispatcher mode and server metrics
- Loading branch information
Showing
16 changed files
with
202 additions
and
474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ node_modules | |
client-build | ||
build.txt | ||
config_build.json | ||
config_local.json | ||
config_local* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
|
||
var cls = require("./lib/class"), | ||
_ = require("underscore"), | ||
memcache = require("memcache"); | ||
|
||
module.exports = Metrics = Class.extend({ | ||
init: function(config) { | ||
var self = this; | ||
|
||
this.config = config; | ||
this.client = new memcache.Client(config.memcached_port, config.memcached_host), | ||
this.client.connect(); | ||
this.isReady = false; | ||
|
||
this.client.on('connect', function() { | ||
log.info("Metrics enabled: memcached client connected to "+config.memcached_host+":"+config.memcached_port); | ||
self.isReady = true; | ||
if(self.ready_callback) { | ||
self.ready_callback(); | ||
} | ||
}); | ||
}, | ||
|
||
ready: function(callback) { | ||
this.ready_callback = callback; | ||
}, | ||
|
||
updatePlayerCounters: function(worlds) { | ||
var self = this, | ||
config = this.config, | ||
numServers = _.size(config.game_servers), | ||
playerCount = _.reduce(worlds, function(sum, world) { return sum + world.playerCount; }, 0); | ||
|
||
if(this.isReady) { | ||
// Set the number of players on this server | ||
this.client.set('player_count_'+config.server_name, playerCount, function() { | ||
var total_players = 0; | ||
|
||
// Recalculate the total number of players and set it | ||
_.each(config.game_servers, function(server) { | ||
self.client.get('player_count_'+server.name, function(error, result) { | ||
var count = result ? parseInt(result) : 0; | ||
|
||
total_players += count; | ||
numServers -= 1; | ||
if(numServers === 0) { | ||
self.client.set('total_players', total_players); | ||
} | ||
}); | ||
}); | ||
}); | ||
} else { | ||
log.error("Memcached client not connected"); | ||
} | ||
}, | ||
|
||
updateWorldDistribution: function(worlds) { | ||
this.client.set('world_distribution_'+this.config.server_name, worlds); | ||
}, | ||
|
||
getOpenWorldCount: function(callback) { | ||
this.client.get('world_count_'+this.config.server_name, function(error, result) { | ||
callback(result); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.