Search documentation of snmpkit

# SnmpKit.SnmpMgr.CircuitBreaker (snmpkit v1.3.17)

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

call(cb, target, fun, timeout \\ 5000)

Executes a function with circuit breaker protection.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

close_circuit(cb, target)

Manually closes a circuit breaker for a target.

configure(cb, config)

Configures circuit breaker settings.

configure_target(cb, target, config)

Configures settings for a specific target.

force_half_open(cb, target)

Forces a circuit breaker to half-open state.

force_open(cb, target)

Forces a circuit breaker to open state.

get_all_targets(cb)

Gets all active targets.

get_config(cb, target)

Gets configuration for a specific target.

get_global_stats(cb)

Gets global circuit breaker statistics.

get_state(cb, target)

Gets the current state of a circuit breaker for a target.

get_stats(cb)

Gets statistics for all circuit breakers.

get_stats(cb, target)

Gets statistics for a specific target.

open_circuit(cb, target)

Manually opens a circuit breaker for a target.

record_failure(cb, target, reason)

Records a failure for a target.

record_success(cb, target)

Records a successful operation for a target.

remove_target(cb, target)

Removes a target from the circuit breaker.

reset(cb, target)

Resets a specific circuit breaker for a target.

reset_all(cb)

Resets all circuit breakers.

start_link(opts \\ [])

Starts the circuit breaker manager.

# Functions

# call(cb, target, fun, timeout \\ 5000)

Executes a function with circuit breaker protection.

## Parameters

- `cb` - Circuit breaker PID or name
- `target` - Target identifier (device address/name)
- `fun` - Function to execute
- `timeout` - 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)

# child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# close_circuit(cb, target)

Manually closes a circuit breaker for a target.

# configure(cb, config)

Configures circuit breaker settings.

# configure_target(cb, target, config)

Configures settings for a specific target.

# force_half_open(cb, target)

Forces a circuit breaker to half-open state.

# force_open(cb, target)

Forces a circuit breaker to open state.

# get_all_targets(cb)

Gets all active targets.

# get_config(cb, target)

Gets configuration for a specific target.

# get_global_stats(cb)

Gets global circuit breaker statistics.

# get_state(cb, target)

Gets the current state of a circuit breaker for a target.

# get_stats(cb)

Gets statistics for all circuit breakers.

# get_stats(cb, target)

Gets statistics for a specific target.

# open_circuit(cb, target)

Manually opens a circuit breaker for a target.

# record_failure(cb, target, reason)

Records a failure for a target.

# record_success(cb, target)

Records a successful operation for a target.

# remove_target(cb, target)

Removes a target from the circuit breaker.

# reset(cb, target)

Resets a specific circuit breaker for a target.

# reset_all(cb)

Resets all circuit breakers.

# start_link(opts \\ [])

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
    )