How to get RabbitMQ uptime

Get and display RabbitMQ uptime measured in seconds using three different methods.

Get uptime using Erlang expression

Get uptime using Erlang expression.

$ sudo rabbitmqctl eval "{Total_Wallclock_Time, _} = erlang:statistics(wall_clock),Total_Wallclock_Time div 1000." 
18309

rabbitmqctl utility

Install jq utility.

$ sudo apt install jq

Get uptime using rabbitmqctl utility.

$ sudo rabbitmqctl status --formatter=json | jq .uptime
18421

Management API

Install jq utility.

$ sudo apt install jq

Get uptime using management API.

$ curl --silent --user admin:password http://localhost:15672/api/nodes | jq ".[].uptime/1000 | floor" 
19075

You need to take into account up to 10 seconds delay when using Management API as this value is not refreshed immediately.

References

Erlang Run-Time System Application (ERTS) Reference Manual