Raxol.Terminal.Metrics.UnifiedMetrics (Raxol v0.5.0)

View Source

Unified metrics system for the Raxol terminal emulator. This module provides centralized metrics collection for:

  • Performance metrics (response times, throughput)
  • Resource usage (memory, CPU)
  • Error tracking
  • Usage statistics

Summary

Functions

Returns a specification to start this module under a supervisor.

Cleans up old metrics.

Exports metrics in the configured format.

Gets error statistics.

Gets the current value of a metric.

Records an error event.

Records a metric value.

Starts the unified metrics manager.

Types

metric_config()

@type metric_config() :: %{
  retention_period: non_neg_integer(),
  aggregation_interval: non_neg_integer(),
  alert_thresholds: map(),
  export_format: :prometheus | :json | :custom
}

metric_id()

@type metric_id() :: term()

metric_state()

@type metric_state() :: %{
  id: metric_id(),
  type: metric_type(),
  value: metric_value(),
  timestamp: integer(),
  labels: map(),
  metadata: map()
}

metric_type()

@type metric_type() :: :counter | :gauge | :histogram | :summary

metric_value()

@type metric_value() :: number() | map() | list()

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

cleanup_metrics(opts \\ [])

Cleans up old metrics.

Parameters

  • opts - Cleanup options
    • :before - Timestamp before which to clean up

export_metrics(opts \\ [])

Exports metrics in the configured format.

Parameters

  • opts - Export options
    • :format - Override the default export format
    • :time_range - Time range to export

get_error_stats(opts \\ [])

Gets error statistics.

Parameters

  • opts - Get options
    • :time_range - Time range to query
    • :severity - Filter by severity

get_metric(name, opts \\ [])

Gets the current value of a metric.

Parameters

  • name - The metric name
  • opts - Get options
    • :labels - Filter by labels
    • :time_range - Time range to query

record_error(error, opts \\ [])

Records an error event.

Parameters

  • error - The error to record
  • opts - Recording options
    • :severity - Error severity
    • :context - Error context
    • :metadata - Additional metadata

record_metric(name, value, opts \\ [])

Records a metric value.

Parameters

  • name - The metric name
  • value - The metric value
  • opts - Recording options
    • :type - Metric type (:counter, :gauge, :histogram, :summary)
    • :labels - Metric labels
    • :metadata - Additional metadata

start_link(opts \\ [])

Starts the unified metrics manager.

Options

  • :retention_period - How long to keep metrics (in milliseconds)
  • :aggregation_interval - How often to aggregate metrics (in milliseconds)
  • :alert_thresholds - Thresholds for alerting
  • :export_format - Format for exporting metrics