From 56c8dabfbc6a6dc8cb6a066d0b74f861b9d16327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Wei=C3=9Fl?= Date: Mon, 17 Mar 2014 01:05:08 +0100 Subject: Add 'disksup_posix_only' parameter to disksup On embedded (Linux) systems the "df" program is very often provided by the Busybox (or Toolbox) project. This version does not provide the "-l" option (for displaying only local filesystems) used in disksup.erl. To make disksup work on these embedded platforms, this patch adds a new application parameter 'disksup_posix_only', to make diskup use only options defined in the POSIX standard: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/df.html --- lib/os_mon/doc/src/disksup.xml | 10 ++++++++++ lib/os_mon/src/disksup.erl | 15 ++++++++++++--- lib/os_mon/test/disksup_SUITE.erl | 39 ++++++++++++++++++++++++++++++--------- 3 files changed, 52 insertions(+), 12 deletions(-) (limited to 'lib/os_mon') diff --git a/lib/os_mon/doc/src/disksup.xml b/lib/os_mon/doc/src/disksup.xml index dbcfd65095..c8566d0126 100644 --- a/lib/os_mon/doc/src/disksup.xml +++ b/lib/os_mon/doc/src/disksup.xml @@ -73,6 +73,16 @@ much disk can be utilized before the disk_almost_full alarm is set. The default is 0.80 (80%).

+ disksup_posix_only = bool() + +

Specifies whether the disksup helper process should only + use POSIX conformant commands (true) or not. The default is + false. Setting this parameter to true can be + necessary on embedded systems with stripped-down versions + of Unix tools like df. The returned disk data and alarms + can be different when using this option.

+

The parameter is ignored on Windows.

+

See config(4) for information about how to change the value of configuration diff --git a/lib/os_mon/src/disksup.erl b/lib/os_mon/src/disksup.erl index 278da26a20..3fd80f2365 100644 --- a/lib/os_mon/src/disksup.erl +++ b/lib/os_mon/src/disksup.erl @@ -81,10 +81,12 @@ param_type(disk_space_check_interval, Val) when is_integer(Val), param_type(disk_almost_full_threshold, Val) when is_number(Val), 0= true; +param_type(disksup_posix_only, Val) when Val==true; Val==false -> true; param_type(_Param, _Val) -> false. param_default(disk_space_check_interval) -> 30; -param_default(disk_almost_full_threshold) -> 0.80. +param_default(disk_almost_full_threshold) -> 0.80; +param_default(disksup_posix_only) -> false. %%---------------------------------------------------------------------- %% gen_server callbacks @@ -94,7 +96,8 @@ init([]) -> process_flag(trap_exit, true), process_flag(priority, low), - OS = get_os(), + PosixOnly = os_mon:get_env(disksup, disksup_posix_only), + OS = get_os(PosixOnly), Port = case OS of {unix, Flavor} when Flavor==sunos4; Flavor==solaris; @@ -102,6 +105,7 @@ init([]) -> Flavor==dragonfly; Flavor==darwin; Flavor==linux; + Flavor==posix; Flavor==openbsd; Flavor==netbsd; Flavor==irix64; @@ -205,8 +209,10 @@ format_status(_Opt, [_PDict, #state{os = OS, threshold = Threshold, %% Internal functions %%---------------------------------------------------------------------- -get_os() -> +get_os(PosixOnly) -> case os:type() of + {unix, _} when PosixOnly -> + {unix, posix}; {unix, sunos} -> case os:version() of {5,_,_} -> {unix, solaris}; @@ -259,6 +265,9 @@ check_disk_space({unix, irix}, Port, Threshold) -> check_disk_space({unix, linux}, Port, Threshold) -> Result = my_cmd("/bin/df -lk", Port), check_disks_solaris(skip_to_eol(Result), Threshold); +check_disk_space({unix, posix}, Port, Threshold) -> + Result = my_cmd("df -k -P", Port), + check_disks_solaris(skip_to_eol(Result), Threshold); check_disk_space({unix, dragonfly}, Port, Threshold) -> Result = my_cmd("/bin/df -k -t ufs,hammer", Port), check_disks_solaris(skip_to_eol(Result), Threshold); diff --git a/lib/os_mon/test/disksup_SUITE.erl b/lib/os_mon/test/disksup_SUITE.erl index 94661cfa77..2f62564959 100644 --- a/lib/os_mon/test/disksup_SUITE.erl +++ b/lib/os_mon/test/disksup_SUITE.erl @@ -29,6 +29,7 @@ -export([port/1]). -export([terminate/1, unavailable/1, restart/1]). -export([otp_5910/1]). +-export([posix_only/1]). %% Default timetrap timeout (set in init_per_testcase) -define(default_timeout, ?t:minutes(1)). @@ -62,9 +63,9 @@ all() -> Bugs = [otp_5910], case test_server:os_type() of {unix, sunos} -> - [api, config, alarm, port, unavailable] ++ Bugs; - {unix, _OSname} -> [api, alarm] ++ Bugs; - {win32, _OSname} -> [api, alarm] ++ Bugs; + [api, config, alarm, port, unavailable, posix_only] ++ Bugs; + {unix, _OSname} -> [api, alarm, posix_only] ++ Bugs; + {win32, _OSname} -> [api, alarm, posix_only] ++ Bugs; _OS -> [unavailable] end. @@ -83,12 +84,7 @@ api(doc) -> ["Test of API functions"]; api(Config) when is_list(Config) -> %% get_disk_data() - [{Id,KByte,Capacity}|_] = get_disk_data(), - true = io_lib:printable_list(Id), - true = is_integer(KByte), - true = is_integer(Capacity), - true = Capacity>0, - true = KByte>0, + ok = check_get_disk_data(), %% get_check_interval() 1800000 = disksup:get_check_interval(), @@ -405,9 +401,34 @@ otp_5910(Config) when is_list(Config) -> ok = application:start(os_mon), ok. +posix_only(suite) -> []; +posix_only(doc) -> ["Test disksup_posix_only option"]; +posix_only(Config) when is_list(Config) -> + %% Set option and restart disksup + ok = application:set_env(os_mon, disksup_posix_only, true), + ok = supervisor:terminate_child(os_mon_sup, disksup), + {ok, _Child1} = supervisor:restart_child(os_mon_sup, disksup), + + ok = check_get_disk_data(), + + %% Reset option and restart disksup + ok = application:set_env(os_mon, disksup_posix_only, false), + ok = supervisor:terminate_child(os_mon_sup, disksup), + {ok, _Child2} = supervisor:restart_child(os_mon_sup, disksup), + ok. + dump_info() -> io:format("Status: ~p~n", [sys:get_status(disksup)]). +check_get_disk_data() -> + [{Id,KByte,Capacity}|_] = get_disk_data(), + true = io_lib:printable_list(Id), + true = is_integer(KByte), + true = is_integer(Capacity), + true = Capacity>0, + true = KByte>0, + ok. + % filter get_disk_data and remove entriew with zero capacity % "non-normal" filesystems report zero capacity % - Perhaps errorneous 'df -k -l'? -- cgit v1.2.3