From ab36e2eae4eccd50a262f7b6c65dcdc7385f8451 Mon Sep 17 00:00:00 2001 From: Stephen L Johnson Date: Wed, 24 Jul 2002 18:30:17 +0000 Subject: [PATCH] Added patch Ilya Martynov for FreeBSD support --- src/lib/Spong/Client/plugins/check_memory | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/lib/Spong/Client/plugins/check_memory b/src/lib/Spong/Client/plugins/check_memory index 00e28d0..cb22193 100755 --- a/src/lib/Spong/Client/plugins/check_memory +++ b/src/lib/Spong/Client/plugins/check_memory @@ -1,4 +1,4 @@ -# $Id: check_memory,v 1.3 2002/01/07 21:25:24 supermathie Exp $ +# $Id: check_memory,v 1.4 2002/07/24 18:30:17 sljohnson Exp $ # vim:syn=perl:expandtab:ts=3:sw=3:ai:si # Register this routine with the plugin registry $CHECKFUNCS{'memory'} = \&check_memory; @@ -63,7 +63,7 @@ sub check_memory_free { sub check_memory_top { $kmb='\s+(\d+[KM])'; - $message = ""; + @parse_error = ("yellow", "Can't parse memory line", $message); open CMD, "$MEMCHECK |"; while () { /PID/ && last; @@ -81,9 +81,24 @@ sub check_memory_top { &to_KB($swaptotal, $swapused, $swapfree, $cached); } else { close CMD; - return ("yellow", "Can't parse memory line", $message); + return @parse_error; }; $hardmemused = $memused-$buffers-$cached; + } elsif (/^Mem:$kmb Active,$kmb Inact,$kmb Wired,$kmb Cache,$kmb Buf,$kmb Free/) { + # the top package supporting FreeBSD has this format + ($memactive,$meminact,$memwired,$memcache,$buffers,$memfree) = ($1,$2,$3,$4,$5,$6); + &to_KB($memactive,$meminact,$memwired,$cached,$buffers,$memfree); + $memtotal = $memactive+$meminact+$memwired+$memcache; + $hardmemused = $memtotal-$memfree; + $_ = ; + $message .= $_; + if (/^Swap:$kmb Total,$kmb Used,$kmb Free/) { + ($swaptotal, $swapused, $swapfree) = ($1,$2,$3); + &to_KB($swaptotal, $swapused, $swapfree); + } else { + close CMD; + return @parse_error; + } } elsif (/^Memory:$kmb real,$kmb free,$kmb swap,$kmb free swap/) { # the top package supporting various unices has this format ($memtotal,$memfree,$swapused,$swapfree) = ($1,$2,$3,$4); @@ -98,7 +113,7 @@ sub check_memory_top { $swaptotal = $swapused+$swapfree; } else { close CMD; - return ("yellow", "Can't parse memory line", $message); + return @parse_error; } $physpctused = floor($hardmemused/$memtotal*100); $virtpctused = floor(($hardmemused+$swapused)/($memtotal+$swaptotal)*100); -- 2.30.2