Advertisement
count0ru

Untitled

May 12th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.26 KB | None | 0 0
  1. #!/bin/sh
  2. # The wrapper for Cacti PHP script.
  3. # It runs the script every 5 min. and parses the cache file on each following run.
  4. # Version: 1.1.6
  5. #
  6. # This program is part of Percona Monitoring Plugins
  7. # License: GPL License (see COPYING)
  8. # Copyright: 2016 Percona
  9. # Authors: Roman Vynar
  10.  
  11. ITEM=$1
  12. HOST=localhost
  13. DIR=`dirname $0`
  14. CMD="/usr/bin/php -q $DIR/ss_get_mysql_stats.php --host $HOST --items gg"
  15. CACHEFILE="/tmp/$HOST-mysql_cacti_stats.txt"
  16.  
  17. if [ "$ITEM" = "running-slave" ]; then
  18.     # Check for running slave
  19.     RES=`HOME=~zabbix mysql -e 'SHOW SLAVE STATUS\G' | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ','`
  20.     if [ "$RES" = " Yes, Yes," ]; then
  21.         echo 1
  22.     else
  23.         echo 0
  24.     fi
  25.     exit
  26. elif [ -e $CACHEFILE ]; then
  27.     # Check and run the script
  28.     TIMEFLM=`stat -c %Y /tmp/$HOST-mysql_cacti_stats.txt`
  29.     TIMENOW=`date +%s`
  30.     if [ `expr $TIMENOW - $TIMEFLM` -gt 300 ]; then
  31.         rm -f $CACHEFILE
  32.         $CMD 2>&1 > /dev/null
  33.     fi
  34. else
  35.     $CMD 2>&1 > /dev/null
  36. fi
  37.  
  38. # Parse cache file
  39. if [ -e $CACHEFILE ]; then
  40.     cat $CACHEFILE | sed 's/ /\n/g; s/-1/0/g'| grep $ITEM | awk -F: '{print $2}'
  41. else
  42.     echo "ERROR: run the command manually to investigate the problem: $CMD"
  43. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement