monã«ããMySQLã®ãããããã¯æ¤ç¥ããããã¯ç§æ°é¾å¤è¨å®ç·¨ã
å æ¥ãmonã§ãããããã¯æ¤ç¥ãããè¨äºãæ¸ãã¾ããã
ã¡ãã£ã¨ã¹ã¯ãªããã®å
容ãæ¹ä¿®ãã¦ã
ã¯ã¨ãªã«ããããã¯ã®ç§æ°ããç§è¶
ãããã¢ã©ã¼ãæ¤ç¥ãã
ã¨ãããã¨ãã§ããããã«ãã¾ããã
åºæ¬çãªæºåã¨ãã¯âã®è¨äºãåç
§ãã¦ãã ããã
ããã¯æ¤ç¥ã¹ã¯ãªããã®ä½æï¼æ¹ä¿®çï¼
vim /usr/local/sbin/mysql_lock_check.sh
#!/bin/sh #--------------------# # Define ENV # #--------------------# export PATH=$PATH:/usr/local/mysql/bin:/usr/bin/mysql HOST=`hostname` LOCK_SECOND=2 #ããã¯ãæ¤ç¥ããç§æ° MYSQL_USER=ã¦ã¼ã¶å #MySQLã®ã¦ã¼ã¶å MYSQL_PASSWORD=ãã¹ã¯ã¼ã #MySQLãã¹ã¯ã¼ã #--------------------# # DIR & FILE # #--------------------# NAME=`basename $0 .sh` PIDFILE=`dirname $0`/$NAME.pid MYSQL_DIR='/data/mysql' if [ -f "$PIDFILE" ] then echo 2 exit 2; fi echo $$ > $PIDFILE CNT=`mysql -u${MYSQL_USER} -p${MYSQL_PASSWORD} -e 'select p_w.TIME seconds from information_schema.INNODB_LOCK_WAITS w,information_schema.INNODB_LOCKS l,information_schema.INNODB_TRX t_b,information_schema.INNODB_TRX t_w,information_schema.PROCESSLIST p_b,information_schema.PROCESSLIST p_w where w.blocking_lock_id = l.lock_id and w.blocking_trx_id = t_b.trx_id and w.requesting_trx_id = t_w.trx_id and t_b.trx_mysql_thread_id = p_b.ID and t_w.trx_mysql_thread_id = p_w.ID \G' | grep "second" | awk -F" " '{ print $2 }' | sort -n | tail -n1` if [ "${CNT}" != "" ]; then if [ "${CNT}" -ge ${LOCK_SECOND} ]; then rm $PIDFILE echo `date` >> ${MYSQL_DIR}/${HOST}_innodb_lock.log mysql -u${MYSQL_USER} -p${MYSQL_PASSWORD} -e 'select t_b.trx_mysql_thread_id blocking_id,t_w.trx_mysql_thread_id requesting_id,p_b.HOST blocking_host,p_w.HOST requesting_host,l.lock_table lock_table,l.lock_index lock_index,l.lock_mode lock_mode,p_w.TIME seconds,p_b.INFO blocking_info,p_w.INFO requesting_info from information_schema.INNODB_LOCK_WAITS w,information_schema.INNODB_LOCKS l,information_schema.INNODB_TRX t_b,information_schema.INNODB_TRX t_w,information_schema.PROCESSLIST p_b,information_schema.PROCESSLIST p_w where w.blocking_lock_id = l.lock_id and w.blocking_trx_id = t_b.trx_id and w.requesting_trx_id = t_w.trx_id and t_b.trx_mysql_thread_id = p_b.ID and t_w.trx_mysql_thread_id = p_w.ID order by requesting_id,blocking_id \G' >> ${MYSQL_DIR}/${HOST}_innodb_lock.log echo 1 exit 1; fi fi rm $PIDFILE echo 0 exit 0;
ééã£ã¦ããæãã¦ä¸ããâ¦ã