SnmpKit.Telemetry (snmpkit v2.0.1)

:telemetry events emitted by SnmpKit.

Attach with :telemetry.attach/4 or :telemetry.attach_many/4, or point Telemetry.Metrics / TelemetryMetricsPrometheus at the event names below. Durations are in native time units; convert with System.convert_time_unit(duration, :native, :millisecond).

Spans

Spans emit :start, :stop and :exception events with the standard :telemetry.span/3 measurements (system_time on start, duration on stop and exception).

Event prefixEmitted aroundMetadata
[:snmpkit, :request, _]one single-target PDU exchange (get, get_next, set, get_bulk), retries includedoperation, target, oid, version; on stop result (:ok/:error) and reason
[:snmpkit, :walk, _]a whole single-target walk (walk, walk_table, bulk_walk, adaptive_walk)operation, target, root_oid; on stop result, reason, count (varbinds)
[:snmpkit, :multi, _]a multi-target call (get_multi, get_bulk_multi, walk_multi, walk_table_multi, execute_mixed)operation, request_count; on stop ok_count, error_count

Events

EventMeasurementsMetadata
[:snmpkit, :engine, :timeout]%{count: 1}request_id, target
[:snmpkit, :trap, :received]%{count: 1}kind, version, trap_oid, trap_name, community, source
[:snmpkit, :trap, :rejected]%{count: 1}reason (:community, :decode_error, :unsupported), source
[:snmpkit, :sim, :request]%{duration: native}device_id, port, pdu_type, result (:ok/:error_injected)
[:snmpkit, :agent, :request]%{duration: native}pdu_type, version, principal (community or v3 user), error_status, varbinds (in the response)

Example

:telemetry.attach("log-slow-snmp", [:snmpkit, :request, :stop], fn _event, %{duration: d}, meta, _ ->
  ms = System.convert_time_unit(d, :native, :millisecond)
  if ms > 500, do: Logger.warning("slow SNMP #{meta.operation} to #{meta.target}: #{ms} ms")
end, nil)

Summary

Functions

Emits [:snmpkit | event] with the given measurements and metadata.

Runs fun inside a [:snmpkit, name, _] span. The stop metadata gets result/reason derived from the return value, plus anything extra.(value) returns.

Functions

execute(event, measurements, metadata)

@spec execute([atom()], map(), map()) :: :ok

Emits [:snmpkit | event] with the given measurements and metadata.

span(name, metadata, fun, extra \\ fn _ -> %{} end)

@spec span(atom(), map(), (-> term()), (term() -> map())) :: term()

Runs fun inside a [:snmpkit, name, _] span. The stop metadata gets result/reason derived from the return value, plus anything extra.(value) returns.