Setup load Alerts on your dedicated server or VPS

A customer of ours wanted to get emails from his server, if the load ever rose above a certain number.

Here’s a script I wrote up to accomplish this:

EMAIL="your email 1"
SUBJECT="Alert $(hostname) load average is $L05"
TEMPFILE="/tmp/$(hostname)"
TOPLOAD="10"
echo "Load average Crossed allowed limit." >> $TEMPFILE
echo "Hostname: $(hostname)" >> $TEMPFILE
echo "Local Date & Time : $(date)" >> $TEMPFILE
echo "| Uptime status: |" >> $TEMPFILE
echo "-------------------------------------------" >> $TEMPFILE
/usr/bin/uptime >> $TEMPFILE
echo "-------------------------------------------" >> $TEMPFILE
echo "| Top 20 CPU consuming processes: |" >> $TEMPFILE
ps aux | head -1 >> $TEMPFILE
ps aux --no-headers | sort -rn +2 | head -20 >> $TEMPFILE
echo "| Top 10 memory-consuming processes: |" >> $TEMPFILE
ps aux --no-headers| sort -rn +3 | head >> $TEMPFILE
echo "-------------------------------------------" >> $TEMPFILE
echo "| Memory and Swap status: |" >> $TEMPFILE
/usr/bin/free -m >> $TEMPFILE
echo "-------------------------------------------" >> $TEMPFILE
echo "| Active network connection: |" >> $TEMPFILE
echo "-------------------------------------------" >> $TEMPFILE
/bin/netstat -tnup | grep ESTA >> $TEMPFILE
echo "-------------------------------------------" >> $TEMPFILE
echo "| Disk Space information: |" >> $TEMPFILE
echo "-------------------------------------------" >> $TEMPFILE
/bin/df -h >> $TEMPFILE
echo "-----------------THE END-------------------" >> $TEMPFILE
L05="$(uptime|awk '{print $(NF-2)}'|cut -d. -f1)"
if test $L05 -gt $TOPLOAD
then
mail -s "$SUBJECT  $L05" "$EMAIL" < $TEMPFILE
fi
rm -f $TEMPFILE
[/bash]

Add this to the root crontab on the server by running:
[bash]echo "* * * * * /root/loadalert >/dev/null 2>&1" >> /var/spool/cron/root

Now we need to restart crond to pick up the change:

/etc/init.d/crond restart

I hope this helps someone out there!

Installing GET

In RPM-based Linux distributions the package named “perl-libwww-perl” includes the LWP module with the GET, POST, and HEAD command aliases; to check if the RPM is installed:

rpm -qi perl-libwww-perl

If the RPM is not installed or if the aliases are otherwise missing (e.g., on FreeBSD), then the issue may be resolved by forcing a re-install of the LWP module from CPAN and having it install the aliases for LWP that enable the GET, POST, and HEAD commands; the re-installation may be performed using the following command, and when running it you would need to answer yes to the questions by entering “y” when prompted to create the aliases:
Code:

/scripts/realperlinstaller --force LWP

MySQL Grants

Here’s a quick MySQL query that will setup grants for the specified user, on the specified database:

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, CREATE ROUTINE ON `user\_database`.* TO 'user_username'@'%' IDENTIFIED by 'password';

cPanel 11.25.1 Database Mapping!

Got a technical advisory this morning, though I would share with the rest of the world!

With version 11.25.1, cPanel introduces the Database Mapping feature. This feature lays the groundwork for providing more flexibility in naming databases and database users.

In the past, cPanel has always appended an account’s username to any database name or database username created by the account (for example, a database might be named “user_dbname”). This changes with the addition of the Database Mapping feature.

In cPanel 11.25.1, Database Mapping provides the following benefits:

1. Accounts transferred from non-cPanel servers, such as those running Plesk or Ensim, will no longer have the cPanel account name added as a prefix to the names of databases and database users. This means applications like blogs and forums should work with minimal (or no) changes after transfer.

2. Server owners can disable use of the database name prefix server-wide. If a server owner chooses this option, databases and database users will no longer be created with the cPanel account as a prefix (for example, a database could be named “dbase” instead of “user_dbase”). This option is not reversible.

Both the above features will make a server incompatible with older versions of cPanel. If either 1) a non-cPanel account is transferred to an 11.25.1 server, or 2) the server owner opts to disable prefixing, then that server will not be able to later downgrade to 11.25.0.

Likewise, transferring an account from a cPanel system that does not use the database prefix to one that does (e.g., cPanel 11.25.1 with prefixing disabled, to cPanel 11.25.0) will result in support issues. Databases and database users whose names lack the prefix will not be manageable in the cPanel interface.

What are your thought’s comments on this?  I personally don’t see this working too well with shared hosts, just due to the sheer numbers of customers.

child pid xxxx exit signal File size limit exceeded (25)

Ever have Apache not respond, and in the logs shows:

[Fri May 04 16:10:35] [notice] child pid 9607 exit signal File size limit exceeded (25)
[Fri May 04 16:10:35] [notice] child pid 9606 exit signal File size limit exceeded (25)
[Fri May 04 16:10:35] [notice] child pid 9602 exit signal File size limit exceeded (25)
[Fri May 04 16:10:35] [notice] child pid 9599 exit signal File size limit exceeded (25)
[Fri May 04 16:10:35] [notice] child pid 9598 exit signal File size limit exceeded (25)
[Fri May 04 16:10:35] [notice] child pid 9593 exit signal File size limit exceeded (25)
[Fri May 04 16:10:35] [notice] child pid 9592 exit signal File size limit exceeded (25)
[Fri May 04 16:10:35] [notice] child pid 9591 exit signal File size limit exceeded (25)
[Fri May 04 16:10:35] [notice] child pid 9590 exit signal File size limit exceeded (25)
[Fri May 04 16:10:35] [notice] child pid 9588 exit signal File size limit exceeded (25)
[Fri May 04 16:10:35] [notice] child pid 9587 exit signal File size limit exceeded (25)
[Fri May 04 16:10:35] [notice] child pid 9583 exit signal File size limit exceeded (25)
[Fri May 04 16:10:35] [notice] child pid 9582 exit signal File size limit exceeded (25)
[Fri May 04 16:10:35] [notice] child pid 9579 exit signal File size limit exceeded (25)
[Fri May 04 16:10:35] [notice] child pid 9578 exit signal File size limit exceeded (25)
[Fri May 04 16:10:35] [notice] child pid 9576 exit signal File size limit exceeded (25)
[Fri May 04 16:10:35] [notice] child pid 9575 exit signal File size limit exceeded (25)
[Fri May 04 16:10:35] [notice] child pid 9574 exit signal File size limit exceeded (25)
[Fri May 04 16:10:35] [notice] child pid 9573 exit signal File size limit exceeded (25)
[Fri May 04 16:10:35] [notice] child pid 9554 exit signal File size limit exceeded (25)
[Fri May 04 16:10:35] [notice] child pid 9551 exit signal File size limit exceeded (25)
[Fri May 04 16:10:35] [notice] child pid 7835 exit signal File size limit exceeded (25)
[Fri May 04 16:10:35] [notice] child pid 7817 exit signal File size limit exceeded (25)

This is due to Apache’s 1’s 2G file size limit. This could also be caused by anyone using an EXT2 file system, as it doesn’t support files over 2G in size.

This is pretty easy to fix. First we need to find the offending file:

find /usr/local/apache/ -size +2000000k -printf “Size: %kK\tPath: %p\n”

Once you find the offending file, you’ll need to get rid of it. You can do this by piping into the file via

> /path/to/file

Than restart Apache:

/etc/init.d/httpd startssl
/etc/init.d/httpd restart
service httpd startssl