MySQL Various status monitoring

Source: Internet
Author: User

#!/bin/bash# defining variables V_username='MySQL'V_datetime= ' Date +"%y-%m-%d%h:%m:%s"' V_hostname=' hostname ' V_IP= '/sbin/ifconfig bond0|grep'inet Addr'|awk'{print $}'|cut-d:-F2 ' My_user="Root"my_pwd=""My_base= ' Ps-ef|grep mysqld|grep8808|awk-f'--' '{print $}'|awk-f'=' '{print $}'|sed's/[\t]*$//g'' my_cm="$MY _base/bin/mysql"My_admin="$MY _base/bin/mysqladmin"My_errlog= ' Ps-ef|grep mysqld|grep8808|awk-f'--' '{print $6}'|awk-f'=' '{print $}'|sed's/[\t]*$//g'' #发送人v_sendmail= ' hostname ' @139. com# receiver V_receivemail='[email protected]'#邮件发送程序MAIL_BIN="/HOME/CROND/BSMTP"#设置LC_ALLexport Lc_all=en_us. utf-8#监控目录v_path="/home/mysql/scripts/monitorlog"if[!-D"$v _path"];thenmkdir-P"$v _path"fi# Database Survival monitoring RM-f/home/mysql/scripts/monitorlog/Mysql_process.logps-elf|grep mysqld|grep-v grep >/home/mysql/scripts/monitorlog/Mysql_process.logif[-s/home/mysql/scripts/monitorlog/Mysql_process.log];thenecho"MySQL process is ok">> $v _path/Monitor_mysql.logElseEcho"############################"> $v _path/Monitor_mysql.logecho"USER: ${v_username}">> $v _path/Monitor_mysql.logecho"HOSTNAME: ${v_hostname}">> $v _path/Monitor_mysql.logecho"IP: ${v_ip}">> $v _path/Monitor_mysql.logecho"############################">> $v _path/Monitor_mysql.logecho"MYSQL is down">> $v _path/Monitor_mysql.log$mail_bin-F ${v_sendmail}-H smtp.api.localdomain-s"${v_hostname} MYSQL PROCESS WARNING!!!-${v_datetime}"${v_receivemail} < $v _path/monitor_mysql.logfi# Active Session Alarm Active_connect= $Sum_active_connect= ' $MY _admin-u$my_user-p$my_pwd pr|grep-iv SLEEP|WC-l ' Monitor_active_connec= ' Expr $active _connect/2+$active _connect 'if["$sum _active_connect"-ge"$monitor _active_connec"];thenecho"############################"> $v _path/My_active_connect.logecho"USER: ${v_username}">> $v _path/My_active_connect.logecho"HOSTNAME: ${v_hostname}">> $v _path/My_active_connect.logecho"IP: ${v_ip}">> $v _path/My_active_connect.logecho"############################">> $v _path/My_active_connect.logecho"Now active Connect warning,usual active Connec are $active _connect, now active Connect is $sum _active_connect">> $v _path/My_active_connect.log$mail_bin-F ${v_sendmail}-H smtp.api.localdomain-s"${v_hostname} ACTIVE CONNECT WARNING!!!-${v_datetime}"${v_receivemail} < $v _path/my_active_connect.logfi# slow Log alarm#if[-S "$v _path/my_slow_dir.txt"];then#echo"SLOW_DIR_OK"#else # $MY _cm-u$my_user-p$my_pwd-e"show global variables like ' slow_query_log_file '"> $v _path/My_slow_dir.txt#fi#my_slow= ' grep slow $v _path/my_slow_dir.txt|awk'{print $}'' #count_slow= ' Wc-l $MY _slow|awk'{print $}'' #echo"$count _slow"#sleep5#count_slow_now= ' Wc-l $MY _slow|awk'{print $}'`#if["$count _slow"-ne "$count _slow_now"];then#echo"############################"> $v _path/My_slow.log#echo"USER: ${v_username}">> $v _path/My_slow.log#echo"HOSTNAME: ${v_hostname}">> $v _path/My_slow.log#echo"IP: ${v_ip}">> $v _path/My_slow.log#echo"############################">> $v _path/my_slow.log#/home/mysql/scripts/pt-query-digest--since=2h $MY _slow >> $v _path/my_slow.log# $MAIL _bin-F ${v_sendmail}-H smtp.api.localdomain-s"${v_hostname} SLOW LOG WARNING!!!-${v_datetime}"${v_receivemail} < $v _path/my_slow.log#fi# lock Wait alarm monitor_lock=3$MY _cm-u$my_user-p$my_pwd-e"show global status like ' Innodb_row_lock_current_waits '"> $v _path/Lock. Logcount_lock= ' grep"[0-9]"$v _path/Lock. Log|awk'{print $}'`if["$count _lock"-ge"$monitor _lock"];thenecho"############################">> $v _path/Lock. Logecho"USER: ${v_username}">> $v _path/Lock. Logecho"HOSTNAME: ${v_hostname}">> $v _path/Lock. Logecho"IP: ${v_ip}">> $v _path/Lock. Logecho"############################">> $v _path/Lock. log$my_cm-u$my_user-p$my_pwd-e"Show engine InnoDB status\g">> $v _path/Lock. Log$mail_bin-F ${v_sendmail}-H smtp.api.localdomain-s"${v_hostname} SLOW LOG WARNING!!!-${v_datetime}"${v_receivemail} < $v _path/Lock. Logfi#mysql Error Log Alarmsif[-S"$v _path/mysql_error.log"];thenecho"ERROR_OK"Elsegrep-I error $MY _errlog > $v _path/Mysql_error.logficount_error= ' Grep-i error $v _path/mysql_error.log|wc-l|awk'{print $}'' Monitor_error= ' grep-i error $MY _errlog |WC-l ' #echo"$monitor _error Monitor_error"if["$monitor _error"-ne"$count _error"];thenecho"############################"> $v _path/My_error.logecho"USER: ${v_username}">> $v _path/My_error.logecho"HOSTNAME: ${v_hostname}">> $v _path/My_error.logecho"IP: ${v_ip}">> $v _path/My_error.logecho"############################">> $v _path/My_error.loggrep-I error $MY _errlog|tail-n ->> $v _path/My_error.log$mail_bin-F ${v_sendmail}-H smtp.api.localdomain-s"${v_hostname} ERROR LOG WARNING!!!-${v_datetime}"${v_receivemail} < $v _path/My_error.logif[ $? ==0];THENRM-F $v _path/Mysql_error.log fifi# Connection Total alarm #connect= -#sum_connect= ' $MY _admin-u$my_user-p$my_pwd PR|WC-l ' #monitor_connect= ' Expr $connect/Ten`#if["$sum _connect"-le "$monitor _connect"];then#echo"############################"> $v _path/My_connect.log#echo"USER: ${v_username}">> $v _path/My_connect.log#echo"HOSTNAME: ${v_hostname}">> $v _path/My_connect.log#echo"IP: ${v_ip}">> $v _path/My_connect.log#echo"############################">> $v _path/My_connect.log#echo"Now connect warning,usual Connect are $connect, now Connect is $sum _connect">> $v _path/my_connect.log# $MAIL _bin-F ${v_sendmail}-H smtp.api.localdomain-s"${v_hostname} SUM CONNECT WARNING!!!-${v_datetime}"${v_receivemail} < $v _path/My_connect.log#fi

MySQL Various status monitoring

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.