Skip to main content

Module metrics

Module metrics 

Source
Expand description

EngineMetrics — process-level event counters for Prometheus export.

Provides a process-global set of std::sync::atomic::AtomicU64 counters that the engine and domain handlers increment at runtime. The metrics_api handler reads them via EngineMetrics::global() without any I/O and renders them in Prometheus text format.

§Design rationale

The mako-engine is a single-process daemon (makod). A process-global static is the simplest, lowest-overhead counter mechanism that:

  • requires zero allocations on the hot path (every command dispatch),
  • is async-safe (atomics need no async context),
  • imposes no external dependency (no prometheus crate in the engine),
  • is observable from metrics_api via a simple method call.

The trade-off: counters reset on process restart (they are not persisted). For a single-process daemon this is acceptable — Prometheus’s rate() function handles counter resets automatically.

§Usage

§Incrementing a counter

use mako_engine::metrics::{EngineMetrics, ProcessOutcome};

// In a workflow handle() or apply() implementation:
EngineMetrics::global().process_initiated("gpke");
EngineMetrics::global().process_completed("gpke", ProcessOutcome::Accepted);
EngineMetrics::global().validation_failed("utilmd", "S2.1");

§Reading counters (metrics endpoint)

let metrics = mako_engine::metrics::EngineMetrics::global();
let snapshot = metrics.snapshot();
// Render snapshot to Prometheus text format.

Structs§

EngineMetrics
Process-global engine metrics counters.
MetricsSnapshot
A point-in-time snapshot of all EngineMetrics counters.

Enums§

ProcessOutcome
Terminal outcome of a MaKo process instance.