Phoenix.SocketClient.PerformanceMonitor (phoenix_socket_client v0.8.0)
View SourceComprehensive performance monitoring for Phoenix Socket Client.
This module provides centralized performance monitoring and metrics collection from all optimization components. It aggregates data from binary pools, route caches, hibernation manager, and transport performance to provide a complete view of system performance.
Features
- Real-time performance metrics
- Memory usage monitoring
- Connection performance tracking
- Cache hit rate analysis
- Hibernation effectiveness
- Network throughput metrics
- Alerting for performance issues
Usage
The monitor is automatically started by the socket supervisor and provides performance data through various interfaces.
Metrics Collected
- Binary pool efficiency and memory savings
- Route cache hit rates and size
- Process hibernation statistics
- Network throughput and latency
- Message processing rates
- Memory usage patterns
- Error rates and types
Summary
Functions
Returns a specification to start this module under a supervisor.
Triggers immediate metrics collection.
Generates performance report.
Gets current performance metrics.
Gets historical performance metrics.
Gets performance summary statistics.
Starts the performance monitor.
Updates alert thresholds.
Types
@type metrics() :: %{ timestamp: integer(), binary_pool: map(), route_cache: map(), hibernation: map(), transport: map(), system: map(), alerts: [map()] }
Performance metrics structure
@type opts() :: [ collection_interval: non_neg_integer(), retention_period: non_neg_integer(), registry_name: atom(), alert_thresholds: map() ]
Monitor configuration options
@type t() :: %Phoenix.SocketClient.PerformanceMonitor{ alert_thresholds: map(), collection_interval: non_neg_integer(), collection_timer: reference() | nil, current_metrics: metrics(), metrics_history: :ets.tid(), registry_name: atom() | nil, retention_period: non_neg_integer(), stats: %{ collections: non_neg_integer(), alerts_triggered: non_neg_integer(), uptime_start: integer() } }
Monitor state
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec collect_metrics(pid()) :: :ok
Triggers immediate metrics collection.
Useful for on-demand performance checks.
Generates performance report.
Creates a comprehensive performance report in various formats.
Gets current performance metrics.
Returns the most recent performance data collected.
Gets historical performance metrics.
Returns metrics for a specified time range.
Gets performance summary statistics.
Returns aggregated statistics for the monitoring period.
@spec start_link(opts()) :: GenServer.on_start()
Starts the performance monitor.
Options
:collection_interval- Metrics collection interval (default: 30000ms):retention_period- How long to retain metrics (default: 1800000ms):registry_name- Registry name for component discovery:alert_thresholds- Alerting thresholds map
Updates alert thresholds.
Modifies the thresholds used for performance alerting.