diff --git a/Changes b/Changes index 3677c90..c010a97 100644 --- a/Changes +++ b/Changes @@ -16,6 +16,8 @@ - Added support for postfix-policyd-spf-perl SPF handler in Mail graph. (thanks to Claude Nadon, claude AT ws01.info) - Added support for process names that include spaces in Process graph. [#94] +- Added the ability to include an alert for each defined filesystem in the 'fs' + graph. The previous alert system in this graph is now deprecated. - Fixed the text color in the bottom URL of the Bind graph. - Fixed the text color in the bottom URL of the Icecast Streaming Server graph. - Fixed a problem with multiple 'ApplicationInstance' tags in Wowza Server diff --git a/lib/fs.pm b/lib/fs.pm index 5df79e8..624d54a 100644 --- a/lib/fs.pm +++ b/lib/fs.pm @@ -521,15 +521,12 @@ sub fs_init { } } - # check dependencies - if(lc($fs->{alerts}->{rootfs_enabled}) eq "y") { - if(! -x $fs->{alerts}->{rootfs_script}) { - logger("$myself: ERROR: script '$fs->{alerts}->{rootfs_script}' doesn't exist or don't has execution permissions."); - } + # check for deprecated options + if($fs->{alerts}->{rootfs_enabled} || $fs->{alerts}->{rootfs_timeintvl} || $fs->{alerts}->{rootfs_threshold} || $fs->{alerts}->{rootfs_script}) { + logger("$myself: WARNING: you have deprecated options in the section. Please read the monitorix.conf(5) man page and consider also upgrade your current configuration file."); } $config->{fs_hist} = (); - $config->{fs_hist_alert1} = 0; push(@{$config->{func_update}}, $package); logger("$myself: Ok") if $debug; } @@ -684,22 +681,27 @@ sub fs_update { # prevents a division by 0 if device is not responding $ino = ($used * 100) / ($used + $free) unless $used + $free == 0; - # FS alert - if($f eq "/" && lc($fs->{alerts}->{rootfs_enabled}) eq "y") { - if(!$fs->{alerts}->{rootfs_threshold} || $use < $fs->{alerts}->{rootfs_threshold}) { - $config->{fs_hist_alert1} = 0; + # check alerts for each filesystem + my @al = split(',', $fs->{alerts}->{$f} || ""); + if(scalar(@al)) { + my $timeintvl = trim($al[0]); + my $threshold = trim($al[1]); + my $script = trim($al[2]); + + if(!$threshold || $use < $threshold) { + $config->{fs_hist}->{$f} = 0; } else { - if(!$config->{fs_hist_alert1}) { - $config->{fs_hist_alert1} = time; + if(!$config->{fs_hist}->{$f}) { + $config->{fs_hist}->{$f} = time; } - if($config->{fs_hist_alert1} > 0 && (time - $config->{fs_hist_alert1}) >= $fs->{alerts}->{rootfs_timeintvl}) { - if(-x $fs->{alerts}->{rootfs_script}) { - logger("$myself: ALERT: executing script '$fs->{alerts}->{rootfs_script}'."); - system($fs->{alerts}->{rootfs_script} . " " . $fs->{alerts}->{rootfs_timeintvl} . " " . $fs->{alerts}->{rootfs_threshold} . " " . $use); + if($config->{fs_hist}->{$f} > 0 && (time - $config->{fs_hist}->{$f}) >= $timeintvl) { + if(-x $script) { + logger("$myself: alert on filesystem '$f': executing script '$script'."); + system($script . " " . $timeintvl . " " . $threshold . " " . $use); } else { - logger("$myself: ERROR: script '$fs->{alerts}->{rootfs_script}' doesn't exist or don't has execution permissions."); + logger("$myself: ERROR: script '$script' doesn't exist or don't has execution permissions."); } - $config->{fs_hist_alert1} = time; + $config->{fs_hist}->{$f} = time; } } } diff --git a/man/man5/monitorix.conf.5 b/man/man5/monitorix.conf.5 index a276b81..32a6846 100644 --- a/man/man5/monitorix.conf.5 +++ b/man/man5/monitorix.conf.5 @@ -942,46 +942,41 @@ Just an example: You can define as much entries as you want. .RE .P -.BI rootfs_enabled +.BI alerts .RS -This section enables or disables the alert capabilities for this graph. Only the alert for the root filesystem disk usage is currently implemented. It works as follows: +This optional list enables the alert capabilities for this graph and complements with the \fBlist\fP option. Each alert has three fields separated by comma: the \fItime interval\fP, the \fIthreshold\fP and the path to the \fIscript\fP to be executed. .P -If the percentage of disk space used in the root filesystem reaches the \fBrootfs_threshold\fP value for the interval of time defined in \fBrootfs_timeintvl\fP, Monitorix will execute the external alert script defined in \fBrootfs_script\fP. +The \fItime interval\fP is the period of time (in seconds) that the \fIthreshold\fP needs to be exceeded before the external script is executed. .P -The default Monitorix installation includes an example of a shell-script alert called \fBmonitorix-alert.sh\fP which you can use as a base for your own script. +The \fIthreshold\fP is the percentage of disk space used in the file system that needs to be reached or exceeded within the specified time in \fItime interval\fP to execute the external script. .P -Default value: \fIn\fP -.RE +The \fIscript\fP is the full path name of the script that will be executed by this alert. +.P +Each defined filesystem has its own alert. +.P +The default Monitorix installation includes an example of a shell-script alert called \fImonitorix-alert.sh\fP which you can use as a base for your own script. +.P +The following is an example of an alert defined for the root filesystem: .P -.BI rootfs_timeintvl .RS -This is the period of time (in seconds) that the threshold needs to be exceeded before the external alert script is executed. -.P -Default value: \fI3600\fP -.RE -.P -.BI rootfs_threshold -.RS -This is the value that needs to be reached or exceeded within the specified time period in \fBrootfs_timeintvl\fP to trigger the mechanism for a particular action, which in this case is the execution of an external alert script. -.P -The value of this option is compared to the current root filesystem disk usage. -.P -Default value: \fI100\fP -.RE -.P -.BI rootfs_script -.RS -This is the full path name of the script that will be executed by this alert. -.P -It will receive the following three parameters: -.P -1st - the value currently defined in \fBrootfs_timeintvl\fP. + .br -2nd - the value currently defined in \fBrootfs_threshold\fP. + / = 3600, 98, /path/to/script .br -3rd - the current root filesystem disk usage. + +.P +.RE +Such alert means that if the percentage of disk space used in the root filesystem reaches or exceeds 98 during at least one hour (3600 seconds) the script in \fI/path/to/script\fP will be executed. +.P +The external script will receive the following arguments: +.P +.RS +1st - the value defined as \fItime interval\fP. +.br +2nd - the value defined as \fIthreshold\fP. +.br +3rd - the filesystem disk usage. .P -Default value: \fI/path/to/script.sh\fP .RE .SS Directory usage statistics (du.rrd) This graph is able to monitor the usage of an unlimited number of directories. diff --git a/monitorix.conf b/monitorix.conf index c05866e..17b2206 100644 --- a/monitorix.conf +++ b/monitorix.conf @@ -231,10 +231,6 @@ secure_log_date_format = %b %e rigid = 2, 0, 2, 0 limit = 100, 1000, 100, 1000 - rootfs_enabled = n - rootfs_timeintvl = 3600 - rootfs_threshold = 100 - rootfs_script = /path/to/script.sh