eve.core.metrics

Pluggable metrics and tracing interfaces for EVE observability.

This module provides:

Usage:

import eve.core.metrics;

// Enable logging metrics
auto sink = new LoggingMetricsSink();
auto config = EventLoopConfig(16, 16);
config.metrics = sink;
auto loop = EventLoop.create(config);

Types 5

Key-value tag for metric attribution.

Tags allow filtering and grouping of metrics by dimension (e.g., ("kind", "timer"), ("backend", "io_uring")).

Fields
const(char)[] keyTag key (metric dimension name).
const(char)[] valueTag value.
interfaceMetricsSink

Interface for collecting event-loop metrics.

Implement this interface to export EVE metrics to monitoring systems such as Prometheus, StatsD, or any custom backend.

All methods are @safe nothrow to ensure metrics collection never interferes with event-loop operation.

Standard metric names are defined in the EVE addendum:

  • eve.loop.iterations — Counter
  • eve.loop.iteration_us — Timing
  • eve.poll.duration_us — Timing
  • eve.poll.events — Gauge
  • eve.io.dispatched — Counter
  • eve.timers.fired — Counter
  • eve.timers.registered — Gauge
  • eve.watchers.total — Gauge
  • eve.callback.duration_us — Timing

See Also

Methods
void counter(scope const(char)[] name, long delta = 1, scope const(MetricsTag)[] tags = null) @safe nothrow;Record a counter increment.
void gauge(scope const(char)[] name, double value, scope const(MetricsTag)[] tags = null) @safe nothrow;Record a gauge value.
void timing(scope const(char)[] name, long microseconds, scope const(MetricsTag)[] tags = null) @safe nothrow;Record a timing measurement in microseconds.

No-op metrics sink with zero overhead.

All methods are static with empty bodies. When used as a compile-time policy, the compiler inlines these to nothing, ensuring metrics collection has zero cost when disabled.

This is the default sink when no metrics configuration is provided.

Methods
void counter(scope const(char)[], long = 1, scope const(MetricsTag)[] = null) static @safe nothrow @nogc
void gauge(scope const(char)[], double, scope const(MetricsTag)[] = null) static @safe nothrow @nogc
void timing(scope const(char)[], long, scope const(MetricsTag)[] = null) static @safe nothrow @nogc

Logging metrics sink that writes metric events to stderr.

Intended for development and debugging. Each metric call writes a single line to stderr in the format: COUNTER name=delta [tags] GAUGE name=value [tags] TIMING name=us [tags]

Not suitable for high-throughput production use due to stderr contention and formatting overhead.

Example:

auto sink = new LoggingMetricsSink();
sink.counter("eve.loop.iterations");    // writes: COUNTER eve.loop.iterations=1
sink.timing("eve.poll.duration_us", 42); // writes: TIMING eve.poll.duration_us=42

Fields
FILE * _output
Methods
void counter(scope const(char)[] name, long delta = 1, scope const(MetricsTag)[] tags = null) @trusted nothrow
void gauge(scope const(char)[] name, double value, scope const(MetricsTag)[] tags = null) @trusted nothrow
void timing(scope const(char)[] name, long microseconds, scope const(MetricsTag)[] tags = null) @trusted nothrow
void writeTags(scope const(MetricsTag)[] tags) @trusted nothrow
Constructors
this(FILE * output = null)Create a logging metrics sink.
interfaceTracingSink

Interface for distributed tracing span collection.

Implement this to send trace spans to OpenTelemetry, Jaeger, Zipkin, or any compatible tracing backend.

Tracing is opt-in and independent of metrics. When no tracing sink is configured, span creation is a no-op.

Methods
void recordSpan(ulong traceId, ulong spanId, ulong parentSpanId, scope const(char)[] name, long startUs, long durationUs) @safe nothrow;Record a completed span.