0
0
RabbitMQdevops~5 mins

Memory and disk alarms in RabbitMQ - Commands & Configuration

Choose your learning style9 modes available
Introduction
RabbitMQ needs enough memory and disk space to work well. Memory and disk alarms help stop RabbitMQ from crashing by pausing message handling when resources are low.
When RabbitMQ server memory usage is close to full and you want to prevent crashes.
When disk space on the RabbitMQ server is running low and you want to avoid data loss.
When running RabbitMQ on a shared server and you want to ensure it does not use too many resources.
When you want to monitor RabbitMQ health and get alerts if memory or disk space is too low.
When you want to automatically pause message publishing to avoid overload during resource shortage.
Commands
Check the current status of RabbitMQ including memory and disk alarm states.
Terminal
rabbitmqctl status
Expected OutputExpected
Status of node rabbit@my-server ... [{pid,12345}, {running_applications,[{rabbit,"RabbitMQ","3.10.7"}, {os_mon,"CPO CXC 138 46"}]}, {alarms,[memory, disk_free]}, {memory,[{total,104857600},{connection_readers,1024000}]}, {disk_free,524288000}]
Set the memory alarm threshold to 40% of total RAM to trigger alarms earlier and protect RabbitMQ.
Terminal
rabbitmqctl set_vm_memory_high_watermark 0.4
Expected OutputExpected
No output (command runs silently)
Set the disk free alarm threshold to 500 MB to stop RabbitMQ when disk space is low.
Terminal
rabbitmqctl set_disk_free_limit 500000000
Expected OutputExpected
No output (command runs silently)
Clear the memory alarm manually after freeing memory or fixing the issue.
Terminal
rabbitmqctl clear_memory_alarm
Expected OutputExpected
No output (command runs silently)
Clear the disk free alarm manually after freeing disk space or fixing the issue.
Terminal
rabbitmqctl clear_disk_free_alarm
Expected OutputExpected
No output (command runs silently)
Key Concept

If you remember nothing else from this pattern, remember: RabbitMQ stops accepting messages when memory or disk space is too low to protect itself.

Common Mistakes
Not setting memory or disk alarm thresholds, relying on defaults.
Defaults may be too high or low for your environment, causing unexpected pauses or crashes.
Set memory and disk alarm thresholds based on your server capacity and workload.
Ignoring alarms and not clearing them after fixing resource issues.
RabbitMQ will remain paused and not process messages until alarms are cleared.
Use rabbitmqctl clear_memory_alarm and clear_disk_free_alarm commands after resolving issues.
Setting disk free limit too low, causing RabbitMQ to run out of disk space.
Running out of disk space can cause data loss or RabbitMQ crashes.
Set a safe disk free limit that leaves enough space for RabbitMQ to operate.
Summary
Use rabbitmqctl status to check memory and disk alarm states.
Set memory and disk alarm thresholds with rabbitmqctl set_vm_memory_high_watermark and set_disk_free_limit.
Clear alarms manually with rabbitmqctl clear_memory_alarm and clear_disk_free_alarm after fixing resource issues.