Difference between revisions of "Talk:Monitoring /proc/user beancounters with nagios"

From OpenVZ Virtuozzo Containers Wiki
Jump to: navigation, search
m (Reverted edits by 121.12.175.21 (Talk) to last revision by Mgual)
 
(4 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
== Introduction ==
 
== Introduction ==
  
This script gives a warning if any parameter in a virtual environment (VZ) exceed 80% of resources.
+
This script gives a warning if any parameter in a virtual environment (VZ) exceeds 80% of resources.
  
 
== packages basic installation ==
 
== packages basic installation ==
Line 20: Line 20:
 
== configuration ==
 
== configuration ==
  
Copy the script and configure <code> /etc/crontab </code>
+
Copy the script and configure the <code> /etc/crontab </code>
  
 
== Script resource ==
 
== Script resource ==
Line 27: Line 27:
 
#!/bin/bash resource.sh
 
#!/bin/bash resource.sh
 
# Copyright (C) 2008 Mgual
 
# Copyright (C) 2008 Mgual
# Distributed under to GNU General Public License v3
+
# Distributed under to GNU General Public License v2
 
# v0.1 2008-08-13
 
# v0.1 2008-08-13
 
# Ajuntament de Benicarló
 
# Ajuntament de Benicarló
Line 35: Line 35:
 
#!/bin/bash
 
#!/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 '
+
 
 +
gawk ' BEGIN {
 +
                printf "%3s %-20s %3s %3s \n", "ID", "Parameter", "%bar", "%lim" > "/tmp/beancounters"
 +
        }
 +
 
 
         /dummy/||/Version/||/uid/ { next }
 
         /dummy/||/Version/||/uid/ { next }
 
         ! /:/ {
 
         ! /:/ {
Line 71: Line 70:
 
                 printf "%-20s %3d %3d ", RESOURCE , PBARRIER, PLIMIT
 
                 printf "%-20s %3d %3d ", RESOURCE , PBARRIER, PLIMIT
 
                 if (PBARRIER>=80)  {
 
                 if (PBARRIER>=80)  {
                         printf " Perill "
+
                         printf " Warning "
 
                         printf "%3d %-20s %3d %3d Perill\n", VZ, RESOURCE , PBARRIER, PLIMIT >> "/tmp/beancounters"
 
                         printf "%3d %-20s %3d %3d Perill\n", VZ, RESOURCE , PBARRIER, PLIMIT >> "/tmp/beancounters"
 
                 }
 
                 }
Line 79: Line 78:
  
 
echo "---------------------------------------------------" >> /tmp/beancounters
 
echo "---------------------------------------------------" >> /tmp/beancounters
echo "" | gawk -vVZ='ID' -vRESOURCE='Use%' '
+
echo "" | gawk -vVZ='ID' -vRESOURCE='Use Disc%' '
 
               {
 
               {
 
                         printf "%3s %-20s \n", VZ, RESOURCE  >> "/tmp/beancounters"
 
                         printf "%3s %-20s \n", VZ, RESOURCE  >> "/tmp/beancounters"
Line 95: Line 94:
  
 
echo "---------------------------------------------------" >> /tmp/beancounters
 
echo "---------------------------------------------------" >> /tmp/beancounters
echo "" | gawk -vVZ='ID' -vRESOURCE='IUse%' '
+
echo "" | gawk -vVZ='ID' -vRESOURCE='IUse Disc%' '
 
               {
 
               {
 
                         printf "%3s %-20s \n", VZ, RESOURCE  >> "/tmp/beancounters"
 
                         printf "%3s %-20s \n", VZ, RESOURCE  >> "/tmp/beancounters"
Line 108: Line 107:
  
 
if [[ "$(cat /tmp/beancounters | wc -l)" != "5"  ]] ; then
 
if [[ "$(cat /tmp/beancounters | wc -l)" != "5"  ]] ; then
         cat /tmp/beancounters  |  nail -s Server:resource.sh perill@smtp-server.org
+
         cat /tmp/beancounters  |  nail -s "Server:resource.sh Warning " user@smtp-server.org
 
fi
 
fi

Latest revision as of 17:16, 12 October 2010


Introduction[edit]

This script gives a warning if any parameter in a virtual environment (VZ) exceeds 80% of resources.

packages basic installation[edit]

  aptitude install nail gawk 

nail configuration[edit]

 Configures    /etc/nailrc  or  ~/.mailrc  files.
set smtp=smtp.server.org
set from=nail@smtp.server.org
set charset=iso-8859-1

configuration[edit]

Copy the script and configure the /etc/crontab

Script resource[edit]

<source lang=bash>

  1. !/bin/bash resource.sh
  2. Copyright (C) 2008 Mgual
  3. Distributed under to GNU General Public License v2
  4. v0.1 2008-08-13
  5. Ajuntament de Benicarló


  1. !/bin/bash


gawk ' BEGIN {

               printf "%3s %-20s %3s %3s \n", "ID", "Parameter", "%bar", "%lim" > "/tmp/beancounters"
       }
       /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 " Warning "
                       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 Disc%' '

              {
                       printf "%3s %-20s \n", VZ, RESOURCE  >> "/tmp/beancounters"
               }
       '


  1. 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 Disc%' '

              {
                       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 Warning " user@smtp-server.org

fi