Metrics Endpoint
Enable the Prometheus metrics HTTP endpoint:kora.toml:
/metrics endpoint exposes Prometheus text exposition format:
Exported Metrics
| Metric | Type | Description |
|---|---|---|
kora_commands_total | counter | Commands processed, labeled by cmd type |
kora_keys_total | gauge | Current key count across all shards |
kora_memory_used_bytes | gauge | Approximate memory consumption |
kora_bytes_in_total | counter | Total bytes received from clients |
kora_bytes_out_total | counter | Total bytes sent to clients |
kora_command_duration_seconds | histogram | Command latency distribution by type |
Example Output
Per-Command Statistics
Kora tracks detailed statistics for each command type:- Command counts — total executions per command
- Total duration — cumulative execution time in nanoseconds
- Average latency — computed from count and total duration
Relaxed ordering for minimal overhead on the data path.
Command Types Tracked
Kora tracks 32 command slots, including:kora-observability/src/prometheus.rs:24-28 for the full list.
Hot-Key Detection
Kora uses a Count-Min Sketch probabilistic data structure to identify frequently accessed keys with minimal memory overhead.How It Works
- Memory footprint: ~2KB per shard (64 columns × 4 rows × 8 bytes)
- Accuracy: Guaranteed never to undercount (may overestimate due to hash collisions)
- Decay: Periodic decay (divide by 2) implements sliding window over recent access patterns
Implementation Details
Querying Hot Keys
Kora currently exposes hot-key frequency estimation through the internal API (not via RESP2 yet):HOTKEYS command may be added to expose top-K keys via the Redis protocol.
Decay Strategy
Calldecay_hot_keys() periodically to prevent stale keys from dominating frequency rankings:
Latency Histograms
Kora uses HDR histograms (High Dynamic Range) for accurate per-command latency distributions.Features
- Percentile queries: p50, p90, p99, p99.9
- Concurrent recording: Lock-free writes from connection handlers
- Low memory overhead: Logarithmic buckets, not linear bins
Histogram Recording
Latency is recorded automatically using RAII-basedCommandTimer:
Accessing Histogram Data
Histograms are exported via Prometheus metrics:le="0.0001"→ p50 (50th percentile)le="0.001"→ p90 (90th percentile)le="0.01"→ p99 (99th percentile)le="0.1"→ p99.9 (99.9th percentile)
Shard Statistics
Each shard maintains independent statistics, which are merged on-demand for server-wide aggregates.Per-Shard Metrics
Ordering::Relaxed for maximum performance.
Snapshot and Merge
Create point-in-time snapshots across all shards and merge:Memory Tracking
Kora tracks approximate memory usage per shard:- Key storage (keys + value pointers)
- Value storage (strings, lists, hashes, sets)
- Metadata overhead (expiration timers, reference counts)
Byte Throughput
Network byte counters track data transfer:bytes_in— bytes received from clients (RESP2 commands)bytes_out— bytes sent to clients (RESP2 responses)
kora_bytes_in_total and kora_bytes_out_total.
Prometheus Integration
Configure Prometheus to scrape the Kora metrics endpoint:Grafana Dashboards
Create Grafana dashboards using the exported metrics:- Operations panel:
rate(kora_commands_total[1m])grouped bycmd - Latency heatmap:
kora_command_duration_seconds_buckethistogram - Memory gauge:
kora_memory_used_bytes / 1024 / 1024(MB) - Throughput graph:
rate(kora_bytes_in_total[1m])+rate(kora_bytes_out_total[1m])
Performance Impact
Kora’s observability subsystem is designed for always-on production use:- Atomic counters:
Relaxedordering, no memory barriers on common path - RAII timers: Zero-cost abstraction, compiler-optimized
- Count-Min Sketch: 2KB memory, simple hash + increment per key access
- HDR histograms: Logarithmic memory, lock-free recording