Results 1 to 10 of 17
Threaded View
-
24th Jun 2011, 12:41 PM #17OPMember
Cheers for that lifehacker.
If updated the script now to update using ajax.
It's becoming a uber cool server monitoring app
index.php
PHP Code:<html>
<head>
<style type="text/css">
.green-circle {
background-color: #0f0;
display: block;
height: 90px;
width: 90px;
-moz-border-radius: 45px;
border-radius: 45px;}
.red-circle {
background-color: #DF0101;
display: block;
height: 90px;
width: 90px;
-moz-border-radius: 45px;
border-radius: 45px;
}
</style>
<script language="javascript" type="text/javascript" src="jx.js"></script>
<script type='text/javascript'>
function LoadAll() {
jx.load("getdata.php",function(data) {
document.getElementById('container').innerHTML = data;
},'text');
setTimeout("LoadAll()",1000);
}
</script>
</head>
<body onload='LoadAll()'>
<div id='container'>
</div>
</body>
</html>
PHP Code:<?php
// Get number of connected users
$cmd = "ps aux | grep apache | wc -l";
$output = exec($cmd);
// Get CPU load
$uptime = exec("uptime");
$parts = split("load average:", $uptime);
$load = split(", ", $parts[1]);
// Get free memory
function get_memory() {
foreach(file('/proc/meminfo') as $ri)
$m[strtok($ri, ':')] = strtok('');
return round($m['MemFree'] / 1024);
}
//Parse output
if ($output > 140)
{
echo "<span class='red-circle'><br /><center>";
printf( $output);
echo "<br />" . get_memory() . "/1024";
echo $load[0];
echo "</span><br /><br />Server 1";
}
elseif ($output < 140)
{
echo "<span class='green-circle'><br /><center>";
printf( $output);
echo "<br />" . get_memory() . "/1024";
echo $load[0];
echo "</span><br /><br />Server 1<br /><br />";
}
?>
PHP Code://V3.01.A - http://www.openjs.com/scripts/jx/
jx = {
//Create a xmlHttpRequest object - this is the constructor.
getHTTPObject : function() {
var http = false;
//Use IE's ActiveX items to load the file.
if(typeof ActiveXObject != 'undefined') {
try {http = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e) {
try {http = new ActiveXObject("Microsoft.XMLHTTP");}
catch (E) {http = false;}
}
//If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document.
} else if (window.XMLHttpRequest) {
try {http = new XMLHttpRequest();}
catch (e) {http = false;}
}
return http;
},
// This function is called from the user's script.
//Arguments -
// url - The url of the serverside script that is to be called. Append all the arguments to
// this url - eg. 'get_data.php?id=5&car=benz'
// callback - Function that must be called once the data is ready.
// format - The return type for this function. Could be 'xml','json' or 'text'. If it is json,
// the string will be 'eval'ed before returning it. Default:'text'
load : function (url,callback,format) {
var http = this.init(); //The XMLHttpRequest object is recreated at every call - to defeat Cache problem in IE
if(!http||!url) return;
if (http.overrideMimeType) http.overrideMimeType('text/xml');
if(!format) var format = "text";//Default return type is 'text'
format = format.toLowerCase();
//Kill the Cache problem in IE.
var now = "uid=" + new Date().getTime();
url += (url.indexOf("?")+1) ? "&" : "?";
url += now;
http.open("GET", url, true);
http.onreadystatechange = function () {//Call a function when the state changes.
if (http.readyState == 4) {//Ready State will be 4 when the document is loaded.
if(http.status == 200) {
var result = "";
if(http.responseText) result = http.responseText;
//If the return is in JSON format, eval the result before returning it.
if(format.charAt(0) == "j") {
//\n's in JSON string, when evaluated will create errors in IE
result = result.replace(/[\n\r]/g,"");
result = eval('('+result+')');
}
//Give the data to the callback function.
if(callback) callback(result);
} else { //An error occured
if(error) error(http.status);
}
}
}
http.send(null);
},
init : function() {return this.getHTTPObject();}
}
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
"Alpha Kenny Body" A tongue tricker! Must Watch XD
By MoWarez in forum General DiscussionReplies: 5Last Post: 2nd Nov 2011, 06:45 PM -
"reply" to "create" and vice versa is post update?
By Gene_Autry in forum Technical Help Desk SupportReplies: 0Last Post: 16th Sep 2011, 04:37 PM -
How can I make my Back-up website "Immediately" to replace my "Original Site"??
By fuchen in forum Webmaster DiscussionReplies: 11Last Post: 13th Aug 2011, 04:14 PM -
Finally "Avatar" Breaks "Titanic" All Time Worldwide
By Last Word in forum General DiscussionReplies: 36Last Post: 5th Aug 2011, 08:06 AM -
Filesonic "counted downloads" or "Premium sales count" now?
By kariofilis in forum File Host DiscussionReplies: 15Last Post: 18th Jan 2011, 03:18 AM
themaCreator - create posts from...
Version 3.55 released. Open older version (or...