show socket lag in monitor

pull/1/merge
Thibault Duplessis 2012-06-07 10:25:46 +02:00
parent b78b399b62
commit f4f8aa0c83
6 changed files with 18 additions and 13 deletions

View File

@ -7,7 +7,7 @@ import play.api.templates.Html
trait AssetHelper {
val assetVersion = 22
val assetVersion = 24
def cssTag(name: String) = css("stylesheets/" + name)

View File

@ -4,14 +4,9 @@
<head>
<title>@title</title>
<meta name="viewport" content="width=device-width, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/monitor.css")" />
<link rel="apple-touch-icon-precomposed" href="@routes.Assets.at("images/icon.png")"/>
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="@routes.Assets.at("images/icon.png")">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="@routes.Assets.at("images/icon@2x.png")">
<link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")" />
<script src="@routes.Assets.at("vendor/zanimo.min.js")" type="text/javascript"></script>
<link rel="shortcut icon" href="@routes.Assets.at("favicon.ico")" type="image/x-icon" />
@cssTag("monitor.css")
@jsTag("vendor/zanimo.min.js")
</head>
<body>
@content

View File

@ -4,7 +4,7 @@
<a class="back" href="@routes.Lobby.home">&lt; back to lichess</a>
<h1>Lichess reactor <span class="down">DOWN</span><span class="up">OPERATIONAL</span></h1>
<div id="monitors" class="clearfix">
<script type="text/javascript" src="@routes.Assets.at("javascripts/monitor.js")"></script>
@jsTag("monitor.js")
</div>
<div id="actions">
<a href="#" id="shutdown">Emergency reactor shutdown - DON'T CLICK</a>

View File

@ -157,6 +157,12 @@
container : container
});
app.lag = new SpeedOMeter({
name : "LAG",
maxVal : 200,
container : container
});
function setStatus(s) {
window.document.body.className = s;
}
@ -174,6 +180,9 @@
}
}
}
},
n: function() {
app["lag"].update(lichess.socket.currentLag);
}
},
options: {

View File

@ -24,6 +24,7 @@ $.websocket = function(url, version, settings) {
self.pingSchedule = null;
self.connectSchedule = null;
self.lastPingTime = self.now();
self.currentLag = 0;
self.averageLag = 0;
self.connect();
$(window).unload(function() {
@ -101,11 +102,11 @@ $.websocket.prototype = {
//self.debug("pong");
clearTimeout(self.connectSchedule);
self.schedulePing(self.options.pingDelay);
var lag = self.now() - self.lastPingTime;
self.currentLag = self.now() - self.lastPingTime;
if (self.options.lagTag) {
self.options.lagTag.text(lag + " ms");
self.options.lagTag.text(self.currentLag + " ms");
}
self.averageLag = self.averageLag * 0.8 + lag * 0.2;
self.averageLag = self.averageLag * 0.8 + self.currentLag * 0.2;
},
pingData: function() {
return JSON.stringify({t: "p", v: this.version});