Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
Check cpu, men and pagin space for AIX
1.0
2011-02-08
- Nagios 2.x
- Nagios 3.x
99301
File | Description |
---|---|
check_aix_cpu.sh | check_aix_cpu.sh |
check_aix_mem.sh | check_aix_mem.sh |
Meet The New Nagios Core Services Platform
Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.
Monitoring Made Magically Better
- Nagios Core on Overdrive
- Powerful Monitoring Dashboards
- Time-Saving Configuration Wizards
- Open Source Powered Monitoring On Steroids
- And So Much More!
- cpu (cumul,us,sy,id,wa,pc).
- mem (srfr,numperm,pctused).
- pagin space.
Reviews (3)
Please find my fix below:
....
....
....
retour_srfr=$(vmstat 1 2 | awk '{ print $8" "$9 }' | tail -1)
fr=$(echo $retour_srfr | cut -d " " -f1 )
sr=$(echo $retour_srfr | cut -d " " -f2 )
retour_numperm=$(vmstat -v | grep numperm | sed 's/ //g' | cut -d " " -f 2)
retour_inuse=$(svmon | awk '{ print $3 }' | head -2 | tail -1)
retour_memory=$(svmon | awk '{ print $2 }' | head -2 | tail -1)
retour_pguse=$(svmon | grep "pg space" | awk '{ print $4 }')
retour_pgsize=$(svmon | grep "pg space" | awk '{ print $3 }')
....
....
....
pgspaceused)
retour_pg_used=$(expr 100 \* $retour_pguse \/ $retour_pgsize)
str_out="$str_out $retour_pg_used% "
if (( $retour_pg_used > $valw))
then
ok=1
fi
if (( $retour_pg_used > $valc))
then
ok=2
fi
# Sortie au format perfparse
echo "$str_out PgSpaceUsed = $retour_pg_used%;| PgSpaceUsed=$retour_pg_used%;$valw;$valc"; exit $ok
;;
esac
....
....
....
....
....
....
retour_srfr=$(vmstat 1 2 | awk '{ print $8" "$9 }' | tail -1)
fr=$(echo $retour_srfr | cut -d " " -f1 )
sr=$(echo $retour_srfr | cut -d " " -f2 )
retour_numperm=$(vmstat -v | grep numperm | sed 's/ //g' | cut -d " " -f 2)
retour_inuse=$(svmon | awk '{ print $3 }' | head -2 | tail -1)
retour_memory=$(svmon | awk '{ print $2 }' | head -2 | tail -1)
retour_pguse=$(svmon | grep "pg space" | awk '{ print $4 }')
retour_pgsize=$(svmon | grep "pg space" | awk '{ print $3 }')
....
....
....
pgspaceused)
retour_pg_used=$(expr 100 \* $retour_pguse \/ $retour_pgsize)
str_out="$str_out $retour_pg_used% "
if (( $retour_pg_used > $valw))
then
ok=1
fi
if (( $retour_pg_used > $valc))
then
ok=2
fi
# Sortie au format perfparse
echo "$str_out PgSpaceUsed = $retour_pg_used%;| PgSpaceUsed=$retour_pg_used%;$valw;$valc"; exit $ok
;;
esac
....
....
....
bylucup, February 27, 2015
1 of 1 people found this review helpful
Hi, good!
But just you can improve the performance of the script avoiding the first step where you execute all the systems commands invocation. If you move them to each select cases. Cosider that in the firs option: srfr the (vmstat 1 2) is too slow, so if you want to execute the orther options: numperm|pctused|pgspaceused, is better to avoid the invocation of the (vmstat 1 2), just invoking the vmstat -v that is faster. :-)
So here the script modified:
-----------------------------------------------------------------------------
#!/bin/sh
#
#-------------------------------------------------------
# Check du taux d'utilisation mmemoie sur AIX - Fabrice Dupre - 11/01/08
# Moving the systems command invocation to each select cases. - LUCUP - Lucas Moreschi - 27/02/2015.
#-------------------------------------------------------
Syntaxe() {
echo " "
echo " Command Syntaxe: check_aix_mem.sh [-c val] [-w val] [-t srfr|numperm|pctused|pgspaceused]"
echo " "
exit 3;
}
#-------------------------------------------------------
if [[ $# == 0 ]]
then
Syntaxe
fi
valw=0
valc=0
while [[ $# > 0 ]]
do
par=$1
case $par in
-c) shift
valc=$1;;
-w) shift
valw=$1;;
-t) shift
type_sortie=$1;;
-h) shift
Syntaxe
exit;;
*) shift;;
esac
done
ok=0
str_out="CHARGE MEM:"
xcpu=0
total=0
case $type_sortie in
srfr)
retour_srfr=$(vmstat 1 2 | awk '{ print $8" "$9 }' | tail -1)
fr=$(echo $retour_srfr | cut -d " " -f1 )
sr=$(echo $retour_srfr | cut -d " " -f2 )
#echo "sr : $sr - fr : $fr"
if [[ $sr -gt 0 ]] && [[ $fr -gt 0 ]]
then
str_out="$str_out $(expr $sr \/ $fr)% "
if (( $(expr $sr \/ $fr) > $valw ))
then
ok=1
fi
if (( $(expr $sr \/ $fr) > $valc ))
then
ok=2
fi
# Sortie au format perfparse
echo "$str_out Srfr = $(expr $sr \/ $fr)%;| Srfr=$(expr $sr \/ $fr)%;$valw;$valc"; exit $ok
# Sortie au format non perfparse
#echo "$str_out Srfr = $(expr $sr \/ $fr)%"; exit $ok
else
str_out="$str_out 0% "
# Sortie au format perfparse
echo "$str_out Srfr = 0%;| Srfr=0%;$valw;$valc"; exit $ok
# Sortie au format non perfparse
#echo "$str_out Srfr = 0%;"; exit $ok
fi
;;
numperm)
retour_numperm=$(vmstat -v | grep numperm | sed 's/ //g' | cut -d " " -f 2)
#echo "Numperm : $retour_numperm"
str_out="$str_out $retour_numperm% "
if (( $retour_numperm > $valw ))
then
ok=1
fi
if (( $retour_numperm > $valc))
then
ok=2
fi
# Sortie au format perfparse
echo "$str_out Numperm = $retour_numperm%;| Numperm=$retour_numperm%;$valw;$valc"; exit $ok
;;
pctused)
retour_inuse=$(svmon | awk '{ print $3 }' | head -2 | tail -1)
retour_memory=$(svmon | awk '{ print $2 }' | head -2 | tail -1)
retour_p_used=$(expr 100 \* $retour_inuse \/ $retour_memory)
str_out="$str_out $retour_p_used% "
if (( $retour_p_used > $valw))
then
ok=1
fi
if (( $retour_p_used > $valc))
then
ok=2
fi
# Sortie au format perfparse
echo "$str_out MemUsed = $retour_p_used%;| MemUsed=$retour_p_used%;$valw;$valc"; exit $ok
;;
pgspaceused)
retour_pguse=$(svmon | grep "pg space" | awk '{ print $3 }')
retour_memory=$(svmon | awk '{ print $2 }' | head -2 | tail -1)
retour_pg_used=$(expr 100 \* $retour_pguse \/ $retour_memory)
str_out="$str_out $retour_pg_used% "
if (( $retour_pg_used > $valw))
then
ok=1
fi
if (( $retour_pg_used > $valc))
then
ok=2
fi
# Sortie au format perfparse
echo "$str_out PgSpaceUsed = $retour_pg_used%;| PgSpaceUsed=$retour_pg_used%;$valw;$valc"; exit $ok
;;
esac
But just you can improve the performance of the script avoiding the first step where you execute all the systems commands invocation. If you move them to each select cases. Cosider that in the firs option: srfr the (vmstat 1 2) is too slow, so if you want to execute the orther options: numperm|pctused|pgspaceused, is better to avoid the invocation of the (vmstat 1 2), just invoking the vmstat -v that is faster. :-)
So here the script modified:
-----------------------------------------------------------------------------
#!/bin/sh
#
#-------------------------------------------------------
# Check du taux d'utilisation mmemoie sur AIX - Fabrice Dupre - 11/01/08
# Moving the systems command invocation to each select cases. - LUCUP - Lucas Moreschi - 27/02/2015.
#-------------------------------------------------------
Syntaxe() {
echo " "
echo " Command Syntaxe: check_aix_mem.sh [-c val] [-w val] [-t srfr|numperm|pctused|pgspaceused]"
echo " "
exit 3;
}
#-------------------------------------------------------
if [[ $# == 0 ]]
then
Syntaxe
fi
valw=0
valc=0
while [[ $# > 0 ]]
do
par=$1
case $par in
-c) shift
valc=$1;;
-w) shift
valw=$1;;
-t) shift
type_sortie=$1;;
-h) shift
Syntaxe
exit;;
*) shift;;
esac
done
ok=0
str_out="CHARGE MEM:"
xcpu=0
total=0
case $type_sortie in
srfr)
retour_srfr=$(vmstat 1 2 | awk '{ print $8" "$9 }' | tail -1)
fr=$(echo $retour_srfr | cut -d " " -f1 )
sr=$(echo $retour_srfr | cut -d " " -f2 )
#echo "sr : $sr - fr : $fr"
if [[ $sr -gt 0 ]] && [[ $fr -gt 0 ]]
then
str_out="$str_out $(expr $sr \/ $fr)% "
if (( $(expr $sr \/ $fr) > $valw ))
then
ok=1
fi
if (( $(expr $sr \/ $fr) > $valc ))
then
ok=2
fi
# Sortie au format perfparse
echo "$str_out Srfr = $(expr $sr \/ $fr)%;| Srfr=$(expr $sr \/ $fr)%;$valw;$valc"; exit $ok
# Sortie au format non perfparse
#echo "$str_out Srfr = $(expr $sr \/ $fr)%"; exit $ok
else
str_out="$str_out 0% "
# Sortie au format perfparse
echo "$str_out Srfr = 0%;| Srfr=0%;$valw;$valc"; exit $ok
# Sortie au format non perfparse
#echo "$str_out Srfr = 0%;"; exit $ok
fi
;;
numperm)
retour_numperm=$(vmstat -v | grep numperm | sed 's/ //g' | cut -d " " -f 2)
#echo "Numperm : $retour_numperm"
str_out="$str_out $retour_numperm% "
if (( $retour_numperm > $valw ))
then
ok=1
fi
if (( $retour_numperm > $valc))
then
ok=2
fi
# Sortie au format perfparse
echo "$str_out Numperm = $retour_numperm%;| Numperm=$retour_numperm%;$valw;$valc"; exit $ok
;;
pctused)
retour_inuse=$(svmon | awk '{ print $3 }' | head -2 | tail -1)
retour_memory=$(svmon | awk '{ print $2 }' | head -2 | tail -1)
retour_p_used=$(expr 100 \* $retour_inuse \/ $retour_memory)
str_out="$str_out $retour_p_used% "
if (( $retour_p_used > $valw))
then
ok=1
fi
if (( $retour_p_used > $valc))
then
ok=2
fi
# Sortie au format perfparse
echo "$str_out MemUsed = $retour_p_used%;| MemUsed=$retour_p_used%;$valw;$valc"; exit $ok
;;
pgspaceused)
retour_pguse=$(svmon | grep "pg space" | awk '{ print $3 }')
retour_memory=$(svmon | awk '{ print $2 }' | head -2 | tail -1)
retour_pg_used=$(expr 100 \* $retour_pguse \/ $retour_memory)
str_out="$str_out $retour_pg_used% "
if (( $retour_pg_used > $valw))
then
ok=1
fi
if (( $retour_pg_used > $valc))
then
ok=2
fi
# Sortie au format perfparse
echo "$str_out PgSpaceUsed = $retour_pg_used%;| PgSpaceUsed=$retour_pg_used%;$valw;$valc"; exit $ok
;;
esac
Hi,
just noticed that the calculation of used Paging Space is done wrong:
expr 100 * / ps_size
It should be:
expr 100 * / ps_size
Or you could just grab the used size in percent from the output of "lsps -a".
Also expr does not allow floats which will cause a problem anyway. awk will work.
Multiple allocated Paging Spaces are pretty but could happen and are not considered.
Cheers
zaxxon
just noticed that the calculation of used Paging Space is done wrong:
expr 100 * / ps_size
It should be:
expr 100 * / ps_size
Or you could just grab the used size in percent from the output of "lsps -a".
Also expr does not allow floats which will cause a problem anyway. awk will work.
Multiple allocated Paging Spaces are pretty but could happen and are not considered.
Cheers
zaxxon