Skip to content

feat: prometheus metrics endpoint - #37

Merged
kacy merged 1 commit into
mainfrom
feat/observability-metrics
Feb 6, 2026
Merged

feat: prometheus metrics endpoint#37
kacy merged 1 commit into
mainfrom
feat/observability-metrics

Conversation

@kacy

@kacy kacy commented Feb 6, 2026

Copy link
Copy Markdown
Owner

summary

  • adds --metrics-port <port> CLI flag to expose a prometheus HTTP endpoint on a separate port
  • instruments per-command counters, latency histograms (cache-tuned buckets from 10µs to 100ms), and error counters
  • background stats poller (5s interval) broadcasts ShardRequest::Stats and publishes key/memory/expiry/eviction gauges
  • adds Command::command_name() returning &'static str for zero-allocation metric labels
  • enriches KeyspaceStats with cumulative keys_expired and keys_evicted counters
  • zero overhead when --metrics-port is not set — no recorder installed, all timing gated behind a bool

tested

  • cargo test --workspace — all 216 tests pass
  • cargo clippy --workspace -- -D warnings — clean
  • manual: started server with --metrics-port 9100, confirmed curl localhost:9100/metrics returns prometheus output with all expected metric families

design considerations

  • metrics deps (metrics, metrics-exporter-prometheus) are only in ember-server. ember-core stays dependency-free — the stats poller pulls data through the existing shard broadcast mechanism
  • histogram buckets are cache-latency focused (10µs–100ms), matching the target P99 <200µs
  • connection counters use gauge for active count (inc/dec) and counters for total/rejected
  • the command_name() method avoids allocation by returning static strings, suitable for use as prometheus labels

adds --metrics-port flag to enable a prometheus HTTP endpoint on a
separate port. when enabled, the server records:

- ember_connections_active / total / rejected (gauge/counters)
- ember_commands_total{cmd} (counter per command)
- ember_commands_duration_seconds{cmd} (histogram, cache-latency buckets)
- ember_commands_errors_total{cmd} (counter)
- ember_keys_total, ember_memory_used_bytes (gauges, polled every 5s)
- ember_keys_expired_total, ember_keys_evicted_total (gauges from shard stats)

zero overhead when --metrics-port is not set — no recorder installed,
timing code is gated behind a bool.

also adds Command::command_name() for zero-allocation metric labels
and enriches KeyspaceStats with cumulative expiry/eviction counters.
@kacy
kacy merged commit 7de367c into main Feb 6, 2026
4 of 5 checks passed
kacy added a commit that referenced this pull request Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant