Pharos

Package VersionHex DocsErlang CompatibleLicense

Built with Nix[Nix] Build & Test

BEACON / PHAROS (φάρος), (...) The system was reportedly created by Leo the Mathematician, who devised a code tor the interpretation of signals, and had two identical water clocks (see Horologion) made for the terminal stations. His work took account of the difference in longitude and of the time the signal needed for transmission. Modern experiments suggest that one hour would suffice for the entire distance. The beacons consisted of huge bonfires on platforms or towers within fortifications on isolated hills. (...) 1

Pharos is a decentralized "smart sensor" for the BEAM: a producer-only monitor and alert manager that watches a node and its host, evaluates thresholds locally, and streams metrics to a central collector, while staying alive through network partitions.

It is built as a plugin over :telemetry and telemetry_poller, and runs as a supervised OTP application that you embed in your own program via pharos.start_link/1.

Features

Installation

gleam add pharos

Pharos targets the Erlang runtime (OTP 27+). Host disk/CPU collection uses OTP's os_mon, native delivery uses distributed Erlang (ETF over the distribution protocol).

Quick start

import pharos
import pharos/alert
import pharos/config
import pharos/statistic
pub fn main() {
let assert Ok(started) =
pharos.start_link(
config.new()
|> config.with_statistics([
statistic.poll(statistic.BeamMemory),
statistic.poll_every(statistic.BeamRunQueues, 500),
statistic.poll(statistic.HostCpu),
])
|> config.with_thresholds([
config.TotalMemory(above: 500.0),
config.HostCpuUtil(above: 85.0),
]),
)
// React to firing / resolved alerts on the event bus.
let assert Ok(_handler) =
pharos.subscribe(started.data, fn(event) {
case event {
alert.AlertFiring(id:, level:, diagnostic:) -> handle_firing(id, level, diagnostic)
alert.AlertResolved(id:) -> handle_resolved(id)
}
})
// ... later, when shutting the owning process down:
// pharos.stop(started.data)
}

See the Quick Start and the usage guide & architecture for thresholds, custom probes, alert sinks, and the resilient Brain metric stream.

Documentation

Development

The project uses devenv and Nix for a hermetic development environment:

nix develop

Or, if you are already using direnv:

direnv allow .
  1. The Oxford Dictionary of Byzantium, Vol I.