<div dir="ltr">
<p class="">disksup:get_disk_data() is returning garbage in OS X 10.8 (on my system)</p>
<p class=""><br></p><p class="">[I have verified this in R15B02, R15B03 & 16B]<br></p>
<p class=""><br></p>
<p class="">1> ok = application:start(sasl).</p>
<p class=""><snip></p>
<p class="">2> ok = application:start(os_mon).</p>
<p class=""><snip></p>
<p class="">3> disksup:get_disk_data().</p>
<p class="">[{"18704735",244277768,31}]</p>
<p class="">4> </p>
<p class=""><br></p>
<p class="">The expectation is: [{"/",244277768,31}]</p>
<p class=""><br></p>
<p class="">The problem is that the format of the df command changed in OS X 10.8 for some reason (at least it is different on my machine... I checked and I don't appear to have any bash functions or aliases getting in the way).</p>
<p class=""><br></p>
<p class="">In OS X 10.7.? (a colleague's mac mini: hdd):</p>
<p class="">$ df -k -t ufs,hfs</p>
<p class="">Filesystem 1024-blocks Used Available Capacity Mounted on</p>
<p class="">/dev/disk0s2 487546976 156364392 330926584 33% /</p>
<p class="">$</p>
<p class=""><br></p>
<p class="">The 6th column is "Mounted on".</p>
<p class=""><br></p>
<p class="">In OS X 10.8.3 (my mac book pro: ssd):</p>
<p class="">$ df -k -t ufs,hfs</p>
<p class="">Filesystem 1024-blocks Used Available Capacity iused ifree %iused Mounted on</p>
<p class="">/dev/disk0s2 244277768 74564136 169457632 31% 18705032 42364408 31% /</p>
<p class="">$</p>
<p class=""><br></p>
<p class="">The 6th column is "iused" instead of "Mounted on".</p>
<p class=""><br></p>
<p class=""><br></p>
<p class="">If this is a simply difference in 10.8 [darwin 12] and isn't a more complex situation than that (macs pre-installed with ssds vs. hdds? some configuration somewhere?), a fix could be:</p><p class="">[I toyed around in R16B, but the code is pretty much the same in R15B03 and I assume the same in R15B02]</p>
<p class=""><br></p>
<p class="">in os_mon's disksup.erl:</p>
<p class=""><br></p>
<p class="">add a guard for the specific darwin in init's case statement:</p>
<p class=""><br></p>
<p class="">Port = case OS of</p>
<p class=""> {unix, Flavor} when Flavor==sunos4;</p>
<p class=""> Flavor==solaris;</p>
<p class=""> Flavor==freebsd;</p>
<p class=""> Flavor==dragonfly;</p>
<p class=""> Flavor==darwin;</p>
<p class=""> Flavor==darwin_12;</p>
<p class=""> Flavor==linux;</p>
<p class=""> Flavor==openbsd;</p>
<p class=""> Flavor==netbsd;</p>
<p class=""> Flavor==irix64;</p>
<p class=""> Flavor==irix -></p>
<p class=""> start_portprogram();</p>
<p class=""> {win32, _OSname} -></p>
<p class=""> not_used;</p>
<p class=""> _ -></p>
<p class=""> exit({unsupported_os, OS})</p>
<p class=""> end,</p>
<p class=""><br></p>
<p class="">add a clause to the case statement in the get_os() function:</p>
<p class=""><br></p>
<p class="">get_os() -></p>
<p class=""> case os:type() of</p>
<p class=""> {unix, sunos} -></p>
<p class=""> case os:version() of</p>
<p class=""> {5,_,_} -> {unix, solaris};</p>
<p class=""> {4,_,_} -> {unix, sunos4};</p>
<p class=""> V -> exit({unknown_os_version, V})</p>
<p class=""> end;</p>
<p class=""> {unix, irix64} -></p><p class=""> {unix, irix};</p>
<p class=""> {unix, darwin} -></p>
<p class=""> case os:version() of</p>
<p class=""> {12,_,_} -> {unix, darwin_12};</p>
<p class=""> _ -> {unix, darwin}</p>
<p class=""> end;</p>
<p class=""> OS -></p>
<p class=""> OS</p>
<p class=""> end.</p>
<p class=""><br></p>
<p class=""><br></p>
<p class="">add a function that will pattern match on the new darwin_12 atom specified in the other places and will call into a function to parse the df command differently:</p>
<p class=""><br></p>
<p class="">check_disk_space({unix, darwin_12}, Port, Threshold) -></p>
<p class=""> Result = my_cmd("/bin/df -k -t ufs,hfs", Port),</p>
<p class=""> check_disks_darwin_12(skip_to_eol(Result), Threshold);</p>
<p class=""><br></p>
<p class=""><br></p>
<p class="">and add that new function to parse the df command:</p>
<p class=""><br></p>
<p class="">%% Special cases like this annoy me...</p>
<p class="">check_disks_darwin_12("", _Threshold) -></p>
<p class=""> [];</p>
<p class="">check_disks_darwin_12("\n", _Threshold) -></p>
<p class=""> [];</p>
<p class="">check_disks_darwin_12(Str, Threshold) -></p>
<p class=""> case io_lib:fread("~s~d~d~d~d%~d~d~d%~s", Str) of</p>
<p class=""> {ok, [_FS, KB, _Used, _Avail, Cap, _IUsed, _IFree, _ICap, MntOn], RestStr} -></p>
<p class=""> if</p>
<p class=""> Cap >= Threshold -></p>
<p class=""> set_alarm({disk_almost_full, MntOn}, []);</p>
<p class=""> true -></p>
<p class=""> clear_alarm({disk_almost_full, MntOn})</p>
<p class=""> end,</p>
<p class=""> [{MntOn, KB, Cap} | check_disks_darwin_12(RestStr, Threshold)];</p>
<p class=""> _Other -></p>
<p class=""> check_disks_darwin_12(skip_to_eol(Str),Threshold)</p>
<p class=""> end.</p><div><br></div><div><br></div><div style>Sorry if I butchered the whitespace (gmail ate the tabs, so I had to manually fix the whitespace with consistent spaces).</div><div><br></div>-- <br>Ryan
</div>