Tuesday, September 11, 2012

Monitor your MySQL or MSSQL servers heartbeat

It is a central piece of most applications nowadays and yet you discover the DB is down because some other alert about a failing service or even worse from your client.

Here is a simple POB script to help you check the health of your MSSQL or MYSQL server.

If you want alerts you could just cron the script and on failure you will get an error in the email address configured in the MAILTO option however a more sophisticated and better approach (for one you will receive the alert just once and after corrected you will get feedback about the issue been solved) is to call the script from Monit for example as in:
#################################################################
#REMOTE MSSQL CHECK
################################################################
check program ssql-heartbeat with path "/bin/sql-heartbeat.sh"
  if status != 0 then alert
Naturally /bin/mssql-heartbeat.sh will need to have 700 permissions and owned by root as credentials will be kept inside. Here is an example of such wrapper:
#!/bin/bash -e
/bin/sql-heartbeat.sh MSSQL myserver.mydomain.com heartbeatUser heartbeatPassword
Feel free to modify the heartbeat script to customize the database for example in case you want to be sure a specific db is available.

No comments:

Followers