
WebApp Lag Meter non SSI using Ajax
By: a guest on Mar 31st, 2010 | syntax:
JavaScript | size: 1.94 KB | hits: 320 | expires: Never
<!--
For Help/Support
Go here: http://thegeekoftheworld.com/webapp-lag-meter-non-ssi-using-ajax/
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
-->
<script>
function createRequestObject() {
var ro;
var browser = navigator.appName;
if (browser == "Microsoft Internet Explorer") {
ro = new ActiveXObject("Microsoft.XMLHTTP");
} else {
ro = new XMLHttpRequest();
}
return ro;
}
var xmlHttp = createRequestObject();
function runping() {
xmlHttp.open('get', '/?ajaxping&ms=' + new Date().getTime());
xmlHttp.onreadystatechange = readping;
xmlHttp.send(null);
}
function readping() {
if (xmlHttp.readyState == 4) {
var a = new Date().getTime();
var ping = a - b - 10;
if (ping > 350) {
var pc = 'red';
var pcode = 'Ultra High lag';
}
if (ping <= 350) {
var pc = 'orange';
var pcode = 'High lag';
}
if (ping <= 225) {
var pc = 'yellow';
var pcode = 'Low lag';
}
if (ping <= 110) {
var pc = 'green';
var pcode = 'No lag';
}
if (document.getElementById("ping")) {
document.getElementById("ping").innerHTML = ping + 'ms<br /><font color="' + pc + '">' + pcode + '</font>';
}
}
//setTimeout("var b = new Date().getTime(); runping();", 5000); // Has a Error in it for testing only
}
var b = new Date().getTime();
runping();
</script>
<div id="ping"></div>