简体   繁体   English

你如何检查Phoenix / Elixir / Erlang应用程序的正常运行时间?

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

How do you check the uptime of a Phoenix/Elixir/Erlang application? 你如何检查Phoenix / Elixir / Erlang应用程序的正常运行时间? If you do :observer.start() and look at the System tab, you can see the uptime in the Statistics area. 如果执行:observer.start()并查看“系统”选项卡,则可以在“统计”区域中查看正常运行时间。 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) : 您可以使用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. 这是Erlang运行时系统中所有线程的运行时间总和,因此可能大于挂钟时间。

Or statistics(wall_clock) : 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. wall_clock可以与运行时相同的方式使用,除了测量实时而不是运行时或CPU时间。

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 . 因此,然后你将有时间Time1Time2 For more information take a look at erlang:statistics/1 有关更多信息,请查看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). 注意:如果您想要自Erlang VM启动以来经过的总时间,您可以从元组中获取第一个元素: {Total_Time, Time_Since_Last_Call} = statistics(wall_clock).

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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