WatchMySQL script for cPanel/WHM

WatchMySQL cPanel/WHM Script

Overview

If you have ever seen the 'Too Many Connections' error from MySQL and then found that you could not connect to the MySQL server to see what user was causing this problem then this scripts for you! This script runs in the background and stays connected to the MySQL server so that it can monitor and notify the admin about users who have exceeded the set threshold. WatchMySQL can also help stop users abusing the server by killing off a users connection if they have exceeded the set limit.

Instructions

  • Installation

    The installation proceedure for this script requires that you have root access to the server via the console or SSH. Below are step by step instructions you should use to install this script.

    cd /sbin
    rm -f watchmysql
    wget http://www.ndchost.com/cpanel-whm/scripts/watchmysql/download.php
    chown root.root watchmysql
    chmod 0750 watchmysql
  • Configuration

    Before you run the script you must first configure it. Use edit to open the watchmysql script and set the options.

    #Sets the maximum concurrent connections per MySQL user.
    my $max_concurrent_connections		= '15';
    
    #Who to tell about this user... (email)
    my $warning_email			= 'your@email.address';
    
    #Kill Abuser's MySQL Connections (0 = no, 1 = yes)
    my $kill_user				= '0';
    
    #MySQL polling in seconds (600 = 10 minutes)
    my $check_interval			= '600';
  • Running

    To start this script simply run the following command

     /sbin/watchmysql &

    If you want the script to start when the system boots you need to add the above line to /etc/rc.local