Malachi. ConnectionLimiter
(malachi v0.22.7)
View Source
Tracks active connections per IP address and globally. Rejects new connections when limits exceeded.
Schema
Uses three ETS tables:
:malachi_conn_limits_ip-{ip, count}per-IP counters:malachi_conn_limits_global-{:total, count}global counter:malachi_conn_pids-{pid, ip, monitor_ref}process tracking
Configuration
connection_limit_enabled- Enable/disable connection limiting (default: true)max_connections_per_ip- Max connections per IP (default: 100)max_total_connections- Max total connections (default: 10000)
Summary
Functions
Returns a specification to start this module under a supervisor.
Get connection count for specific IP.
Get statistics about connections.
Get total connection count.
List all connections by IP.
Register a new connection.
Clears all tracked connections: the per-IP and global counters and the process monitors. This does not change limiting behavior; it only resets the tracked state, so it is primarily for tests that need a known-clean baseline (the tracker is process-global, shared with the live server and every other test).
Starts the connection limiter GenServer.
Unregister a connection manually.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Get connection count for specific IP.
Get statistics about connections.
Get total connection count.
List all connections by IP.
Returns map of %{ip => count}.
Register a new connection.
Returns :ok if allowed, or error tuple if limit exceeded.
Examples
register_connection(self(), "192.168.1.1")
#=> :ok
register_connection(self(), "10.0.0.1")
#=> {:error, :connection_limit_exceeded}
Clears all tracked connections: the per-IP and global counters and the process monitors. This does not change limiting behavior; it only resets the tracked state, so it is primarily for tests that need a known-clean baseline (the tracker is process-global, shared with the live server and every other test).
Starts the connection limiter GenServer.
Unregister a connection manually.
Usually not needed as process monitoring handles cleanup automatically.