Raxol.Core.Metrics (Raxol v2.0.1)

View Source

Core metrics module for Raxol framework.

This module provides basic metrics collection and recording functionality with pure functional error handling patterns.

Summary

Functions

Clears all recorded metrics.

Gets all recorded metrics.

Initializes the metrics system.

Records a metric with the given name, value, and optional tags.

Functions

clear_metrics()

@spec clear_metrics() ::
  :ok
  | {:error,
     {:metrics_clear_failed,
      :clear_collector_timeout
      | :clear_aggregator_timeout
      | {:clear_collector_exit, term()}
      | {:clear_aggregator_exit, term()}}}

Clears all recorded metrics.

Returns

  • :ok - Metrics cleared successfully
  • {:error, reason} - Failed to clear metrics

get_metrics()

@spec get_metrics() :: {:ok, map()} | {:error, term()}

Gets all recorded metrics.

Returns

  • {:ok, metrics} - Map of recorded metrics
  • {:error, reason} - Failed to get metrics

init(options \\ [])

@spec init(keyword()) :: :ok | {:error, term()}

Initializes the metrics system.

Parameters

  • options - Configuration options for metrics (optional)

Returns

  • :ok - Metrics system initialized successfully
  • {:error, reason} - Failed to initialize metrics system

record(name, value, tags \\ [])

@spec record(String.t(), any(), keyword()) :: :ok

Records a metric with the given name, value, and optional tags.

Parameters

  • name - Metric name
  • value - Metric value (number, string, or map)
  • tags - Optional tags as keyword list

Returns

  • :ok - Metric recorded successfully
  • {:error, reason} - Failed to record metric

Example

Raxol.Core.Metrics.record("render_time", 150, [component: "table"])
Raxol.Core.Metrics.record("user_action", "button_click", [screen: "main"])