- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Memory negative result in Nagios Script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2009 07:42 AM
12-21-2009 07:42 AM
Hi all,
We use a Nagios monitoring script to monitor our servers and in our memory script we receive in some servers negative results. When I go trough the script step by step I do get a positive result (e.g: 2% of mem percentage used), but never negative as when I run the script.
Please could someone check the script and tell me why it gives negative results?
Serverx:/usr/local/nagios/libexec#./check_memory.sh 85 96
OK: -49% used. Used Mem= -2071116 Kb, Total Mem= 4185088 Kb | Memory_perc=-49%;85;96;; Memory_Kb=-2071116KB;3557324;4017684;0;4185088
Thanks as always for your help.
P.S: And no, there's no way I can ask this to the creator of this script ;-)
Regards,
Solved! Go to Solution.
- Tags:
- nagios
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2009 07:58 AM
12-21-2009 07:58 AM
SolutionIt is possible that you have exceeded 32-bit shell arithmetic limitations. If you are running 11.23 try using '/usr/bin/ksh' which should support 64-bit precision. Otherwise, you could try the Korn93 shell found as '/usr/dt/bin/dtksh'. Change your "she-bang" (#! interpreter line) accordingly.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2009 08:15 AM
12-21-2009 08:15 AM
Re: Memory negative result in Nagios Script
./check_memory.sh 85 96 > chkmem.log 2>&1
Then look at the chkmem.log file or post it back. Most likely shell arithmetic overflow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2009 10:37 AM
12-21-2009 10:37 AM
Re: Memory negative result in Nagios Script
> ME: If you are running 11.23 try using '/usr/bin/ksh' which should support 64-bit precision. Otherwise, you could try the Korn93 shell found as '/usr/dt/bin/dtksh'.
While the 'ksh' shell on 11.23 or later will do 64-bit arithmetic, the 'dtksh' shell will _not_.
You could use 'bc' or 'awk' [with printf()'s "f" specification], or Perl to perform your calculations in lieu of the shell. For example, 'awk' will do:
# echo 2147483647 | awk '{printf "%12.0f\n",$0*4}'
8589934588
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2009 10:58 AM
12-21-2009 10:58 AM
Re: Memory negative result in Nagios Script
Yes but it will do floating point arithmetic.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2009 01:07 AM
12-22-2009 01:07 AM
Re: Memory negative result in Nagios Script
Your answers are very useful. Although changing the shell from #!/bin/sh to #!/usr/bin/ksh helped a lot, now I get results above 100% ¿? Check example:
root:serverx:/ # ./usr/local/nagios/libexec/check_memory.sh 85 95
CRITICAL: 114% used. Used Mem= 52837076 Kb, Total Mem= 46086144 Kb | Memory_perc=114%;85;95;; Memory_Kb=52837076KB;39173222;43781836;0;46086144
Perhaps the following line does not provide the best way to check physical memory used:
USEDPAGES=`vmstat |grep -v memory | grep -v avm | awk '{ print $4 }'`
Any idea on what could be the best command to achieve the memory used?
However I wanted to paste the result that TTr asked just in case there's something interesting to mention about
:
root:serverx:/usr/local/nagios/libexec # more check_mem.log
+ test 2 -ne 2
+ + getconf PAGESIZE
PAGESIZE=4096
+ WARNING=85
+ CRITICAL=96
+ + machinfo
+ grep -i memory
+ awk { print $3 }
TOTALMBMEM=49102
+ TOTALMEM=50280448
+ + vmstat
+ grep -v memory
+ awk { print $4 }
+ grep -v avm
USEDPAGES=3137222
+ USEDMEM=-34024
+ FREEMEM=50314472
+ USEDPERCENT=0
+ WARNINGKB=-211292
+ CRITICALKB=5319557
+ [ 0 != ]
+ [ 0 -ge 96 ]
+ [ 0 -ge 85 ]
+ [ 0 -lt 85 ]
+ echo OK: 0% used. Used Mem= -34024 Kb, Total Mem= 50280448 Kb | Memory_perc=0%;85;96;; Memory_Kb=-34024KB;-211292;5319557;0;502804
48
OK: 0% used. Used Mem= -34024 Kb, Total Mem= 50280448 Kb | Memory_perc=0%;85;96;; Memory_Kb=-34024KB;-211292;5319557;0;50280448
+ exit 0
Thanks again for your help.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2009 04:45 AM
12-22-2009 04:45 AM
Re: Memory negative result in Nagios Script
Using double parentheses for arithmetic evaluation is fine as where you do:
# TOTALMEM=$(($TOTALMBMEM * 1024))
However, you should use curly braces for parameter substitution. Change things like:
# echo "Memory_Kb=$((USEDMEM))KB;"
to:
# echo "Memory_Kb=${USEDMEM}KB;"
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2009 04:53 AM
12-22-2009 04:53 AM
Re: Memory negative result in Nagios Script
3137222 * 4096 = 12,850,061,312 This number is too big and overflows as follows
12,850,061,312 mod 2^31 = 2,112,643,072
2,112,643,072 - 2^31 = -34840576 (The number is in the negative range for 2^32 integers)
-34840576 / 1024 = -34024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2009 05:04 AM
12-22-2009 05:04 AM
Re: Memory negative result in Nagios Script
TOTALMEM=$(($TOTALMBMEM * 1024)), you can use
TOTALMEM=`echo "$TOTALMBMEM * 1024" | /usr/bin/bc`
and
USEDMEM=`echo "$USEDPAGES * $PAGESIZE / 1024" | /usr/bin/bc`
and so on.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2009 05:04 AM
12-22-2009 05:04 AM
Re: Memory negative result in Nagios Script
> TTr: It is 32 bit arithmetic overflow.
I agree if this is the Posix shell, but if the Korn ('ksh') shell is used in 11.23 or later, the result is valid.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2009 06:16 AM
12-22-2009 06:16 AM
Re: Memory negative result in Nagios Script
# TOTALMEM=$(($TOTALMBMEM * 1024))
Actually no need to use any stinkin' "$" for arithmetic evaluation:
(( TOTALMEM = TOTALMBMEM * 1024 ))
>TTr: The first error appears at the ... which is calculated as USEDMEM=$(($USEDPAGES * $PAGESIZE / 1024)).
You can change the order to:
(( USEDMEM = USEDPAGES * (PAGESIZE / 1024) ))
>TOTALMEM=`echo "$TOTALMBMEM * 1024" | /usr/bin/bc`
You shouldn't go backwards and use `` vs $():
TOTALMEM=$(echo "$TOTALMBMEM * 1024" | /usr/bin/bc)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2009 07:57 AM
12-28-2009 07:57 AM
Re: Memory negative result in Nagios Script
I'm trying to when it goes over 100% then set variable to 100. With lines:
if [ $var -eg 100 ]; then
$VAR=100
fi
But does not work like this.
Other way of doing this?
regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2009 08:22 AM
12-28-2009 08:22 AM
Re: Memory negative result in Nagios Script
> $VAR=100
> fi
> But does not work like this.
"does not work" is not a useful problem
description. What happens? Error messages?
Compare:
$var $VAR
-eg -ge
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2009 08:53 AM
12-28-2009 08:53 AM
Re: Memory negative result in Nagios Script
I used the following:
if [ $VAR-ge 100 ]; then
VAR=$((100))
fi
Regards!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2009 10:57 AM
12-28-2009 10:57 AM
Re: Memory negative result in Nagios Script
No need to do something that complicated.
VAR=100
(( VAR = 100 ))