1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

Save with UNIX line breaks

This commit is contained in:
Stig Sandbeck Mathisen 2014-10-04 22:21:35 +02:00
parent 73e23cb7ba
commit 81fd4c97c3

View file

@ -1,153 +1,153 @@
#!/bin/bash #!/bin/bash
# #
# Munin plugin to monitor oracle connections w/o DBD::Oracle, or perl for that # Munin plugin to monitor oracle connections w/o DBD::Oracle, or perl for that
# matter ;-) # matter ;-)
# #
# Author: Kevin Kunkel (kunkel.kevin@gmail.com) on December 11, 2007 # Author: Kevin Kunkel (kunkel.kevin@gmail.com) on December 11, 2007
# (Based off the perl munin plugin by Joan Carles Soler) # (Based off the perl munin plugin by Joan Carles Soler)
# #
# Licenced under GPL v2. # Licenced under GPL v2.
# #
# Usage: # Usage:
# #
# If required, give username, password and/or oracle server # If required, give username, password and/or oracle server
# host through environment variables. # host through environment variables.
# #
# Parameters: # Parameters:
# autoconf # autoconf
# config (required) # config (required)
# #
# Config variables: # Config variables:
# #
# ORACLE_SID - Which database to use. Defaults to orcl # ORACLE_SID - Which database to use. Defaults to orcl
# oracle_user - A oracle user account with read permission to # oracle_user - A oracle user account with read permission to
# the v$session view. Defaults to # the v$session view. Defaults to
# 'oracle'. Anyway, Munin must be told which user # 'oracle'. Anyway, Munin must be told which user
# this plugin should be run as. # this plugin should be run as.
# oracle_pass - The corresponding password, if # oracle_pass - The corresponding password, if
# applicable. Default to undef. # applicable. Default to undef.
# #
# SHOW_ORACLE_USERS - If set to 1 show usernames and num. of connections. # SHOW_ORACLE_USERS - If set to 1 show usernames and num. of connections.
# Default is not show users (0). # Default is not show users (0).
# Magic markers # Magic markers
#%# family=auto #%# family=auto
#%# capabilities=autoconf #%# capabilities=autoconf
# Hard-code environment variables here # Hard-code environment variables here
#oracle_user= #oracle_user=
#oracle_pass= #oracle_pass=
#ORACLE_SID= #ORACLE_SID=
#ORACLE_HOME= #ORACLE_HOME=
#SHOW_ORACLE_USERS= #SHOW_ORACLE_USERS=
# End variable hard-code # End variable hard-code
if [ -z "$ORACLE_HOME" ] ; then if [ -z "$ORACLE_HOME" ] ; then
# Adjust to your oratab locations # Adjust to your oratab locations
for oratab in /var/opt/oracle/oratab /etc/oratab for oratab in /var/opt/oracle/oratab /etc/oratab
do do
[ ! -f $oratab ] && continue [ ! -f $oratab ] && continue
IFS=: IFS=:
while read SID HOME STARTUP; while read SID HOME STARTUP;
do do
if [ "$SID" = "*" ] if [ "$SID" = "*" ]
then then
ORACLE_HOME=$HOME ORACLE_HOME=$HOME
break break
fi fi
done < $oratab done < $oratab
[ -n "$ORACLE_HOME" ] && break [ -n "$ORACLE_HOME" ] && break
break break
done done
fi fi
if [ -z "$ORACLE_SID" ] if [ -z "$ORACLE_SID" ]
then then
ORACLE_SID="orcl" ORACLE_SID="orcl"
fi fi
if [ -z "$oracle_user" ] if [ -z "$oracle_user" ]
then then
oracle_user="oracle" oracle_user="oracle"
fi fi
if [ -z "$SHOW_ORACLE_USERS" ] if [ -z "$SHOW_ORACLE_USERS" ]
then then
SHOW_ORACLE_USERS=0 SHOW_ORACLE_USERS=0
else else
if [ $SHOW_ORACLE_USERS -ne 1 ] if [ $SHOW_ORACLE_USERS -ne 1 ]
then then
SHOW_ORACLE_USERS=0 SHOW_ORACLE_USERS=0
fi fi
fi fi
PATH=$PATH:$ORACLE_HOME/bin PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_HOME PATH ORACLE_SID export ORACLE_HOME PATH ORACLE_SID
if [ "$1" = "autoconf" ] if [ "$1" = "autoconf" ]
then then
echo yes echo yes
exit 0 exit 0
fi fi
if [ "$1" = "config" ] if [ "$1" = "config" ]
then then
WARN_CRIT=`sqlplus -s ${oracle_user}/${oracle_pass}@$ORACLE_SID << EOF | \ WARN_CRIT=`sqlplus -s ${oracle_user}/${oracle_pass}@$ORACLE_SID << EOF | \
grep -v '^$' | awk '{print $1 * 0.7 " " $1 * 0.8 }' grep -v '^$' | awk '{print $1 * 0.7 " " $1 * 0.8 }'
set pagesize 0 set pagesize 0
select value from v\\$parameter where name = 'sessions'; select value from v\\$parameter where name = 'sessions';
EOF` EOF`
echo "graph_title Oracle active connections to $ORACLE_SID" echo "graph_title Oracle active connections to $ORACLE_SID"
echo "graph_args -l 0 --base 1000" echo "graph_args -l 0 --base 1000"
echo "graph_vlabel Connections" echo "graph_vlabel Connections"
echo "graph_category Oracle" echo "graph_category Oracle"
echo "graph_info Shows active oracle connections to $ORACLE_SID" echo "graph_info Shows active oracle connections to $ORACLE_SID"
echo "graph_scale no" echo "graph_scale no"
if [ $SHOW_ORACLE_USERS -eq 1 ] if [ $SHOW_ORACLE_USERS -eq 1 ]
then then
sqlplus -s ${oracle_user}/${oracle_pass}@$ORACLE_SID << EOF | \ sqlplus -s ${oracle_user}/${oracle_pass}@$ORACLE_SID << EOF | \
grep -v '^$' | awk '{ print $1 ".label " $1 " active connections" grep -v '^$' | awk '{ print $1 ".label " $1 " active connections"
print $1 ".info " $1 " active connections" print $1 ".info " $1 " active connections"
print $1 ".type GAUGE" }; END { print $1 ".type GAUGE" }; END {
print "total.label active connections" print "total.label active connections"
print "total.info active connections" print "total.info active connections"
print "total.type GAUGE" print "total.type GAUGE"
}' }'
set pagesize 0 set pagesize 0
select username, count(username) from v\$session where username is not null group by username; select username, count(username) from v\$session where username is not null group by username;
EOF EOF
echo $WARN_CRIT| awk '{ print "total.warning " $1 "\ntotal.critical " $2 }' echo $WARN_CRIT| awk '{ print "total.warning " $1 "\ntotal.critical " $2 }'
else else
echo "connections.label active connections" echo "connections.label active connections"
echo "connections.info active connections" echo "connections.info active connections"
echo "connections.type GAUGE" echo "connections.type GAUGE"
echo $WARN_CRIT| awk '{ print "connections.warning " $1 "\nconnections.critical " $2 }' echo $WARN_CRIT| awk '{ print "connections.warning " $1 "\nconnections.critical " $2 }'
fi fi
fi fi
if [ $SHOW_ORACLE_USERS -eq 1 ] if [ $SHOW_ORACLE_USERS -eq 1 ]
then then
sqlplus -s ${oracle_user}/${oracle_pass}@$ORACLE_SID << EOF | \ sqlplus -s ${oracle_user}/${oracle_pass}@$ORACLE_SID << EOF | \
grep -v '^$'|awk 'BEGIN { total=0 } { grep -v '^$'|awk 'BEGIN { total=0 } {
print $1 ".value " $2 print $1 ".value " $2
total=total+$2 } END { print "total.value " total }' total=total+$2 } END { print "total.value " total }'
set pagesize 0 set pagesize 0
select username, count(username) from v\$session where username is not null group by username; select username, count(username) from v\$session where username is not null group by username;
EOF EOF
else else
sqlplus -s ${oracle_user}/${oracle_pass}@$ORACLE_SID << EOF | grep -v '^$'|\ sqlplus -s ${oracle_user}/${oracle_pass}@$ORACLE_SID << EOF | grep -v '^$'|\
awk '{ print "connections.value " $1 }' awk '{ print "connections.value " $1 }'
set pagesize 0 set pagesize 0
select count(username) from v\$session where username is not null; select count(username) from v\$session where username is not null;
EOF EOF
fi fi
echo "max_connections.value" "`sqlplus -s ${oracle_user}/${oracle_pass}@$ORACLE_SID << EOF | \ echo "max_connections.value" "`sqlplus -s ${oracle_user}/${oracle_pass}@$ORACLE_SID << EOF | \
grep -v '^$' | awk '{print $1 }' grep -v '^$' | awk '{print $1 }'
set pagesize 0 set pagesize 0
select value from v\\$parameter where name = 'sessions'; select value from v\\$parameter where name = 'sessions';
EOF`" EOF`"