To determine the uptime of a RabbitMQ instance, you would need to check the server logs or use monitoring tools that track the system's uptime. These tools can provide you with information on how long the RabbitMQ server has been running since its last restart or crash. Here are some methods that will provide you with the uptime information of the RabbitMQ node, allowing you to monitor its stability and availability.
Server logsIn the server logs, search for the startup timestamp. These lines often contain information such as the RabbitMQ version, startup timestamp, and other details. You can calculate the uptime by noting the startup timestamp in the log, and comparing it with the current date and time. The difference between the startup timestamp and the current time will give you the uptime of RabbitMQ. Please note that the exact format and content of the log file can vary depending on the RabbitMQ version and configuration.
The log message that indicates the RabbitMQ startup time typically includes the phrase "Started RabbitMQ" or "RabbitMQ started." However, the exact log message format can vary depending on the specific version and configuration of RabbitMQ being used. Here are a couple of examples of a log message that indicates the RabbitMQ startup time:
2023-07-14 09:15:23 [info] <0.1234.0> Application rabbit started on node rabbit@localhost
or
2023-07-13 19:40:32.145185+00:00 [notice] <0.249.0> Logging: configured log handlers are now ACTIVE
RabbitMQ Command-Line ToolsThe “rabbitmqctl status” command provides an overview of the current status and information about a RabbitMQ node. When you run the “rabbitmqctl status” command from the command line on a server where RabbitMQ is installed, it displays the Node uptime, along with additional details. Please make sure that the RabbitMQ user has sufficient privileges, to run the commands below.
$ rabbitmqctl status | grep Uptime
Uptime (seconds): 7183907
Check uptime using the Eval command
$ rabbitmqctl eval "{WT, _} = erlang:statistics(wall_clock), WT div 1000."
25309
RabbitMQ management plugin1. Make sure the RabbitMQ management plugin is installed and enabled. Access the RabbitMQ management web interface by opening a web browser and navigating to http://localhost:15672 (replace localhost with the hostname or IP address of your RabbitMQ server if it's running on a different machine).
2. Login with your RabbitMQ credentials.
3. Once logged in, you will see the RabbitMQ management dashboard. On the Overview page, you can find various details about the RabbitMQ node, including the uptime. information.
Please note: the uptime value in the response will be in milliseconds. You can convert it to a human-readable format (e.g., days, hours, minutes) based on your requirements.
Access uptime from “/api/nodes” using the command line The “/api/nodes” has the “uptime” field, which is the time since the Erlang VM started, in milliseconds. Here is an example to retrieve the uptime at the command line. Please note that the "jq" used below is a command line JSON processor. You can use it to slice, filter, map, and transform structured data.
$ curl --silent -u guest:guest -H "content-type:application/json" http://localhost:15672/api/nodes | jq . | grep uptime
"uptime": 17728576, ⇒ displayed in milliseconds
$ curl --silent -u guest:guest http://localhost:15672/api/nodes | jq ".[].uptime/1000 | round"
16157 ⇒ converted to seconds
RabbitMQ Monitoring ToolThe RabbitMQ Monitoring helps detect issues before they affect the rest of the environment and, eventually, the end users. Prometheus will periodically scrape (read) metrics from the systems it monitors, every 60 seconds by default. RabbitMQ metrics are updated periodically, too, every 5 seconds by default.
The RabbitMQ Prometheus metric Rabbitmq_erlang_uptime_seconds can be used to retrieve the RabbitMQ Node uptime.
References:RabbitMQ DocumentationRabbitMQ Management PluginRabbitMQ MonitoringRabbitMQ Monitoring with Prometheus & GrafanaErlang Run-Time System Application (ERTS) Reference Manual