From bdb135a4d9c6aa32204d5c87f6e59c3b1b4c86be Mon Sep 17 00:00:00 2001 From: Sriram Melkote Date: Thu, 31 Jan 2013 17:01:34 -0800 Subject: This patch fixes disksup:get_disk_data for SUSv3, specifically OS X ML On OS X Mountain Lion, the default output of df command includes iNode used and iNodes free, which apparent what SUSv3 specifies. This breaks the current parse logic and reports incorrect results. This patch adds support for the new format and ensures older versions of OS X produce this format by adding the -i switch (which is now the default). Adding support for this new format rather than changing df output as we'll presumably see this on other platforms eventually. --- lib/os_mon/src/disksup.erl | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'lib/os_mon/src/disksup.erl') diff --git a/lib/os_mon/src/disksup.erl b/lib/os_mon/src/disksup.erl index f5f76f1488..f906f33d32 100644 --- a/lib/os_mon/src/disksup.erl +++ b/lib/os_mon/src/disksup.erl @@ -275,8 +275,8 @@ check_disk_space({unix, sunos4}, Port, Threshold) -> Result = my_cmd("df", Port), check_disks_solaris(skip_to_eol(Result), Threshold); check_disk_space({unix, darwin}, Port, Threshold) -> - Result = my_cmd("/bin/df -k -t ufs,hfs", Port), - check_disks_solaris(skip_to_eol(Result), Threshold). + Result = my_cmd("/bin/df -i -k -t ufs,hfs", Port), + check_disks_susv3(skip_to_eol(Result), Threshold). % This code works for Linux and FreeBSD as well check_disks_solaris("", _Threshold) -> @@ -298,6 +298,26 @@ check_disks_solaris(Str, Threshold) -> check_disks_solaris(skip_to_eol(Str),Threshold) end. +% Parse per SUSv3 specification, notably recent OS X +check_disks_susv3("", _Threshold) -> + []; +check_disks_susv3("\n", _Threshold) -> + []; +check_disks_susv3(Str, Threshold) -> + case io_lib:fread("~s~d~d~d~d%~d~d~d%~s", Str) of + {ok, [_FS, KB, _Used, _Avail, Cap, _IUsed, _IFree, _ICap, MntOn], RestStr} -> + if + Cap >= Threshold -> + set_alarm({disk_almost_full, MntOn}, []); + true -> + clear_alarm({disk_almost_full, MntOn}) + end, + [{MntOn, KB, Cap} | + check_disks_susv3(RestStr, Threshold)]; + _Other -> + check_disks_susv3(skip_to_eol(Str),Threshold) + end. + %% Irix: like Linux with an extra FS type column and no '%'. check_disks_irix("", _Threshold) -> []; check_disks_irix("\n", _Threshold) -> []; -- cgit v1.2.3