diff --git a/status/CHANGELOG b/status/CHANGELOG index 2bd3c9400..6cce3d3f3 100644 --- a/status/CHANGELOG +++ b/status/CHANGELOG @@ -67,3 +67,5 @@ Added an option to the SSH monitor type for a port number. ---- Changes since 1.490 ---- Added a new monitor type for detecting large directories. Added a button to the main page for refreshing only selected monitors, thanks to Michael Mansour. +---- Changes since 1.500 ---- +Added an option to the Disk Space monitor to alert based on percentage free, as an alternative to a threshold in bytes. diff --git a/status/lang/en b/status/lang/en index 33cbc8cf5..7da171759 100644 --- a/status/lang/en +++ b/status/lang/en @@ -237,13 +237,18 @@ traffic_ebytes=Missing or invalid number of bytes/second space_fs=Filesystem to check space_min2=Minimum free space +space_mode0=Absolute size +space_mode1=Percentage of total space_desc=$1 free space_nofs=Filesystem not mounted space_other=Other.. space_emin=Missing or invalid free space +space_epc=Missing or invalid free space percentage space_eother=Missing or invalid filesystem space_inode=Minimum free Inodes space_ierr=Only $1 inodes free +space_merr=Only $1 space free +space_perr=Only $1% free load_time=Load average to check load_1=1 minute diff --git a/status/space-monitor.pl b/status/space-monitor.pl index 5c39d0739..acff6040b 100755 --- a/status/space-monitor.pl +++ b/status/space-monitor.pl @@ -11,8 +11,21 @@ foreach $f (&mount::list_mounted()) { } if ($m) { local @sp = &mount::disk_space($m->[2], $m->[0]); - if ($sp[1] < $_[0]->{'min'}) { - return { 'up' => 0 }; + if ($_[0]->{'min'} =~ /^(\S+)%/) { + # Compare percentage + local $pc = $sp[1] * 100.0 / $sp[0]; + if ($pc < $1) { + return { 'up' => 0, + 'desc' => &text('space_perr', int($pc)) }; + } + } + else { + # Compare absolute size + if ($sp[1] < $_[0]->{'min'}) { + return { 'up' => 0, + 'desc' => &text('space_merr', + &nice_size($sp[1]*1024)) }; + } } if ($_[0]->{'inode'} && defined(&mount::inode_space)) { @@ -54,9 +67,17 @@ else { &ui_textbox("other", $_[0]->{'fs'}, 30)); } +# Minumum free space +local $min = $_[0]->{'min'}; +local $pc = ($min =~ s/\%$// ? 1 : 0); print &ui_table_row($text{'space_min2'}, - &ui_bytesbox("min", $_[0]->{'min'}*1024)); + &ui_radio_table("min_mode", $pc, + [ [ 0, $text{'space_mode0'}, + &ui_bytesbox("min", $pc ? undef : $min*1024) ], + [ 1, $text{'space_mode1'}, + &ui_textbox("pc", $pc ? $min : undef, 4)."%" ] ]), 3); +# Minimum free inodes if (defined(&mount::inode_space)) { print &ui_table_row($text{'space_inode'}, &ui_textbox("inode", $_[0]->{'inode'}, 10)); @@ -66,8 +87,15 @@ if (defined(&mount::inode_space)) { sub parse_space_dialog { &depends_check($_[0], "mount"); -$in{'min'} =~ /^[0-9\.]+$/ || &error($text{'space_emin'}); -$_[0]->{'min'} = $in{'min'}*$in{'min_units'}/1024; +if ($in{'min_mode'} == 0) { + $in{'min'} =~ /^[0-9\.]+$/ || &error($text{'space_emin'}); + $_[0]->{'min'} = $in{'min'}*$in{'min_units'}/1024; + } +else { + $in{'pc'} =~ /^[0-9\.]+$/ && $in{'pc'} >= 0 && $in{'pc'} <= 100 || + &error($text{'space_epc'}); + $_[0]->{'min'} = $in{'pc'}."%"; + } if ($in{'fs'}) { $_[0]->{'fs'} = $in{'fs'}; }