pharos

Public API.

start_link/1 boots the entire pharos supervision tree from a Config. The returned Pharos handle lets callers subscribe to alert events, unsubscribe later, and stop everything when done.

Example

import pharos
import pharos/config
import pharos/statistic

let assert Ok(started) =
  pharos.start_link(
    config.new()
    |> config.with_statistics([
      statistic.poll(statistic.BeamMemory),
      statistic.poll_every(statistic.BeamRunQueues, 500),
    ])
    |> config.with_thresholds([config.TotalMemory(above: 500.0)]),
  )

let assert Ok(_handler) =
  pharos.subscribe(started.data, fn(event) { handle(event) })

Types

Opaque handle returned by start_link. Pass it to subscribe, unsubscribe, and stop.

pub opaque type Pharos

Reasons start_link/1 can fail.

pub type StartError {
  SupervisorStartFailed(reason: String)
  TelemetryAttachFailed(reason: String)
}

Constructors

  • SupervisorStartFailed(reason: String)

    The OTP supervisor itself could not be started; carries the reason.

  • TelemetryAttachFailed(reason: String)

    The supervisor started but the telemetry handler could not be attached. The supervisor (and all its children) is shut down before returning this error so we don’t leak processes.

Values

pub fn start_link(
  config: config.Config,
) -> Result(actor.Started(Pharos), StartError)

Boot pharos from config.

Generates stable registered names for the event bus and one per threshold, builds the supervision tree, then attaches a single telemetry handler that decodes events and routes breach/recover casts to the matching alert managers.

pub fn stop(pharos: Pharos) -> Nil

Stop pharos: detach the telemetry handler, then shut down the supervision tree. Safe to call multiple times - extra calls become no-ops once the supervisor is already gone.

pub fn subscribe(
  pharos: Pharos,
  on_event: fn(alert.AlertEvent) -> Nil,
) -> Result(event_bus.HandlerId, event_manager.AddError(Nil, Nil))

Subscribe on_event to the alert event bus. Returns an opaque handle that can be passed to unsubscribe.

pub fn unsubscribe(
  pharos: Pharos,
  handler: event_bus.HandlerId,
) -> Result(Nil, event_manager.RemoveError(Nil, Nil))

Unsubscribe a previously registered handler.

Search Document