Raxol. Core. Metrics. MetricsCollector
(Raxol v2.6.0)
View Source
ETS-backed metrics collection for high-throughput metric recording.
Uses ETS tables for concurrent write access, avoiding GenServer mailbox serialization that bottlenecks write-heavy metric workloads.
Design
- Writes: Direct ETS inserts from any process (no serialization)
- Reads: Direct ETS lookups (no blocking)
- GenServer: Only for lifecycle management and periodic tasks
Usage
# Record metrics (can be called from any process)
MetricsCollector.record_metric(:request_time, :performance, 45.2)
MetricsCollector.record_performance(:parse_time, 3.3)
MetricsCollector.record_resource(:memory_mb, 128.5)
# Read metrics
MetricsCollector.get_metric(:request_time, :performance)
MetricsCollector.get_all_metrics()ETS Tables
raxol_metrics- Main metrics storage (ordered_set for time-ordered queries)raxol_metrics_meta- Metadata and aggregates
Summary
Functions
Returns a specification to start this module under a supervisor.
Clears all metrics.
Clears all metrics (with optional parameter for compatibility).
Gets all metrics grouped by type.
Gets metric entries for a name and type.
Gets metric statistics (count, latest value, etc.)
Alias for get_all_metrics/0.
Gets metrics for a specific metric name and tags.
Gets metrics by type.
Records a custom metric.
Records a metric value. Can be called from any process.
Records an operation metric.
Records a performance metric.
Records a resource metric.
Stops the metrics collector.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec clear_metrics() :: :ok
Clears all metrics.
Clears all metrics (with optional parameter for compatibility).
@spec get_all_metrics() :: map()
Gets all metrics grouped by type.
Examples
MetricsCollector.get_all_metrics()
# => %{
# performance: %{request_time: [...], parse_time: [...]},
# resource: %{memory_mb: [...]}
# }
Gets metric entries for a name and type.
Examples
MetricsCollector.get_metric(:request_time, :performance)
# => [%{value: 45.2, timestamp: ~U[...], tags: []}, ...]
@spec get_metric_stats(atom(), atom()) :: %{ count: non_neg_integer(), latest: term(), min: number() | nil, max: number() | nil, avg: number() | nil }
Gets metric statistics (count, latest value, etc.)
Alias for get_all_metrics/0.
Gets metrics for a specific metric name and tags.
Gets metrics by type.
Records a custom metric.
Records a metric value. Can be called from any process.
Parameters
name- Metric name (atom)type- Metric type (:performance, :resource, :operation, :custom)value- Metric value (number or map)opts- Options including:tags
Examples
MetricsCollector.record_metric(:request_time, :performance, 45.2)
MetricsCollector.record_metric(:cache_hits, :operation, 1, tags: [:api])
Records an operation metric.
Records a performance metric.
Records a resource metric.
Stops the metrics collector.