"Fossies" - the Fresh Open Source Software Archive 
Member "mosshe/functions.virtual" (12 Jun 2016, 9239 Bytes) of package /linux/privat/old/mosshe.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 #!/bin/sh
2
3 #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
4 #
5 # function library - please call with external script
6 #
7 #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
8
9 #############################################################################
10 # MoSSHe: remote server monitoring environment
11 #
12 # Copyright (C) 2003- Volker Tanger
13 #
14 # This program is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
18 #
19 # For bug reports and suggestions or if you just want to talk to me please
20 # contact me at volker.tanger@wyae.de
21 #
22 # Updates will be available at http://www.wyae.de/software/mosshe/
23 # please check there for updates prior to submitting patches!
24 #
25 # For list of changes please refer to the HISTORY file. Thanks.
26 #############################################################################
27
28
29
30 ################################################################
31 ### Linux VServer functions
32 ################################################################
33
34 #40001 11 731.5M 140.8M 1m16s69 0m57s64 2h50m31 fraktion
35 # 40002 5 141.6M 4.1M 0m07s00 0m18s14 53m49s96 crystal
36 # DF=`df -Plm | fgrep "$HD" `
37
38 #---------------------------------------------------------
39 # CheckVserverUp SERVERNAME - returns
40 #---------------------------------------------------------
41 CheckVserverUp () {
42 VSRV="$1"
43 MossheLog "CheckVserverUp $VSRV"
44 if ! [ -x /usr/sbin/vserver-stat ]; then
45 CODE=1
46 echo "${DATIM};$MYGROUP;$VSRV;CheckVserverUp;UNDEF;0;VSERVER-UTILS not installed - cannot check $VSRV" >> $TEMPDIR/tmp.$$.collected.tmp
47 else
48 RTN=`/usr/sbin/vserver-stat`
49 VRTN=`/usr/sbin/vserver-stat | fgrep $VSRV | sed -e "s/ */ /g"`
50 if [ -z "$RTN" ]; then
51 CODE=2
52 MESSAGE="something's wrong with VServer status"
53 STATUS="WARN"
54 elif [ -n "$VRTN" ]; then
55 CODE=0
56 MESSAGE="VServer $VSRV up: $VRTN"
57 STATUS="OK"
58 else
59 CODE=3
60 MESSAGE="VServer $VSRV down"
61 STATUS="ALERT"
62 fi
63 echo "${DATIM};$MYGROUP;$VSRV;CheckVserverUp;$STATUS;$CODE;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
64 fi
65 }
66
67
68 #---------------------------------------------------------
69 # CheckVserverDown SERVERNAME - returns
70 #---------------------------------------------------------
71 CheckVserverDown () {
72 VSRV="$1"
73 MossheLog "CheckVserverDown $VSRV"
74 if ! [ -x /usr/sbin/vserver-stat ]; then
75 CODE=1
76 echo "${DATIM};$MYGROUP;$VSRV;CheckVserverDown;UNDEF;0;VSERVER-UTILS not installed - cannot check $VSRV" >> $TEMPDIR/tmp.$$.collected.tmp
77 else
78 RTN=`/usr/sbin/vserver-stat`
79 VRTN=`/usr/sbin/vserver-stat | fgrep $VSRV | sed -e "s/ */ /g"`
80 if [ -z "$RTN" ]; then
81 CODE=2
82 MESSAGE="something's wrong with VServer status"
83 STATUS="WARN"
84 elif [ -n "$VRTN" ]; then
85 CODE=3
86 MESSAGE="VServer $VSRV unexpectedly up: $VRTN"
87 STATUS="ALERT"
88 else
89 CODE=0
90 MESSAGE="VServer $VSRV still down as expected"
91 STATUS="OK"
92 fi
93 echo "${DATIM};$MYGROUP;$VSRV;CheckVserverDown;$STATUS;$CODE;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
94 fi
95 }
96
97 #---------------------------------------------------------
98 # VserverLoad SERVERNR SERVERNAME WARN ALERT
99 #---------------------------------------------------------
100 VserverLoad () {
101 VSRV="$1"
102 VSNAM="$2"
103 typeset -i WARN="$3"
104 typeset -i ALERT="$4"
105 typeset -i LOAD
106 MossheLog "VserverLoad $VSNAM"
107 if ! [ -e /proc/virtual/${VSRV}/cvirt ]; then
108 echo "${DATIM};$MYGROUP;$VSNAM;VserverLoad (general);UNDEF;0;VSERVER $VSRV not running - cannot check its load" >> $TEMPDIR/tmp.$$.collected.tmp
109 else
110 MESSAGE=`fgrep loadavg /proc/virtual/${VSRV}/cvirt | cut -c 10-13`
111 LOAD=`echo $MESSAGE | sed -e "s/\.//" | sed -e "s/^0*//g"`
112 STATUS="OK"
113 STAT="Normal Load";
114 if [ $LOAD -ge $WARN ]; then STATUS="WARN"; STAT="High Load"; fi
115 if [ $LOAD -ge $ALERT ]; then STATUS="ALERT"; STAT="Critical Load"; fi
116 echo "${DATIM};$MYGROUP;$VSNAM;VserverLoad;$STATUS;$LOAD;$STAT: $MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
117 fi
118 }
119
120 ################################################################
121 ### Virtuzzo / OpenVZ beancounter checks
122 ################################################################
123
124 # root@strato:~# cat /proc/user_beancounters
125 #Version: 2.5
126 # uid resource held maxheld barrier limit failcnt
127 # 2173448: kmemsize 54355729 79167488 9223372036854775807 9223372036854775807 0
128 # lockedpages 0 0 524288 524288 0
129 # privvmpages 112366 135711 9223372036854775807 9223372036854775807 0
130 # shmpages 1280 1296 9223372036854775807 9223372036854775807 0
131 # dummy 0 0 9223372036854775807 9223372036854775807 0
132 # numproc 65 105 9223372036854775807 9223372036854775807 0
133 # physpages 80202 524290 524288 524288 0
134 # vmguarpages 0 0 524288 524288 0
135 # oomguarpages 18641 19270 524288 524288 0
136 # numtcpsock 10 33 9223372036854775807 9223372036854775807 0
137 # numflock 4 10 9223372036854775807 9223372036854775807 0
138 # numpty 2 3 9223372036854775807 9223372036854775807 0
139 # numsiginfo 0 30 9223372036854775807 9223372036854775807 0
140 # tcpsndbuf 357784 1128512 9223372036854775807 9223372036854775807 0
141 # tcprcvbuf 163840 2712192 9223372036854775807 9223372036854775807 0
142 # othersockbuf 26672 180352 9223372036854775807 9223372036854775807 0
143 # dgramrcvbuf 0 2576 9223372036854775807 9223372036854775807 0
144 # numothersock 73 85 9223372036854775807 9223372036854775807 0
145 # dcachesize 48546016 73094218 9223372036854775807 9223372036854775807 0
146 # numfile 1848 2075 9223372036854775807 9223372036854775807 0
147 # dummy 0 0 9223372036854775807 9223372036854775807 0
148 # dummy 0 0 9223372036854775807 9223372036854775807 0
149 # dummy 0 0 9223372036854775807 9223372036854775807 0
150 # numiptent 24 24 9223372036854775807 9223372036854775807 0
151 #
152 # 11111111111
153 # 11111111112222222222333333333344444444445555555555666666666677777777778888888888999999999900000000001
154 #12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
155
156
157 #---------------------------------------------------------
158 # VZbeancounter RESOURCE %WARN %ALERT
159 #---------------------------------------------------------
160 VZbeancounter () {
161 # lockedpages, physpages, vmguarpages, oomguarpages
162 VRESRC="$1"
163 typeset -i WARN="$2"
164 typeset -i ALERT="$3"
165 typeset -i HELD LIMIT PERC
166 MossheLog "VZbeancounter $VRESRC"
167 if ! [ -e /proc/user_beancounters ]; then
168 echo "${DATIM};$MYGROUP;$MYNAME;VZ_$VRESRC;UNDEF;0;not an OpenVZ/Virtuzzo guest" >> $TEMPDIR/tmp.$$.collected.tmp
169 else
170 HELD=`fgrep $VRESRC /proc/user_beancounters | cut -c 30-45 | sed -e "s/ //g"`
171 LIMIT=`fgrep $VRESRC /proc/user_beancounters | cut -c 90-109 | sed -e "s/ //g"`
172 PERC=$(( HELD / ( LIMIT / 100 ) ))
173 STATUS="OK"; STAT="Normal Usage"
174 if [ $PERC -ge $WARN ]; then STATUS="WARN"; STAT="High Usage"; fi
175 if [ $PERC -ge $ALERT ]; then STATUS="ALERT"; STAT="Overload"; fi
176 echo "${DATIM};$MYGROUP;$MYNAME;VZ_$VRESRC;$STATUS;$PERC;$STAT: $PERC % of MAX used" >> $TEMPDIR/tmp.$$.collected.tmp
177 fi
178 }
179
180
181
182 #############################################################################
183 #############################################################################