Announcement

Collapse
No announcement yet.

MySql monitoring script

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • MySql monitoring script

    Hi everyone!

    Please use following script which will monitor MySQL Server service and will automatically restart it if its down.

    #!/bin/bash

    # MySQL Server root/admin username
    MUSER="root"

    # MySQL Server admin/root password
    MPASS="SET-ROOT-PASSWORD"

    # MySQL Server hostname
    MHOST="localhost"

    #Shell script to start MySQL server i.e. path to MySQL daemon start/stop script.
    MSTART="/etc/init.d/mysql start"

    # Email ID to send notification
    EMAILID="[email protected]"

    # path to mail program
    MAILCMD="$(which mail)"

    # path mysqladmin
    MADMIN="$(which mysqladmin)"

    #### DO NOT CHANGE anything BELOW ####
    MAILMESSAGE="/tmp/mysql.fail.$$"

    # see if MySQL server is alive or not
    # 2&1 could be better but i would like to keep it simple and easy to
    # understand stuff
    $MADMIN -h $MHOST -u $MUSER -p${MPASS} ping 2>/dev/null 1>/dev/null
    if [ $? -ne 0 ]; then
    echo "" >$MAILMESSAGE
    echo "Error: MySQL Server is not running/responding ping request">>$MAILMESSAGE
    echo "Hostname: $(hostname)" >>$MAILMESSAGE
    echo "Date & Time: $(date)" >>$MAILMESSAGE
    # try to start mysql
    $MSTART>/dev/null
    # see if it is started or not
    o=$(ps cax | grep -c ' mysqld$')
    if [ $o -eq 1 ]; then
    sMess="MySQL Server MySQL server successfully restarted"
    else
    sMess="MySQL server FAILED to restart"
    fi
    # Email status too
    echo "Current Status: $sMess" >>$MAILMESSAGE
    echo "" >>$MAILMESSAGE
    echo "*** This email generated by $(basename $0) shell script ***" >>$MAILMESSAGE
    echo "*** Please don't reply this email, this is just notification email ***" >>$MAILMESSAGE
    # send email
    $MAILCMD -s "MySQL server" $EMAILID < $MAILMESSAGE
    else # MySQL is running and do nothing
    :
    fi
    # remove file
    rm -f $MAILMESSAGE
    You just have to do some minor changes in this script (mysql password, email ID etc).

    Then set a cron to run according to your requirement for the above script.

    for eg.
    */15 * * * * ./(path to script) > /dev/null 2>&1
    This will run the script in every 15 mins.

    That's all !!


    Best Regards,
    eUKShane
    http://www.eukhost.com

    Best Regards,
    Sebastian
    Senior System Administrator


  • #2
    Hi Shane,

    I have enabled monitoring of MySQL Server and httpd through my WHM - do you know if these will send email alerts as well, as your script seems to do?

    thanks,
    Iain

    Comment


    • #3
      Hi Iain,

      No, you will not receive any alert mails as the above mentioned script does.

      But, you can also check the "CPU/Memory/MySQL" Usage from the WHM >> Server Status >> CPU/Memory/MySQL Usage and apache load from WHM >> Server Status >> Apache Status.
      Best Regards,
      Access Denied

      Comment


      • #4
        eUKShane can you confirm that the script really works?

        Comment


        • #5
          may i ask, will that SQL Server query work on a database that is hosted by trap17,or will i have to edit it in any way?

          Comment


          • #6
            Guys, I will suggest you to go for "System Integrity Monitor" which is best to monitor critical services, load, network etc on the server.

            http://www.rfxnetworks.com/sim.php
            Scott M
            System Administrator

            || ||

            Comment


            • #7
              Originally posted by eUKAlex View Post
              Guys, I will suggest you to go for "System Integrity Monitor" which is best to monitor critical services, load, network etc on the server.

              http://www.rfxnetworks.com/sim.php
              I've tried to install this on my VPS Hosting, but when I follow the instructions and run setup, nothing seems to appear in the default directories.

              Is there any help available for installing this on an eUKHost VPS Hosting server?

              Many thanks,
              Darren.

              Comment


              • #8
                Originally posted by darrenw View Post
                I've tried to install this on my VPS Hosting, but when I follow the instructions and run setup, nothing seems to appear in the default directories.

                Is there any help available for installing this on an eUKHost VPS Hosting server?

                Many thanks,
                Darren.
                I dont see any reason to install service monitoring scripts on cPanel VPS Hosting. cPanel has got its inbuilt service monitoring and chkservd will automatically restart any downed service. If you need sim even after knowing this then open a ticket for our VPS Hosting support team and they will install sim on your VPS Hosting.
                eUKhost - eNlight Cloud Hosting || eUKhost Knowledgebase
                Toll Free : 0808 262 0255 || Skype : mark_ducadi

                Comment


                • #9
                  Originally posted by eukhost.com View Post
                  I dont see any reason to install service monitoring scripts on cPanel VPS Hosting. cPanel has got its inbuilt service monitoring and chkservd will automatically restart any downed service. If you need sim even after knowing this then open a ticket for our VPS Hosting support team and they will install sim on your VPS Hosting.
                  Hi,

                  For some reason, the MySQL service keeps intermittently failing for no apparent reason. How often does chkservd check downed services? Does it include mysql?

                  Many thanks,
                  Darren.

                  Comment


                  • #10
                    chkservd checks status of services every minute so it will restart MySQL as soon as it goes down. There may be some other reason why MySQL fails and you need to question our support team about this problem.

                    none of our shared, reseller, semi-dedicated or dedicated hosting customers face this problem. This seems to happen on VPS Hosting's only as VPS Hosting seem to run short of memory for MySQL intensive website hostings. question our support team and find out the reason for this problem. It is possible that chkservd is down on your VPS Hosting
                    eUKhost - eNlight Cloud Hosting || eUKhost Knowledgebase
                    Toll Free : 0808 262 0255 || Skype : mark_ducadi

                    Comment


                    • #11
                      Originally posted by eukhost.com View Post
                      chkservd checks status of services every minute so it will restart MySQL as soon as it goes down. There may be some other reason why MySQL fails and you need to question our support team about this problem. none of our shared, reseller, semi-dedicated or dedicated hosting customers face this problem. This seems to happen on VPS Hosting's only as VPS Hosting seem to run short of memory for MySQL intensive website hostings. question our support team and find out the reason for this problem. It is possible that chkservd is down on your VPS Hosting
                      Unfortunately, MySQL Server has failed yet again for the third time in the last couple of days. The support ticket id is #DIT-48131-863

                      Comment


                      • #12
                        Hi,

                        This is wonderful script and good to monitor the mysql service. However, you need to make two changes in the script in order to work.

                        o=$(ps cax | grep -c ' mysqld$')
                        if [ $o -eq 1 ]; then

                        Edit these two lines to the below.

                        o=$(ps cax | grep -c ' mysqld')
                        if [ $o -ge 1 ]; then

                        It will work as expected.

                        Farhan Zahidi
                        System Engg

                        Comment


                        • #13
                          Hi,

                          This is wonderful script and good to monitor the mysql service. However, you need to make two changes in the script in order to work.

                          o=$(ps cax | grep -c ' mysqld$')
                          if [ $o -eq 1 ]; then

                          Edit these two lines to the below.

                          o=$(ps cax | grep -c ' mysqld')
                          if [ $o -ge 1 ]; then

                          It will work as expected.

                          Farhan Zahidi
                          System Engg

                          Comment


                          • #14
                            It is possible to use Checksum MySQL (http:// adm-it . net/checksum-mysql)

                            Comment


                            • #15
                              very nice script i must say! im using it

                              Comment

                              Working...
                              X