pharos/alert

Types

Configuration for a single alert rule gen_statem instance. Pass to alert_manager.start_link/2.

pub type AlertData {
  AlertData(
    id: String,
    level: AlertLevel,
    soak_period_ms: Int,
    cool_period_ms: Int,
    window: option.Option(WindowSpec),
  )
}

Constructors

  • AlertData(
      id: String,
      level: AlertLevel,
      soak_period_ms: Int,
      cool_period_ms: Int,
      window: option.Option(WindowSpec),
    )

    Arguments

    id

    Unique string ID for this alert rule (e.g. "total_memory").

    level

    Severity level carried in AlertFiring events.

    soak_period_ms

    Milliseconds the threshold must stay breached before the alert fires. Set to 0 to skip the Pending state and fire immediately.

    cool_period_ms

    Milliseconds recovery must hold before the alert resolves.

    window

    When Some, the manager evaluates a sliding window of samples instead of a per-tick breach signal. Windowed rules use soak_period_ms: 0 (the window is the debounce); cool_period_ms still applies.

Events broadcast over the gen_event alert dispatcher bus.

pub type AlertEvent {
  AlertFiring(id: String, level: AlertLevel, diagnostic: String)
  AlertResolved(id: String)
}

Constructors

  • AlertFiring(id: String, level: AlertLevel, diagnostic: String)

    Threshold has been continuously breached for longer than soak_period_ms. diagnostic is a snapshot of VM state captured at the moment the soak timer fires.

  • AlertResolved(id: String)

    System recovered and stayed healthy for at least cool_period_ms.

Alert severity level attached to a firing alert.

pub type AlertLevel {
  Warning
  Critical
}

Constructors

  • Warning
  • Critical

The four states of the alert lifecycle state machine.

pub type AlertState {
  Clear
  Pending
  Firing
  Cooling
}

Constructors

  • Clear

    System is healthy; no timer running.

  • Pending

    Threshold just breached; soak timer is counting down.

  • Firing

    Alert is active - threshold was breached for the full soak period.

  • Cooling

    System recovered; cool-down timer is counting down.

How a sliding window aggregates its samples into a breach decision.

pub type WindowMode {
  Average
  Percentage(at_least: Float)
}

Constructors

  • Average

    Breached when the mean of the window’s values exceeds limit.

  • Percentage(at_least: Float)

    Breached when the fraction of samples exceeding limit is at least at_least (a ratio in [0.0, 1.0]).

Runtime parameters for a windowed alert rule. limit is the inner threshold’s comparison limit (widened to a float); window_ms is the window duration; mode selects average vs percentage aggregation.

pub type WindowSpec {
  WindowSpec(window_ms: Int, limit: Float, mode: WindowMode)
}

Constructors

  • WindowSpec(window_ms: Int, limit: Float, mode: WindowMode)

Values

pub fn prune_samples(
  samples: List(#(Int, Float)),
  now: Int,
  window_ms: Int,
) -> List(#(Int, Float))

Drop samples (a #(timestamp_ms, value) list) older than now - window_ms.

pub fn window_breached(
  samples: List(#(Int, Float)),
  now: Int,
  spec: WindowSpec,
) -> Bool

Whether the window currently breaches per spec, considering only samples within [now - window_ms, now]. An empty window is never breaching.

Search Document