SnmpKit.SnmpMgr.CircuitBreaker (snmpkit v0.6.4)
Circuit breaker pattern implementation for SNMP device failure protection.
This module implements the circuit breaker pattern to prevent cascading failures when SNMP devices become unresponsive. It provides automatic failure detection, recovery attempts, and configurable thresholds for different failure scenarios.
Summary
Functions
Executes a function with circuit breaker protection.
Returns a specification to start this module under a supervisor.
Manually closes a circuit breaker for a target.
Configures circuit breaker settings.
Configures settings for a specific target.
Forces a circuit breaker to half-open state.
Forces a circuit breaker to open state.
Gets all active targets.
Gets configuration for a specific target.
Gets global circuit breaker statistics.
Gets the current state of a circuit breaker for a target.
Gets statistics for all circuit breakers.
Gets statistics for a specific target.
Manually opens a circuit breaker for a target.
Records a failure for a target.
Records a successful operation for a target.
Removes a target from the circuit breaker.
Resets a specific circuit breaker for a target.
Resets all circuit breakers.
Starts the circuit breaker manager.
Functions
Executes a function with circuit breaker protection.
Parameters
cb
- Circuit breaker PID or nametarget
- Target identifier (device address/name)fun
- Function to executetimeout
- Operation timeout in ms
Examples
result = SnmpKit.SnmpMgr.CircuitBreaker.call(cb, "192.168.1.1", fn ->
SnmpKit.SnmpMgr.get("192.168.1.1", "sysDescr.0")
end, 5000)
Returns a specification to start this module under a supervisor.
See Supervisor
.
Manually closes a circuit breaker for a target.
Configures circuit breaker settings.
Configures settings for a specific target.
Forces a circuit breaker to half-open state.
Forces a circuit breaker to open state.
Gets all active targets.
Gets configuration for a specific target.
Gets global circuit breaker statistics.
Gets the current state of a circuit breaker for a target.
Gets statistics for all circuit breakers.
Gets statistics for a specific target.
Manually opens a circuit breaker for a target.
Records a failure for a target.
Records a successful operation for a target.
Removes a target from the circuit breaker.
Resets a specific circuit breaker for a target.
Resets all circuit breakers.
Starts the circuit breaker manager.
Options
:failure_threshold
- Number of failures before opening circuit (default: 5):recovery_timeout
- Time to wait before attempting recovery in ms (default: 30000):timeout_threshold
- Request timeout threshold in ms (default: 10000):half_open_max_calls
- Max calls in half-open state (default: 3)
Examples
{:ok, cb} = SnmpKit.SnmpMgr.CircuitBreaker.start_link(
failure_threshold: 10,
recovery_timeout: 60_000
)