API Reference Aurora Meter v#0.4.0

View Source

Modules

Aurora Meter — real-time usage metering, plan entitlements, and Stripe-ready billing primitives for Phoenix.

Default billing provider: every operation returns {:error, :not_configured}.

Behaviour for a billing provider. The core ships AuroraMeter.Billing.Noop; the Pro package provides a Stripe implementation. Only ever call a provider through the AuroraMeter.Billing facade.

Fans live counter values out over Phoenix.PubSub on an interval, decoupled from the (slower) database flush, and ships this node's deltas to the other nodes.

Keeps every node's counters converging on the same totals.

Drop-in HEEx components for showing live usage and credit spend. Compiled only when Phoenix.Component is available (the LiveView deps are optional).

Reads and validates Aurora Meter configuration from the :aurora_meter application environment.

The hot path: atomic ETS counter operations.

A prepaid credit ledger per tenant: grant credit, hold an estimate while work runs, settle the actual cost, and read the balance back.

Conversions between the ledger's integer micro-dollars and the units the rest of the world uses.

Plan resolution and the entitlement gate.

Persists buffered usage in idempotent database batches.

Helper for consuming live usage updates in a LiveView (or any process).

Creates and drops the Aurora Meter core tables, in versions.

Resolves the billing period a usage counter belongs to.

Default period source: calendar month in UTC.

A billing plan: an id, a monthly price (minor units / cents), and a map of feature configurations.

Compile-time DSL for declaring billing plans, plus runtime lookups.

A flushed snapshot of a usage counter for one {tenant_key, feature, period_start}. The live value lives in ETS; this row is the durable copy the flusher upserts on an interval.

A tenant's prepaid credit balance, one row per tenant, in micro-dollars (1e-6 USD; see AuroraMeter.Credits.Money).

One append-only entry in a tenant's credit ledger, in micro-dollars.

A raw usage event. Written only for features configured as :durable (and for audit), giving billing-grade exactness beyond the buffered ETS counters.

A flushed snapshot of a usage history bucket (bucket_kind "day", UTC) for one {tenant_key, feature, bucket_start}. Maintained by the flusher alongside the period counters when :history is enabled, and read by AuroraMeter.history/3 for charts.

A tenant's plan assignment. Created locally by AuroraMeter.subscribe/2 (free) or synced from the billing provider (Pro). One row per tenant.

Behaviour for persisting Aurora Meter state, plus dispatch helpers that route to the configured adapter (AuroraMeter.Config.storage/0, default AuroraMeter.Storage.Ecto).

Default AuroraMeter.Storage adapter, backed by the host's Ecto repo (AuroraMeter.Config.repo/0). Counter and event writes use insert_all for throughput. Flushes add deltas in a transaction with a unique batch receipt, so retrying an uncertain commit cannot duplicate usage.

Owns the ETS tables that back real-time metering.

Cached subscription lookups.

Resolves an opaque tenant term into a stable string key.

Default tenant resolver: passes binaries through and stringifies anything that implements String.Chars (integers, atoms, …). A term without String.Chars raises Protocol.UndefinedError — configure a custom AuroraMeter.Tenant implementation for structs.

Helpers for testing an application that uses Aurora Meter.

Mix Tasks

Measures Aurora Meter's hot-path throughput: concurrent AuroraMeter.Counter increments against warm ETS counters (no database on the hot path). This is the evidence behind the BEAM-metering moat claim.

Generates a migration that installs the Aurora Meter tables into the host app.

Installs Aurora Meter into a Phoenix (or plain Ecto) application in one step, powered by Igniter