Search documentation of snmpkit

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

Intelligent request routing and load balancing for SNMP requests.

This module provides sophisticated routing strategies to optimize request distribution across multiple engines and target devices, with support for load balancing, affinity routing, and performance-based routing decisions.

# Summary

## Functions

add_engine(router, engine_spec)

Adds an engine to the routing pool.

attempt_engine_recovery(router, engine_name)

Attempts to recover a failed engine.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

configure_batch_strategy(router, strategy_config)

Configures batch processing strategy.

configure_engines(router, config)

Configures engine settings.

configure_health_check(router, config)

Configures health check settings.

get_engine_health(router)

Gets engine health information.

get_stats(router)

Gets routing statistics and engine health.

mark_engine_healthy(router, engine_name)

Marks an engine as healthy.

mark_engine_unhealthy(router, engine_name, reason)

Marks an engine as unhealthy.

remove_engine(router, engine_name)

Removes an engine from the routing pool.

route_batch(router, requests, opts \\ [])

Routes multiple requests as a batch.

route_request(router, request, opts \\ [])

Routes a request to the best available engine.

set_engine_weights(router, weights)

Sets engine weights for weighted routing.

set_strategy(router, strategy)

Updates routing strategy.

start_link(opts \\ [])

Starts the request router.

# Functions

# add_engine(router, engine_spec)

Adds an engine to the routing pool.

# attempt_engine_recovery(router, engine_name)

Attempts to recover a failed engine.

# child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# configure_batch_strategy(router, strategy_config)

Configures batch processing strategy.

# configure_engines(router, config)

Configures engine settings.

# configure_health_check(router, config)

Configures health check settings.

# get_engine_health(router)

Gets engine health information.

# get_stats(router)

Gets routing statistics and engine health.

# mark_engine_healthy(router, engine_name)

Marks an engine as healthy.

# mark_engine_unhealthy(router, engine_name, reason)

Marks an engine as unhealthy.

# remove_engine(router, engine_name)

Removes an engine from the routing pool.

# route_batch(router, requests, opts \\ [])

Routes multiple requests as a batch.

## Parameters

- `router` - Router PID or name
- `requests` - List of request specifications
- `opts` - Routing options

## Examples

    requests = [
      %{type: :get, target: "device1", oid: "sysDescr.0"},
      %{type: :get, target: "device2", oid: "sysUpTime.0"}
    ]

    {:ok, results} = SnmpKit.SnmpMgr.Router.route_batch(router, requests)

# route_request(router, request, opts \\ [])

Routes a request to the best available engine.

## Parameters

- `router` - Router PID or name
- `request` - Request specification
- `opts` - Routing options

## Examples

    request = %{
      type: :get,
      target: "192.168.1.1",
      oid: "sysDescr.0"
    }

    {:ok, result} = SnmpKit.SnmpMgr.Router.route_request(router, request)

# set_engine_weights(router, weights)

Sets engine weights for weighted routing.

# set_strategy(router, strategy)

Updates routing strategy.

# start_link(opts \\ [])

Starts the request router.

## Options

- `:strategy` - Routing strategy (:round_robin, :least_connections, :weighted, :affinity)
- `:engines` - List of engine specifications
- `:health_check_interval` - Health check interval in ms (default: 30000)
- `:max_retries` - Maximum retry attempts (default: 3)

## Examples

    {:ok, router} = SnmpKit.SnmpMgr.Router.start_link(
      strategy: :least_connections,
      engines: [
        %{name: :engine1, weight: 2, max_load: 100},
        %{name: :engine2, weight: 1, max_load: 50}
      ]
    )