Difference between revisions of "Talk:Monitoring /proc/user beancounters with nagios"
Line 5: | Line 5: | ||
− | <source lang= | + | <source lang=bash> |
#!/bin/bash | #!/bin/bash | ||
# Copyright (C) 2008 Mgual | # Copyright (C) 2008 Mgual | ||
− | # Distributed under GNU General Public License v3 | + | # Distributed under to GNU General Public License v3 |
− | # v0.2 2008- | + | # v0.2 2008-08-13 |
− | # | + | # Miquel Gual Torner |
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | #!/bin/bash | |
− | + | ||
+ | echo "" | gawk -vVZ='ID' -vRESOURCE='Parametre' -vPBARRIER='%bar' -vPLIMIT='%lim' ' | ||
+ | { | ||
+ | printf "%3s %-20s %3s %3s \n", VZ, RESOURCE , PBARRIER, PLIMIT > "/tmp/beancounters" | ||
+ | } | ||
+ | ' | ||
+ | |||
+ | gawk ' | ||
+ | /dummy/||/Version/||/uid/ { next } | ||
+ | ! /:/ { | ||
+ | RESOURCE=$1 | ||
+ | MAXHELD=$3 | ||
+ | BARRIER=$4 | ||
+ | LIMIT=$5 | ||
+ | } | ||
+ | /:/ { gsub(/:/, "", $1) | ||
+ | printf "------- %s ------- \n",$1 | ||
+ | VZ=$1 | ||
+ | RESOURCE=$2 | ||
+ | MAXHELD=$4 | ||
+ | BARRIER=$5 | ||
+ | LIMIT=$6 | ||
+ | } | ||
+ | { | ||
+ | #printf "R=%s M=%s B=%s L=%s ", RESOURCE, MAXHELD, BARRIER, LIMIT | ||
+ | if (BARRIER>0) { | ||
+ | PBARRIER=MAXHELD*100/BARRIER | ||
+ | } else { | ||
+ | PBARRIER=0 | ||
+ | } | ||
+ | if (LIMIT>0) { | ||
+ | PLIMIT=MAXHELD*100/LIMIT | ||
+ | } else { | ||
+ | PLIMIT=0 | ||
+ | } | ||
+ | printf "%-20s %3d %3d ", RESOURCE , PBARRIER, PLIMIT | ||
+ | if (PBARRIER>=80) { | ||
+ | printf " Perill " | ||
+ | printf "%3d %-20s %3d %3d Perill\n", VZ, RESOURCE , PBARRIER, PLIMIT >> "/tmp/beancounters" | ||
+ | } | ||
+ | printf "\n" | ||
+ | } | ||
+ | ' /proc/user_beancounters | ||
+ | |||
+ | echo "---------------------------------------------------" >> /tmp/beancounters | ||
+ | echo "" | gawk -vVZ='ID' -vRESOURCE='Use%' ' | ||
+ | { | ||
+ | printf "%3s %-20s \n", VZ, RESOURCE >> "/tmp/beancounters" | ||
+ | } | ||
+ | ' | ||
+ | |||
+ | |||
+ | # Quota Disc | ||
+ | |||
+ | for i in $(vzlist | cut -d" " -f 8) | ||
+ | do | ||
+ | vzctl exec $i df -h | gawk -vVEID=$i '/^simfs/ { if ($5 > "80%") { printf "%s %s\n", VEID, $5 } }' >>/tmp/beancounters | ||
+ | |||
+ | done | ||
+ | |||
+ | echo "---------------------------------------------------" >> /tmp/beancounters | ||
+ | echo "" | gawk -vVZ='ID' -vRESOURCE='IUse%' ' | ||
+ | { | ||
+ | printf "%3s %-20s \n", VZ, RESOURCE >> "/tmp/beancounters" | ||
+ | } | ||
+ | ' | ||
+ | for i in $(vzlist | cut -d" " -f 8) | ||
+ | do | ||
+ | vzctl exec $i df -i | gawk -vVEID=$i '/^simfs/ { if ($5 > "80%") { printf "%s %s\n", VEID, $5 } }' >>/tmp/beancounters | ||
+ | |||
+ | done | ||
+ | |||
+ | |||
+ | if [[ "$(cat /tmp/beancounters | wc -l)" != "5" ]] ; then | ||
+ | cat /tmp/beancounters | nail -s Server:resource.sh perill@smtp-server.org | ||
+ | fi |
Revision as of 10:44, 13 August 2008
To be added locally on the VZ HN to /etc/crontab
to script resource.sh
<source lang=bash>
- !/bin/bash
- Copyright (C) 2008 Mgual
- Distributed under to GNU General Public License v3
- v0.2 2008-08-13
- Miquel Gual Torner
- !/bin/bash
echo "" | gawk -vVZ='ID' -vRESOURCE='Parametre' -vPBARRIER='%bar' -vPLIMIT='%lim' '
{ printf "%3s %-20s %3s %3s \n", VZ, RESOURCE , PBARRIER, PLIMIT > "/tmp/beancounters" } '
gawk '
/dummy/||/Version/||/uid/ { next } ! /:/ { RESOURCE=$1 MAXHELD=$3 BARRIER=$4 LIMIT=$5 } /:/ { gsub(/:/, "", $1) printf "------- %s ------- \n",$1 VZ=$1 RESOURCE=$2 MAXHELD=$4 BARRIER=$5 LIMIT=$6 } { #printf "R=%s M=%s B=%s L=%s ", RESOURCE, MAXHELD, BARRIER, LIMIT if (BARRIER>0) { PBARRIER=MAXHELD*100/BARRIER } else { PBARRIER=0 } if (LIMIT>0) { PLIMIT=MAXHELD*100/LIMIT } else { PLIMIT=0 } printf "%-20s %3d %3d ", RESOURCE , PBARRIER, PLIMIT if (PBARRIER>=80) { printf " Perill " printf "%3d %-20s %3d %3d Perill\n", VZ, RESOURCE , PBARRIER, PLIMIT >> "/tmp/beancounters" } printf "\n" } ' /proc/user_beancounters
echo "---------------------------------------------------" >> /tmp/beancounters echo "" | gawk -vVZ='ID' -vRESOURCE='Use%' '
{ printf "%3s %-20s \n", VZ, RESOURCE >> "/tmp/beancounters" } '
- Quota Disc
for i in $(vzlist | cut -d" " -f 8) do
vzctl exec $i df -h | gawk -vVEID=$i '/^simfs/ { if ($5 > "80%") { printf "%s %s\n", VEID, $5 } }' >>/tmp/beancounters
done
echo "---------------------------------------------------" >> /tmp/beancounters echo "" | gawk -vVZ='ID' -vRESOURCE='IUse%' '
{ printf "%3s %-20s \n", VZ, RESOURCE >> "/tmp/beancounters" } '
for i in $(vzlist | cut -d" " -f 8) do
vzctl exec $i df -i | gawk -vVEID=$i '/^simfs/ { if ($5 > "80%") { printf "%s %s\n", VEID, $5 } }' >>/tmp/beancounters
done
if wc -l)" != "5" ; then
cat /tmp/beancounters | nail -s Server:resource.sh perill@smtp-server.org
fi