12 July 2012

sample script to watch your number of connections of your msyql server

#!/bin/bash

NMAX=400
EMAILTO=yourname@domain.com

NSLEEP=5
TEMPFILE=/tmp/netstat.txt
EMAILME=0
while [ 1 ]; do
netstat -ant | awk '$6 == "ESTABLISHED" && $4 ~ /:3306$/
{print $5}' > $TEMPFILE
NCOUNT=`wc -l < $TEMPFILE`
if [ "$NCOUNT" -ge "$NMAX" ]; then
if [ "$EMAILME" -eq "0" ]; then
EMAILME=1
mail $EMAILTO < $TEMPFILE
fi
else
EMAILME=0
fi
sleep $NSLEEP
done

save it to a file with executable bit and run in the background (eg.
./filename.sh&)... since you set your max_connection to 500.. i set
NMAX to 400 so that it will email you once it reaches at that point so
that you have time to check before it hit your 500 connections..

replace EMAILTO to your valid email address and just make sure your
email system inside your mysql server is working properly (eg. echo
testing | mail yourname@domain.com)

Thanks to fooler

No comments:

Post a Comment