Ability to also check free swap space
authorJamie Cameron <jcameron@webmin.com>
Tue, 16 Nov 2010 20:00:43 +0000 (12:00 -0800)
committerJamie Cameron <jcameron@webmin.com>
Tue, 16 Nov 2010 20:00:43 +0000 (12:00 -0800)
https://sourceforge.net/tracker/index.php?func=detail&aid=3110202&group_id=17457&atid=117457#

status/CHANGELOG
status/lang/en
status/memory-monitor.pl

index 0b5dbe3..08da6ab 100644 (file)
@@ -73,3 +73,5 @@ Put back the option to use Cingular as an SMS carrier.
 ---- Changes since 1.510 ----
 The Check File or Directory monitor can now use a pattern like /tmp/* to check sizes for all files in a directory.
 Added a monitor-level option to run a command if the monitor times out.
+---- Changes since 1.520 ----
+Enhanced the free memory monitor to be able to check virtual memory as well.
index bc0358f..40d2d33 100644 (file)
@@ -282,10 +282,15 @@ change_file=File or directory to monitor (fail if changed)
 
 jabber_eparser=The Perl module $1 is not installed on your system.
 
-memory_min2=Minimum free memory
-memory_emin=Missing or invalid amount of free memory
+memory_min2=Minimum free real memory
+memory_emin=Missing or invalid amount of free real memory
 memory_eproc=Webmin does not know how to check free memory on your operating system
-memory_free2=$1 free
+memory_free2=$1 real memory free
+memory_freeswap=$1 virtual memory free
+memory_freelow=Only $1 real memory free
+memory_freelowswap=Only $1 virtual memory free
+memory_minswap=Minimum free virtual memory
+memory_eminswap=Missing or invalid amount of free virtual memory
 
 proftpd_etype=This monitor cannot be used when ProFTPD is run stand-alone
 
index 369f9f9..23e241e 100755 (executable)
@@ -11,11 +11,21 @@ if ($@) {
        return { 'up' => -1 };
        }
 elsif ($mem[1] < $_[0]->{'min'}) {
-       return { 'up' => 0 };
+       return { 'up' => 0,
+                'desc' => &text('memory_freelow', &nice_size($mem[1]*1024)) };
+       }
+elsif ($mem[2] && $mem[3] < $_[0]->{'minswap'}) {
+       return { 'up' => 0,
+                'desc' => &text('memory_freelowswap',
+                                &nice_size($mem[3]*1024)) };
        }
 else {
+       my @desc = ( &text('memory_free2', &nice_size($mem[1]*1024)) );
+       if ($mem[2]) {
+               push(@desc, &text('memory_freeswap', &nice_size($mem[2]*1024)));
+               }
        return { 'up' => 1,
-                'desc' => &text('memory_free2', &nice_size($mem[1]*1024)) };
+                'desc' => join(", ", @desc) };
        }
 }
 
@@ -23,6 +33,9 @@ sub show_memory_dialog
 {
 print &ui_table_row($text{'memory_min2'},
        &ui_bytesbox("min", $_[0]->{'min'}*1024));
+
+print &ui_table_row($text{'memory_minswap'},
+       &ui_bytesbox("minswap", $_[0]->{'minswap'}*1024));
 }
 
 sub parse_memory_dialog
@@ -32,5 +45,7 @@ sub parse_memory_dialog
 defined(&proc::get_memory_info) || &error($text{'memory_eproc'});
 $in{'min'} =~ /^[0-9\.]+$/ || &error($text{'memory_emin'});
 $_[0]->{'min'} = $in{'min'}*$in{'min_units'}/1024;
+$in{'minswap'} =~ /^[0-9\.]+$/ || &error($text{'memory_eminswap'});
+$_[0]->{'minswap'} = $in{'minswap'}*$in{'minswap_units'}/1024;
 }