Skip to content

Instantly share code, notes, and snippets.

@seriyps
Last active April 29, 2022 08:38
Show Gist options
  • Save seriyps/db52ff310021ee243d1e4b7fe48a3442 to your computer and use it in GitHub Desktop.
Save seriyps/db52ff310021ee243d1e4b7fe48a3442 to your computer and use it in GitHub Desktop.
Uptime of Erlang node
-export([uptime/0, uptime/1, uptime_string/0]).
%% @doc uptime in native time units
uptime() ->
erlang:monotonic_time() - erlang:system_info(start_time).
%% @doc uptime in specified time units
uptime(Unit) ->
erlang:convert_time_unit(uptime(), native, Unit).
%% @doc uptime as binary formatted string
uptime_string() ->
{D, {H, M, S}} = calendar:seconds_to_daystime(uptime(seconds)),
list_to_binary(
io_lib:format("~pd, ~p:~p:~p", [D, H, M, S])).
uptime2() ->
{StartTime, _} = erlang:statistics(wall_clock),
{D, {H, M, S}} = calendar:seconds_to_daystime(StartTime div 1000),
list_to_binary(
io_lib:format("~pd, ~p:~p:~p", [D, H, M, S])).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment