Phine Solutions web work notes

monitoring the server load from web

Filed under: ajax gadgets by 1.618 — September 22, 2007 11:04 am

From a Linux console, we can choose to show the server load using the ‘top” or “uptime” command. To get a simple reflection of the same information, we can also use the “/proc/loadavg”.

The first three columns of “/proc/loadavg” measure CPU and IO utilization of the last one, five, and 10 minute periods. The fourth column shows the number of currently running processes and the total number of processes. The last column displays the last process ID used.

Using a simple PHP script and Ajax, we can display the load status using “/proc/loadavg” on a timer using web interface without having to login to a console.

Here is the html page that we can use to show the status in every 5 seconds. It calls a PHP script which returns the content of /proc/loadavg. And by using Ajax, the page doesn’t need to be refreshed.

<html>
<body>

<script type=”text/javascript”>
<!– //
// initialize the ajax stuff
var x;
try {
// Try to create object for Firefox, Safari, IE7, etc.
x = new XMLHttpRequest();
} catch (e) {
try {
// Try to create object for later versions of IE.
x = new ActiveXObject(‘MSXML2.XMLHTTP’);
} catch (e) {
try {
// Try to create object for early versions of IE.
x = new ActiveXObject(‘Microsoft.XMLHTTP’);
} catch (e) {
// Could not create an XMLHttpRequest object.
alert(‘Not able to init ajax’);
}
}
}

setInterval(‘showLoad()’, 5000);

function showLoad() {
el = document.getElementById(‘LoadStatus’);
x.onreadystatechange = function() {
if (x.readyState == 4) {
if (x.status >= 200 && x.status <= 299) {
el.innerHTML = x.responseText;
}
}
}
x.open(“GET”, ‘/path/to/serverstatus.php?Load’, true);
x.send(null);
}
// –>
</script>
<div id=”LoadStatus” style=”width:400px; height:30px; background-color:#eee;”>
</div>

</body>
</html>

The simple PHP script that reads the loadavg file:

<?php
$info = date(“H:i:s”) . ‘ ‘;

if (isset($_GET['Load'])) {
$info .= file_get_contents(‘/proc/loadavg’);
echo $info;
}
?>

This solution is especially useful when telnet/ssh to a server is hard to do. For example, in a restricted network, or there is no computer around. You might ask without a computer, how to access web in the first place, well smart phone is the answer :) . As you can see it has more potential to do a lot more stuff if utilizing other Linux commands.

ip location on Google map

Filed under: ajax gadgets by 1.618 — February 14, 2007 10:58 am

This little tool takes an ip address and maps it on a Google map. Using the simple API provided by hostip.info, I am trying to pinpoint the geographical location of an ip address. Not sure about the accuracy though. Also, this is a little experiment using the Ajax utility by Javascript Prototype framework.

If you don’t enter an ip address or hostname, the tool will try to map your current ip (hopefully).


One way I enjoy using this tool is to check where the “scanners” or spammers of my server are located. Not that I can do anything about it but just to get some idea.

easy access to unix man page

Filed under: ajax gadgets by 1.618 — December 27, 2006 7:59 pm

command

ascii to char decoder

Filed under: ajax gadgets by 1.618 — December 26, 2006 11:36 am

This is a tool to convert an ascii stream to character string. I wrote this tool to make my life easier to peek into the spam page I got in the email and figure how do they hide the Javascript re-direct. Please do not try to inject executable commands or XSS. They are blocked.

decode ascii (replace the example in the text box):

output

a mortgage calculator using ajax + PHP

Filed under: ajax gadgets by 1.618 — December 22, 2006 2:14 pm

This little tool is written with ajax and php script.

This mortgage calculator can be used to figure out monthly payments of a home mortgage loan,
based on the home’s sale price, the term of the loan desired, buyer’s down payment percentage, and the loan’s interest rate.
This calculator factors in PMI (Private Mortgage Insurance) for loans where less than 20% is put as a down payment.

Purchase & Financing Information

Sale Price of Home:

(In Dollars)

Percentage Down:

%

Length of Mortgage:

years

Annual Interest Rate:

%

html url decoder

Filed under: ajax gadgets by 1.618 — December 21, 2006 1:56 pm

This is a little tool to convert the decoded URL back to an Ascii string.

decode url:
output:

©phinesolutions.com