Editing Talk:Monitoring /proc/user beancounters with nagios

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
 
{{DISPLAYTITLE:Monitoring /proc/user_beancounters with email}}
 
{{DISPLAYTITLE:Monitoring /proc/user_beancounters with email}}
 +
To be added locally on the VZ HN to
  
== Introduction ==
+
Works as nagios-plugin with option '-f' or reports an increase of a failcnt-value by mail if run e.g. as a cronjob with option '-t'. We use it with both cases to be sure that we see a peak in case it happened between the nagios-checks.
  
This script gives a warning if any parameter in a virtual environment (VZ) exceeds 80% of resources.
+
<source lang=python>
 +
#!/usr/bin/python
 +
# Copyright (C) 2008 Christian Benke
 +
# Distributed under the terms of the GNU General Public License v2
 +
# v0.2 2008-04-04
 +
# Christian Benke <benkokakao  gmail  com>
  
== packages basic installation ==
+
import string
<pre>
+
import pickle
  aptitude install nail gawk
+
import sys
</pre>
+
import getopt
 +
import re
  
== nail configuration ==
+
veid=''
  Configures  <code> /etc/nailrc </code> or <code> ~/.mailrc </code> files.
+
current_data=dict()
<pre>
 
set smtp=smtp.server.org
 
set from=nail@smtp.server.org
 
set charset=iso-8859-1
 
</pre>
 
 
 
== configuration ==
 
 
 
Copy the script and configure the <code> /etc/crontab </code>
 
 
 
== Script resource ==
 
 
 
<source lang=bash>
 
#!/bin/bash resource.sh
 
# Copyright (C) 2008 Mgual
 
# Distributed under to GNU General Public License v2
 
# v0.1 2008-08-13
 
# Ajuntament de Benicarló
 
 
 
 
 
 
 
#!/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"
 
                }
 
        '
 
 
 
 
 
# 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 [[ "$(cat /tmp/beancounters | wc -l)" != "5"  ]] ; then
 
        cat /tmp/beancounters  |  nail -s "Server:resource.sh Warning " user@smtp-server.org
 
fi
 

Please note that all contributions to OpenVZ Virtuozzo Containers Wiki may be edited, altered, or removed by other contributors. If you don't want your writing to be edited mercilessly, then don't submit it here.
If you are going to add external links to an article, read the External links policy first!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)