OS X os_mon broken

Sean Hinde sean.hinde@REDACTED
Tue Mar 8 11:02:13 CET 2005


Excellent, thank you.

Sean

On 8 Mar 2005, at 07:23, Bjorn Gustavsson wrote:

> There will be several bug fixes in os_mon in R10B-4, including a bug
> fix to cpu_sup for Max OS X.
>
> My bug fix is similar to yours in that it looks at the uptime output
> starting at the end.
>
> /Bjorn
>
>     %% Get the load average using uptime.
>     D = os:cmd("uptime") -- "\n",
>     %% Here is a sample uptime string from Mac OS 10.3.8:
>     %%    "11:17  up 12 days, 20:39, 2 users, load averages: 1.07 0.95 
> 0.66"
>     %% The safest way to extract the load averages seems to be grab 
> everything
>     %% after the last colon and then do an fread on that.
>     Avg = lists:reverse(hd(string:tokens(lists:reverse(D), ":"))),
>     {ok,[L1,L5,L15],_} = io_lib:fread("~f ~f ~f", Avg),
>
>     case Request of
> 	?avg1  -> sunify(L1);
> 	?avg5  -> sunify(L5);
> 	?avg15 -> sunify(L15);
> 	?ping -> 4711;
> 	?nprocs ->
> 	    Ps = os:cmd("/bin/ps -ax | /usr/bin/wc -l"),
> 	    {ok, [N], _} = io_lib:fread("~d", Ps),
> 	    N-1
>     end;
>
> Sean Hinde <sean.hinde@REDACTED> writes:
>
>> Hi,
>>
>> os_mon-1.6.2 is still broken under OS X darwin.
>>
>> The following patch restores what was in my original patch. This makes
>> the solution much less susceptible to changes in the output of uptime.
>>
>> Regards,
>> Sean
>>
>> --- cpu_sup.erl.orig    Fri Jun 25 14:25:58 2004
>> +++ cpu_sup.erl Mon Mar  7 21:50:04 2005
>> @@ -274,11 +274,11 @@
>>       end;
>>   get_int_measurement(Request, #state{os_type = {unix, darwin}}) ->
>>       D = os:cmd("uptime") -- "\n",
>> -    {ok, [L1, L5, L15], _} =
>> io_lib:fread("~*s~*s~*s~*s~*s~*s~*s~f,~f,~f", D),
>> +    [L15, L5, L1|_] = lists:reverse(string:tokens(D, ", ")),
>>       case Request of
>> -       ?avg1  -> sunify(L1);
>> -       ?avg5  -> sunify(L5);
>> -       ?avg15 -> sunify(L15);
>> +       ?avg1  -> sunify(list_to_float(L1));
>> +       ?avg5  -> sunify(list_to_float(L5));
>> +       ?avg15 -> sunify(list_to_float(L15));
>>          ?ping -> 4711;
>>          ?nprocs ->
>>              Ps = os:cmd("/bin/ps -ax | /usr/bin/wc -l"),
>>
>
> -- 
> Björn Gustavsson, Erlang/OTP, Ericsson AB




More information about the erlang-questions mailing list