PacketFlow.Component.Monitoring (packetflow v0.1.0)

Component monitoring interfaces for health checks and metrics

This module provides:

  • Health check interfaces and implementations
  • Metrics collection and reporting
  • Performance monitoring
  • Resource usage tracking
  • Alert and notification systems
  • Monitoring dashboard data

Summary

Functions

Perform health check for a specific component

Returns a specification to start this module under a supervisor.

Clear alerts for a component

Get current alerts

Get current health status for all components

Get all current metrics

Get metrics for a specific component

Get monitoring dashboard data

Callback implementation for GenServer.init/1.

Register a component for monitoring

Subscribe to monitoring events for a component

Unregister a component from monitoring

Update monitoring configuration

Types

health_check()

@type health_check() :: %{
  component_id: atom(),
  status: health_status(),
  message: String.t(),
  timestamp: integer(),
  duration_ms: number(),
  metadata: map()
}

health_status()

@type health_status() :: :healthy | :unhealthy | :degraded | :unknown

metric()

@type metric() :: %{
  name: String.t(),
  type: metric_type(),
  value: metric_value(),
  labels: map(),
  timestamp: integer(),
  component_id: atom()
}

metric_type()

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

metric_value()

@type metric_value() :: number() | %{count: integer(), sum: number(), buckets: map()}

monitoring_config()

@type monitoring_config() :: %{
  health_check_interval: integer(),
  metrics_collection_interval: integer(),
  retention_period: integer(),
  alert_thresholds: map(),
  enabled_checks: [atom()],
  enabled_metrics: [atom()]
}

Functions

check_component_health(component_id)

@spec check_component_health(atom()) :: health_check() | {:error, term()}

Perform health check for a specific component

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear_alerts(component_id)

@spec clear_alerts(atom()) :: :ok

Clear alerts for a component

get_alerts()

@spec get_alerts() :: map()

Get current alerts

get_all_health_status()

@spec get_all_health_status() :: %{required(atom()) => health_check()}

Get current health status for all components

get_all_metrics()

@spec get_all_metrics() :: %{required(atom()) => [metric()]}

Get all current metrics

get_component_metrics(component_id)

@spec get_component_metrics(atom()) :: [metric()] | {:error, term()}

Get metrics for a specific component

get_dashboard_data()

@spec get_dashboard_data() :: map()

Get monitoring dashboard data

init(opts)

Callback implementation for GenServer.init/1.

record_metric(component_id, name, type, value, labels \\ %{})

@spec record_metric(atom(), String.t(), metric_type(), metric_value(), map()) :: :ok

Record a metric for a component

register_component(component_id, metadata \\ %{})

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

Register a component for monitoring

start_link(opts \\ [])

subscribe_to_component(component_id, subscriber_pid)

@spec subscribe_to_component(atom(), pid()) :: :ok

Subscribe to monitoring events for a component

unregister_component(component_id)

@spec unregister_component(atom()) :: :ok

Unregister a component from monitoring

unsubscribe_from_component(component_id, subscriber_pid)

@spec unsubscribe_from_component(atom(), pid()) :: :ok

Unsubscribe from monitoring events

update_config(new_config)

@spec update_config(monitoring_config()) :: :ok | {:error, term()}

Update monitoring configuration