Get the size of the disk and free space. How?

Hello all!

Working with file storage now and seeking information about Erlang abilities.

  • Is there Erlang in-box-solution for getting info about physical disk and free space on it?
  • Is there Erlang in-box-solution for maintaining data when changing physical disks on-fly or need to develop by my own?

disksup:get_disk_data(). The result I got from asking AI.:grin:

Setup: Erlang running in Ubuntu 24 WSL2 on Windows 11.
Eshell V13.2.2.5 (abort with ^G)
1> disksup:get_disk_data().
=WARNING REPORT==== 28-Oct-2025::12:46:56.523046 ===
OS_MON (disksup) called by <0.82.0>, not started

[{“none”,0,0}]

You have to ensure that os_mon is started. I haven’t used it myself,
so it’s not clear to me whether you can start it without setting a configuration
parameter.

? I’m not the one who looked it up using an AI.
I’m the one who tried it and discovered that you have to set os_mon up first.

1 Like

Thx a lot. Appreciate it.

The image isn’t for you.

Using os_mon in some cases isn’t possible for me by some restrictions. Going to write out example of using “df“ within parsing reply soon.

maybe as a starter:

-record( dinf, {disk,
				mountpoint,
				totalBytes,
				usedBytes,
				freeBytes,
				percentUsed
				}
		).

-spec diskinfo( string() ) -> #dinf{} | error.
diskinfo( Path ) ->
	Df = os:cmd( lists:concat(["/usr/bin/df -h ",Path])),
	Result = lists:nth( 2, string:split(Df,"\n",all) ),
	case length(Result) > 0 of
		true ->
			[A,B,C,D,E,F] = string:lexemes(Result," "),
			#dinf{disk=A, mountpoint=F, totalBytes=B, usedBytes=C, freeBytes=D, percentUsed=E};
		false ->
			error
	end.
1 Like

Thx. Already done it for myself. :-)))) Going to publish it soon. In my approach using JSON reply. Based on this article Printing df -h output in json format - UNIX for Beginners Q & A - Unix Linux Community or this https://stackoverflow.com/questions/35211716/store-output-diskspace-df-h-json for the FreeBSD/Linux usage.