eve.core.metrics
Pluggable metrics and tracing interfaces for EVE observability.
This module provides:
- MetricsSink — interface for collecting counters, gauges, and timings
- NullMetricsSink — zero-overhead no-op implementation
- LoggingMetricsSink — stderr logging implementation
- TracingSink — interface for distributed tracing spans
- MetricsTag — key-value tag for metric attribution
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);Copyright
Types 5
Key-value tag for metric attribution.
Tags allow filtering and grouping of metrics by dimension (e.g., ("kind", "timer"), ("backend", "io_uring")).
const(char)[] keyTag key (metric dimension name).const(char)[] valueTag value.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— Countereve.loop.iteration_us— Timingeve.poll.duration_us— Timingeve.poll.events— Gaugeeve.io.dispatched— Countereve.timers.fired— Countereve.timers.registered— Gaugeeve.watchers.total— Gaugeeve.callback.duration_us— Timing
See Also
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.
void counter(scope const(char)[], long = 1,
scope const(MetricsTag)[] = null) static @safe nothrow @nogcvoid gauge(scope const(char)[], double,
scope const(MetricsTag)[] = null) static @safe nothrow @nogcLogging 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=42FILE * _outputvoid counter(scope const(char)[] name, long delta = 1,
scope const(MetricsTag)[] tags = null) @trusted nothrowvoid gauge(scope const(char)[] name, double value,
scope const(MetricsTag)[] tags = null) @trusted nothrowvoid timing(scope const(char)[] name, long microseconds,
scope const(MetricsTag)[] tags = null) @trusted nothrowthis(FILE * output = null)Create a logging metrics sink.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.
void recordSpan(ulong traceId, ulong spanId, ulong parentSpanId,
scope const(char)[] name, long startUs,
long durationUs) @safe nothrow;Record a completed span.