PropertyDamage.Telemetry.Collector (PropertyDamage v0.2.0)

View Source

Collects and aggregates telemetry events for the dashboard.

The Collector is a GenServer that:

  1. Attaches to PropertyDamage telemetry events
  2. Aggregates metrics (counts, timings, pass/fail rates)
  3. Maintains a sliding window of recent events
  4. Broadcasts updates to subscribers (LiveView processes)

Usage

# Start the collector (typically in your application supervisor)
{:ok, pid} = PropertyDamage.Telemetry.Collector.start_link()

# Subscribe to updates (from a LiveView)
PropertyDamage.Telemetry.Collector.subscribe()

# Get current state
state = PropertyDamage.Telemetry.Collector.get_state()

State Structure

The collector maintains:

  • runs - Total runs started
  • runs_completed - Successful runs
  • runs_failed - Failed runs
  • commands_executed - Total commands executed
  • checks_passed - Total checks passed
  • checks_failed - Total checks failed
  • current_run - Current run info (if running)
  • recent_events - Last N events (sliding window)
  • command_stats - Per-command timing stats
  • check_stats - Per-check pass/fail stats

Summary

Functions

Returns a specification to start this module under a supervisor.

Get the current aggregated state.

Get the PubSub topic for broadcasts.

Reset all collected metrics.

Start the collector.

Subscribe to telemetry updates.

Unsubscribe from telemetry updates.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_state(server \\ __MODULE__)

@spec get_state(GenServer.server()) :: map()

Get the current aggregated state.

pubsub_topic()

@spec pubsub_topic() :: String.t()

Get the PubSub topic for broadcasts.

reset(server \\ __MODULE__)

@spec reset(GenServer.server()) :: :ok

Reset all collected metrics.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Start the collector.

subscribe(server \\ __MODULE__)

@spec subscribe(GenServer.server()) :: :ok

Subscribe to telemetry updates.

The calling process will receive messages of the form: {:telemetry_update, event_type, data}

unsubscribe(server \\ __MODULE__)

@spec unsubscribe(GenServer.server()) :: :ok

Unsubscribe from telemetry updates.