Calculate number of connections for MySQL server.

Make sure you always backup a copy of this very important configuration file before tweaking with it.
The formula that you want to use to calculate as follows;

 Available RAM = Global Buffers + (Thread Buffers x max_connections)
max_connections = (Available RAM - Global Buffers) / Thread Buffers

To find out what are the current settings for these buffers, you can use the following statement:


Here is a sample output:


You can download this spreadsheet below:

Monitor CPU and disk usage.

Using top:Save the O/P in a file.

$top -b -d 01 >> outputfile

This will update for every second.

$top -b -d 01 -n 5 >> outputfile
This will update for every second for 5 times.

Using iostat:

$sudo apt-get install sysstat
Install sysstat package,

$iostat -x 01 10
This will refresh for every second for 10 times.

Monitor web server using PHP script.

The following script will just check the response header and based on the response header it will send mail.

// check list of URLs (select URLs with small traffic – static content)

* function checks Web server and sends an e-mail if there is a problem
* email_admin has a default value and function can be called with or without e-mail address
* script implies that the Web server does not work if there is no response within 10 seconds
* @param string $url URL that must be checked
* @param string $email_admin if there is a problem send e-mail notification to this address
function url_test($url, $email_admin=’mani’){
// set timeout
$timeout = 10;
// init url session and set curl options
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, $timeout);
$http_respond = curl_exec($ch); // execute http request
// remove all html tags from the http response
$http_respond = trim(strip_tags($http_respond));
// get status from the http response
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// returned http code should be 200 / 304 otherwise there is a problem
if (($http_code != 200) && ($http_code != 304)){
// prepare tested server name (component parameter added in PHP 5.1.2)
$http_server = parse_url($url, PHP_URL_HOST);
// and who was tester
$hostname = trim(`/bin/hostname`);
// get an error message from the URL request
$http_error = trim(curl_error($ch));
// prepare e-mail message
$email_message = "SITE: $url";
if ($http_code) $email_message .= "\n\nHTTP CODE: $http_code";
if ($http_respond) $email_message .= "\n\nHTTP RESPOND:\n$http_respond";
if ($http_error) $email_message .= "\n\nHTTP ERROR:\n$http_error";
// prepare e-mail header
$email_header = "Content-Type: text/plain; charset=\"iso-8859-2\"\n".
"Subject: http://$http_server problem!\n".
"From: manikandan.r\n".
"X-Priority: 1\n".
"Priority: Urgent\n".
"Importance: high";
// send e-mail message
//error_log($email_message, 1, $email_admin, $email_header);
mail($email_admin, "SERVER ALERT", $email_message, $email_header);
// close url session