Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you check the uptime of a Phoenix/Elixir/Erlang application?

How do you check the uptime of a Phoenix/Elixir/Erlang application? If you do :observer.start() and look at the System tab, you can see the uptime in the Statistics area. But I want to be able to pull that information programmatically and include it in a report. I've figured out where to get most of that data from, but I don't see where it pulls uptime from.

like image 408
Matt Avatar asked May 09 '16 13:05

Matt


1 Answers

You can use either statistics(runtime):

Returns information about runtime, in milliseconds.

This is the sum of the runtime for all threads in the Erlang runtime system and can therefore be greater than the wall clock time.

Or statistics(wall_clock):

Returns information about wall clock. wall_clock can be used in the same manner as runtime, except that real time is measured as opposed to runtime or CPU time.

In both cases, you need to call them at the beginning of your program in order to reset their timers. When you want to print the time passed just do:

{_, Time1} = statistics(runtime).

Or

 {_, Time2} = statistics(wall_clock).

Accordingly, and then you will have the time in Time1 or Time2. For more information take a look at erlang:statistics/1

Note: If you want the total time elapsed since the Erlang VM started you can take the first element from the tuple: {Total_Time, Time_Since_Last_Call} = statistics(wall_clock).

like image 68
A. Sarid Avatar answered Nov 16 '22 03:11

A. Sarid