SnmpKit.SnmpMgr.Metrics (snmpkit v0.6.4)
Comprehensive metrics collection and monitoring for SNMP operations.
This module provides real-time metrics collection, aggregation, and reporting for all SNMP operations including request latency, success rates, throughput, and resource utilization across engines, pools, and circuit breakers.
Summary
Functions
Returns a specification to start this module under a supervisor.
Records a counter metric.
Records a gauge metric (current value).
Gets current metrics snapshot.
Gets aggregated metrics summary.
Gets metrics for a specific time window.
Records a histogram metric (for latency/duration measurements).
Resets all metrics.
Starts the metrics collector.
Subscribes to metrics updates.
Records timing for a function execution.
Unsubscribes from metrics updates.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
Records a counter metric.
Parameters
metrics
- Metrics PID or namemetric_name
- Name of the metricvalue
- Value to add (default: 1)tags
- Optional tags for the metric
Examples
SnmpKit.SnmpMgr.Metrics.counter(metrics, :requests_total, 1, %{target: "device1"})
Records a gauge metric (current value).
Parameters
metrics
- Metrics PID or namemetric_name
- Name of the metricvalue
- Current valuetags
- Optional tags for the metric
Examples
SnmpKit.SnmpMgr.Metrics.gauge(metrics, :active_connections, 15, %{pool: "main"})
Gets current metrics snapshot.
Gets aggregated metrics summary.
Gets metrics for a specific time window.
Records a histogram metric (for latency/duration measurements).
Parameters
metrics
- Metrics PID or namemetric_name
- Name of the metricvalue
- Value to recordtags
- Optional tags for the metric
Examples
SnmpKit.SnmpMgr.Metrics.histogram(metrics, :request_duration_ms, 150, %{operation: "get"})
Resets all metrics.
Starts the metrics collector.
Options
:window_size
- Metrics window size in seconds (default: 60):retention_period
- How long to keep metrics in seconds (default: 3600):collection_interval
- Collection frequency in ms (default: 1000)
Examples
{:ok, metrics} = SnmpKit.SnmpMgr.Metrics.start_link(
window_size: 120,
retention_period: 7200
)
Subscribes to metrics updates.
Records timing for a function execution.
Parameters
metrics
- Metrics PID or namemetric_name
- Name of the metricfun
- Function to timetags
- Optional tags for the metric
Examples
result = SnmpKit.SnmpMgr.Metrics.time(metrics, :snmp_get_duration, fn ->
SnmpKit.SnmpMgr.get("device1", "sysDescr.0")
end, %{device: "device1"})
Unsubscribes from metrics updates.