SnmpKit.SnmpMgr.Engine (snmpkit v1.4.0)

High-performance streaming PDU engine with request routing and connection pooling.

This module provides the core infrastructure for handling large volumes of SNMP requests efficiently through connection pooling, request batching, and intelligent routing strategies.

Summary

Functions

Returns a specification to start this module under a supervisor.

Gets connection pool status.

Gets engine statistics and metrics.

Starts the streaming PDU engine.

Gracefully shuts down the engine.

Submits multiple requests as a batch.

Submits a request to the engine for processing.

Types

request()

@type request() :: %{
  :type => atom(),
  :target => term(),
  :oid => term(),
  optional(atom()) => term()
}

result()

@type result() :: {:ok, term()} | {:error, term()}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_pool_status(engine)

@spec get_pool_status(GenServer.server()) :: [map()]

Gets connection pool status.

get_stats(engine)

@spec get_stats(GenServer.server()) :: map()

Gets engine statistics and metrics.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the streaming PDU engine.

Options

  • :pool_size - Number of UDP socket connections to maintain (default: 10)
  • :max_rps - Maximum requests per second (default: 100)
  • :request_timeout - Individual request timeout in ms (default: 5000)
  • :batch_size - Maximum requests per batch (default: 50)
  • :batch_timeout - Maximum time to wait for batch in ms (default: 100)
  • :circuit_breaker - Per-target circuit breaker, off unless configured. [threshold: n, recovery_timeout: ms] opens a target after n consecutive failures (timeouts / send errors) and fails requests to it with {:error, :circuit_breaker_open} for recovery_timeout ms (default 30_000) before letting one request through to probe it.

Examples

{:ok, engine} = SnmpKit.SnmpMgr.Engine.start_link(
  pool_size: 20,
  max_rps: 200,
  batch_size: 100
)

stop(engine)

@spec stop(GenServer.server()) :: :ok

Gracefully shuts down the engine.

submit_batch(engine, requests, opts \\ [])

@spec submit_batch(GenServer.server(), [request()], keyword()) ::
  {:ok, [result()]} | {:error, term()}

Submits multiple requests as a batch.

Parameters

  • engine - Engine PID or name
  • requests - List of request specification maps
  • opts - Batch options

Examples

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

{:ok, batch_ref} = SnmpKit.SnmpMgr.Engine.submit_batch(engine, requests)

submit_request(engine, request, opts \\ [])

@spec submit_request(GenServer.server(), request(), keyword()) :: result()

Submits a request to the engine for processing.

Parameters

  • engine - Engine PID or name
  • request - Request specification map
  • opts - Request options

Examples

request = %{
  type: :get,
  target: "192.168.1.1",
  oid: "1.3.6.1.2.1.1.1.0",
  community: "public"
}

{:ok, ref} = SnmpKit.SnmpMgr.Engine.submit_request(engine, request)