简体   繁体   中英

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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM