Skip to content

Commit

Permalink
Fixed Inspector values
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom32i committed Aug 12, 2015
1 parent d824432 commit 6d2c776
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 46 deletions.
6 changes: 4 additions & 2 deletions gulpfile.js
Expand Up @@ -139,11 +139,13 @@ gulp.task('copy-stress-test', function() {
});

gulp.task('watch', ['dev'], function () {
gulp.watch('src/**/*.js', ['jshint', 'server', 'front-full']);
gulp.watch('src/shared/**/*.js', ['jshint', 'server', 'front-full']);
gulp.watch('src/client/**/*.js', ['jshint', 'front-full']);
gulp.watch('src/server/**/*.js', ['jshint', 'server']);
gulp.watch('src/client/views/*/*.html', ['views']);
gulp.watch('src/client/views/*.html', ['ga']);
gulp.watch('src/client/stressTest.js', ['copy-stress-test']);
gulp.watch('src/**/*.scss', ['sass-full']);
gulp.watch('src/sass/**/*.scss', ['sass-full']);
});

gulp.task('default', ['jshint', 'server', 'front-expose', 'ga', 'views', 'front-min', 'sass-min']);
Expand Down
45 changes: 20 additions & 25 deletions src/server/core/Inspector.js
Expand Up @@ -38,8 +38,8 @@ function Inspector (server, config)
this.server.roomRepository.on('room:close', this.onRoomClose);

this.client.writePoint(this.DEPLOY, { version: packageInfo.version }, {}, {});
this.client.writePoint(this.CLIENTS, { value: this.server.clients.count() }, {}, {});
this.client.writePoint(this.ROOMS, { value: this.server.roomRepository.rooms.count() }, {}, {});
this.client.writePoint(this.CLIENTS, this.server.clients.count(), {}, {});
this.client.writePoint(this.ROOMS, this.server.roomRepository.rooms.count(), {}, {});

this.logInterval = setInterval(this.onLog, this.logFrequency);
}
Expand Down Expand Up @@ -78,7 +78,7 @@ Inspector.prototype.onClientOpen = function(client)
tracker.on('latency', this.onClientLatency);
client.on('close', this.onClientClose);

this.client.writePoint(this.CLIENTS, { value: this.server.clients.count() }, {}, {});
this.client.writePoint(this.CLIENTS, this.server.clients.count(), {}, {});
};

/**
Expand All @@ -90,12 +90,12 @@ Inspector.prototype.onClientClose = function(client)
{
var tracker = this.trackers.client.getById(client.id);

this.client.writePoint(this.CLIENTS, { value: this.server.clients.count() }, {}, {});
this.client.writePoint(this.CLIENTS, this.server.clients.count(), {}, {});

if (tracker) {
client.removeListener('close', this.onClientClose);
tracker.removeListener('latency', this.onClientLatency);
this.client.writePoint(this.CLIENT, tracker.serialize(), {}, {});
this.client.writePoint(this.CLIENT, tracker.getValues(), tracker.getTags(), {});
this.trackers.client.remove(tracker.destroy());
}
};
Expand All @@ -107,10 +107,7 @@ Inspector.prototype.onClientClose = function(client)
*/
Inspector.prototype.onClientLatency = function(data)
{
this.client.writePoint(this.CLIENT_LATENCY, {
value: data.latency,
game: data.tracker.uniqId
}, {}, {});
this.client.writePoint(this.CLIENT_LATENCY, data.latency, {'game': data.tracker.uniqId}, {});
};

/**
Expand All @@ -124,7 +121,7 @@ Inspector.prototype.onRoomOpen = function(data)

this.trackers.room.add(new RoomTracker(this, room));

this.client.writePoint(this.ROOMS, { value: this.server.roomRepository.rooms.count() }, {}, {});
this.client.writePoint(this.ROOMS, this.server.roomRepository.rooms.count(), {}, {});

room.on('game:new', this.onGameNew);
};
Expand All @@ -141,10 +138,10 @@ Inspector.prototype.onRoomClose = function(data)

room.removeListener('game:new', this.onGameNew);

this.client.writePoint(this.ROOMS, { value: this.server.roomRepository.rooms.count() }, {}, {});
this.client.writePoint(this.ROOMS, this.server.roomRepository.rooms.count(), {}, {});

if (tracker) {
this.client.writePoint(this.ROOM, tracker.serialize(), {}, {});
this.client.writePoint(this.ROOM, tracker.getValues(), tracker.getTags(), {});
this.trackers.room.remove(tracker.destroy());
}
};
Expand All @@ -171,12 +168,13 @@ Inspector.prototype.onGameNew = function(data)
this.client.writePoint(
this.CLIENT_GAME_PLAYER,
{
game: tracker.uniqId,
client: clientTracker.uniqId,
player: md5(avatar.name),
color: avatar.color
'player': md5(avatar.name),
'color': avatar.color
},
{
'game': tracker.uniqId,
'client': clientTracker.uniqId
},
{},
{}
);
}
Expand All @@ -193,7 +191,7 @@ Inspector.prototype.onGameNew = function(data)
*/
Inspector.prototype.onGameEnd = function(data)
{
var game = data.game,
var game = data.game,
tracker = this.trackers.game.getById(game.name);

game.removeListener('end', this.onGameEnd);
Expand All @@ -211,10 +209,7 @@ Inspector.prototype.onGameEnd = function(data)
*/
Inspector.prototype.onGameFPS = function(data)
{
this.client.writePoint(this.GAME_FPS, {
value: data.fps,
game: data.tracker.uniqId
}, {}, {});
this.client.writePoint(this.GAME_FPS, data.fps, {'game': data.tracker.uniqId}, {});
};

/**
Expand All @@ -224,7 +219,7 @@ Inspector.prototype.onGameFPS = function(data)
*/
Inspector.prototype.collectGameTrackerData = function(tracker)
{
this.client.writePoint(this.GAME, tracker.serialize(), {}, {});
this.client.writePoint(this.GAME, tracker.getValues(), tracker.getTags(), {});
this.trackers.game.remove(tracker.destroy());
};

Expand All @@ -242,7 +237,7 @@ Inspector.prototype.onLog = function()
Inspector.prototype.logUsage = function (err, result)
{
if (result) {
this.client.writePoint(this.USAGE_CPU, { value: result.cpu }, {}, {});
this.client.writePoint(this.USAGE_MEMORY, { value: result.memory }, {}, {});
this.client.writePoint(this.USAGE_CPU, result.cpu, {}, {});
this.client.writePoint(this.USAGE_MEMORY, result.memory, {}, {});
}
};
10 changes: 5 additions & 5 deletions src/server/launcher.js
Expand Up @@ -13,11 +13,11 @@ try {
var server = new Server({ port: config.port });

if (config.inspector.enabled) {
//try {
new Inspector(server, config.inspector);
//} catch (error) {
// console.error('Inspector error:', error);
//}
try {
new Inspector(server, config.inspector);
} catch (error) {
console.error('Inspector error:', error);
}
}

module.exports = server;
17 changes: 14 additions & 3 deletions src/server/trackers/Tracker.js
Expand Up @@ -42,10 +42,21 @@ Tracker.prototype.getDuration = function()
*
* @return {Object}
*/
Tracker.prototype.serialize = function()
Tracker.prototype.getValues = function()
{
return {
id: this.uniqId,
duration: this.getDuration()
'duration': this.getDuration()
};
};

/**
* Get tags
*
* @return {Object}
*/
Tracker.prototype.getTags = function()
{
return {
'id': this.uniqId
};
};
6 changes: 3 additions & 3 deletions src/server/trackers/TrackerClient.js
Expand Up @@ -32,11 +32,11 @@ ClientTracker.prototype.onLatency = function(latency)
/**
* @inheritDoc
*/
ClientTracker.prototype.serialize = function()
ClientTracker.prototype.getValues = function()
{
var data = Tracker.prototype.serialize.call(this);
var data = Tracker.prototype.getValues.call(this);

data.ip = md5(this.ip);
data['ip'] = md5(this.ip);

return data;
};
10 changes: 5 additions & 5 deletions src/server/trackers/TrackerGame.js
Expand Up @@ -99,13 +99,13 @@ GameTracker.prototype.destroy = function()
/**
* @inheritDoc
*/
GameTracker.prototype.serialize = function()
GameTracker.prototype.getValues = function()
{
var data = Tracker.prototype.serialize.call(this);
var data = Tracker.prototype.getValues.call(this);

data.size = this.size;
data.rounds = this.rounds;
data.finished = this.finished;
data['size'] = this.size;
data['rounds'] = this.rounds;
data['finished'] = this.finished;

return data;
};
6 changes: 3 additions & 3 deletions src/server/trackers/TrackerRoom.js
Expand Up @@ -39,11 +39,11 @@ RoomTracker.prototype.destroy = function()
/**
* @inheritDoc
*/
RoomTracker.prototype.serialize = function()
RoomTracker.prototype.getValues = function()
{
var data = Tracker.prototype.serialize.call(this);
var data = Tracker.prototype.getValues.call(this);

data.games = this.games;
data['games'] = this.games;

return data;
};

0 comments on commit 6d2c776

Please sign in to comment.