Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # -*- sh -*-
- : << =cut
- =head1 NAME
- intra_mysql_metrics - Munin Plugin to monitor the number of records on a
- mysql-server
- =head1 CONFIGURATION
- The following environment variables are used by this plugin:
- mysqlopts - Options to pass to mysql
- =head1 AUTHOR
- Unknown author
- =head1 LICENSE
- Unknown license
- =head1 MAGIC MARKERS
- #%# family=manual
- #%# capabilities=autoconf
- =cut
- #MYSQLOPTS="$mysqlopts"
- MYSQLOPTS="-u xxxdbuser -h xxxx-db-instance.qwertyuiopas.ap-northeast-1.rds.amazonaws.com --password=xxxdbuserpass"
- MYSQLADMIN=${mysqladmin:-mysqladmin}
- if [ "$1" = "autoconf" ]; then
- $MYSQLADMIN --version 2>/dev/null >/dev/null
- if [ $? -eq 0 ]
- then
- $MYSQLADMIN $MYSQLOPTS status 2>/dev/null >/dev/null
- if [ $? -eq 0 ]
- then
- echo yes
- exit 0
- else
- echo "no (could not connect to mysql)"
- fi
- else
- echo "no (mysqladmin not found)"
- fi
- exit 0
- fi
- if [ "$1" = "config" ]; then
- echo 'graph_title MySQL metrics'
- # echo 'graph_args --base 1000 -l 0'
- echo 'graph_args -l 0'
- echo 'graph_vlabel count(*)'
- echo 'graph_category intra_mysql'
- echo 'graph_info Note that this is a old plugin which is no longer installed by default. It is retained for compatability with old installations.'
- echo 'users.label users'
- #echo 'users.type DERIVE'
- #echo 'users.type COUNTER'
- echo 'users.min 0'
- echo 'users.max 500000'
- echo 'posts.label posts'
- #echo 'posts.type DERIVE'
- #echo 'posts.type COUNTER'
- echo 'posts.min 0'
- echo 'posts.max 500000'
- echo 'groups.label groups'
- #echo 'groups.type DERIVE'
- #echo 'groups.type COUNTER'
- echo 'groups.min 0'
- echo 'groups.max 500000'
- echo 'pages.label pages'
- #echo 'pages.type DERIVE'
- #echo 'pages.type COUNTER'
- echo 'pages.min 0'
- echo 'pages.max 500000'
- echo 'login.label login users in 5 mins.'
- #echo 'login.type DERIVE'
- #echo 'login.type COUNTER'
- echo 'longin.min 0'
- echo 'login.max 500000'
- exit 0
- fi
- #/usr/bin/printf "usres.value "
- #/usr/bin/mysql -B -e "select count(*) from users;" $MYSQLOPTS xxxdb 2>/dev/null | tail -n +2 | awk '{print $1}'
- #/usr/bin/printf "queries.value "
- #($MYSQLADMIN $MYSQLOPTS status 2>/dev/null || echo a a a a a a a a U) | awk '{print $9}'
- /usr/bin/printf "users.value "
- mysql -B -e "select count(*) from users;" $MYSQLOPTS xxxdb 2>/dev/null | tail -n +2 | awk '{print $1}'
- /usr/bin/printf "posts.value "
- mysql -B -e "select count(*) from posts;" $MYSQLOPTS xxxdb 2>/dev/null | tail -n +2 | awk '{print $1}'
- /usr/bin/printf "groups.value "
- mysql -B -e "select count(*) from groups;" $MYSQLOPTS xxxdb 2>/dev/null | tail -n +2 | awk '{print $1}'
- /usr/bin/printf "pages.value "
- mysql -B -e "select count(*) from pages;" $MYSQLOPTS xxxdb 2>/dev/null | tail -n +2 | awk '{print $1}'
- /usr/bin/printf "login.value "
- mysql -B -e "select count(*) from users where current_sign_in_at > date_sub(now(), interval 5 minute);" $MYSQLOPTS xxxdb 2>/dev/null | tail -n +2 | awk '{print $1}'
Add Comment
Please, Sign In to add comment