1 #!/bin/sh 2 3 #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 4 # 5 # function library - please call with external script 6 # 7 #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 8 9 ############################################################################# 10 # MoSSHe: remote server monitoring environment 11 # 12 # Copyright (C) 2013- Volker Tanger 13 # 14 # This program is free software; you can redistribute it and/or 15 # modify it under the terms of the GNU General Public License 16 # as published by the Free Software Foundation; either version 2 17 # of the License, or (at your option) any later version. 18 # 19 # For bug reports and suggestions or if you just want to talk to me please 20 # contact me at volker.tanger@wyae.de 21 # 22 # Updates will be available at http://www.wyae.de/software/mosshe/ 23 # please check there for updates prior to submitting patches! 24 # 25 # For list of changes please refer to the HISTORY file. Thanks. 26 ############################################################################# 27 28 29 30 ############################################################################# 31 # MySQL checks - functions below 32 ############################################################################# 33 34 # before monitoring grant query permissions to status user 35 # mysql> grant usage on *.* to 'status'@'localhost' identified by 'status'; 36 37 38 #--------------------------------------------------------- 39 # MySQLThreads WARN ALERT 40 #--------------------------------------------------------- 41 MySQLThreads () { 42 MossheLog "MySQLThreads $1 $2" 43 typeset -i ALERT WARN VALUE RTN 44 WARN=$1 45 ALERT=$2 46 TEMPFILE=`mktemp` 47 48 if [ -x /usr/bin/mysqladmin ]; then 49 RTN=`mysqladmin --user=status --password=status status > $TEMPFILE 2>/dev/null; echo $?` 50 if [ $RTN -gt 0 ]; then 51 echo "${DATIM};$MYGROUP;$MYNAME;MySQLThreads;UNDEF;-10;mysql-user status without permission" >> $TEMPDIR/tmp.$$.collected.tmp 52 else 53 VALUE=`cut -d " " -f 5 < $TEMPFILE` 54 if [ "$VALUE" -gt "$ALERT" ]; then 55 STATUS="ALERT" 56 MESSAGE="Excessive Thread count for Mysql on $MYGROUP: $MYNAME " 57 elif [ "$VALUE" -gt "$WARN" ]; then 58 STATUS="WARN" 59 MESSAGE="High Thread count for Mysql on $MYGROUP: $MYNAME " 60 else 61 STATUS="OK" 62 MESSAGE="Thread count ok for Mysql on $MYGROUP: $MYNAME " 63 fi 64 echo "${DATIM};$MYGROUP;$MYNAME;MySQLThreads;$STATUS;$VALUE;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp 65 fi 66 else 67 echo "${DATIM};$MYGROUP;$MYNAME;MySQLThreads;UNDEF;-5;mysql not installed?" >> $TEMPDIR/tmp.$$.collected.tmp 68 fi 69 rm $TEMPFILE 70 } 71 72 73 #--------------------------------------------------------- 74 # MySQLQueries WARN ALERT Queries per second (int) 75 #--------------------------------------------------------- 76 MySQLQueries () { 77 MossheLog "MySQLQueries $1 $2" 78 typeset -i ALERT WARN VALUE RTN 79 WARN=$1 80 ALERT=$2 81 TEMPFILE=`mktemp` 82 83 if [ -x /usr/bin/mysqladmin ]; then 84 RTN=`mysqladmin --user=status --password=status status > $TEMPFILE 2>/dev/null; echo $?` 85 if [ $RTN -gt 0 ]; then 86 echo "${DATIM};$MYGROUP;$MYNAME;MySQLQueries;UNDEF;-10;mysql-user status without permission" >> $TEMPDIR/tmp.$$.collected.tmp 87 else 88 VALUE=`cut -d " " -f 29 < $TEMPFILE | cut -d "." -f 1` 89 if [ "$VALUE" -gt "$ALERT" ]; then 90 STATUS="ALERT" 91 MESSAGE="Excessive Query/sec load for Mysql on $MYGROUP: $MYNAME " 92 elif [ "$VALUE" -gt "$WARN" ]; then 93 STATUS="WARN" 94 MESSAGE="High Query/sec count for Mysql on $MYGROUP: $MYNAME " 95 else 96 STATUS="OK" 97 MESSAGE="Queries/sec ok for Mysql on $MYGROUP: $MYNAME " 98 fi 99 echo "${DATIM};$MYGROUP;$MYNAME;MySQLQueries;$STATUS;$VALUE;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp 100 fi 101 else 102 echo "${DATIM};$MYGROUP;$MYNAME;MySQLQueries;UNDEF;-5;mysql not installed?" >> $TEMPDIR/tmp.$$.collected.tmp 103 fi 104 rm $TEMPFILE 105 } 106 107 108 #############################################################################