sysguard_mem
The `sysguard_mem` directive sets memory-based thresholds to limit traffic based on memory usage statistics.
Description
The sysguard_mem directive is part of the NGINX Sysguard module, which is designed to help manage server resources more effectively by imposing traffic control based on specific memory conditions. This directive can take one or two arguments that specify the memory thresholds to monitor. The accepted parameters include swapratio, which indicates the allowable percentage of swap memory usage, and free, which defines the minimum amount of free physical memory required before certain actions are taken. An action can also be linked to these conditions, allowing configurable responses like returning a specific status code when thresholds are exceeded.
When using sysguard_mem, if the specified memory condition is met—either the percentage of swap memory used exceeds the defined ratio or the free memory falls below the set limit—NGINX triggers the designated action, effectively managing server load. This capability makes it essential for preventing the server from becoming overloaded, particularly under heavy traffic or memory-intensive operations. Thus, you can configure multiple sysguard_mem directives for different locations or server blocks to apply tailored resource management depending on the context.
Additionally, the directive's behavior can be influenced by others such as sysguard and sysguard_mode, allowing for complex decision-making processes based on combined conditions, which enhances the robustness of your server configurations against resource exhaustion.
Config Example
location /api {
sysguard on;
sysguard_mem swapratio=20% action=/swaplimit;
sysguard_mem free=100M action=/freelimit;
}Ensure that the thresholds you set are achievable based on the server's capacity; otherwise, actions may be triggered too frequently.
Be careful with the action specified; misconfiguring it can lead to unnecessarily returning errors to users.
Remember that only one action can be linked per sysguard_mem directive if both parameters are specified. Each directive should be distinct if multiple actions are needed.