Skip to main content

Observability

Chengeta AI provides built-in metrics via CacheMetrics and two exporters for production monitoring: Prometheus and OpenTelemetry.

CacheMetrics

Every CacheManager instance has a metrics property exposing live counters:

manager = CacheManager(backend=InMemoryBackend(), key_builder=CacheKeyBuilder())

# Use the cache...
manager.get("key")
manager.set("key", b"value")

snap = manager.metrics.snapshot()
print(snap)
# {
# 'hits': 0, 'misses': 1, 'evictions': 0, 'sets': 1,
# 'hit_rate': 0.0, 'miss_rate': 1.0,
# 'provider_cache_hits': 0,
# 'estimated_tokens_saved': 0,
# 'estimated_cost_saved_usd': 0.0
# }

Fields

FieldDescription
hitsExact or semantic cache hits
missesCache misses requiring a downstream call
evictionsLRU evictions from InMemoryBackend
setsTotal cache writes
hit_ratehits / (hits + misses)
provider_cache_hitsServer-side prompt cache hits (Anthropic/OpenAI)
estimated_tokens_savedTokens saved via provider prompt caching
estimated_cost_saved_usdEstimated USD saved via provider caching

Prometheus Exporter

pip install 'chengeta-ai[observability]'
from chengeta_ai.core.exporters import PrometheusExporter

exporter = PrometheusExporter(manager.metrics, port=9090, namespace="myapp")
exporter.start() # non-blocking — scrapes at http://localhost:9090/metrics

Exposed metrics

MetricTypeDescription
myapp_cache_hits_totalCounterTotal cache hits
myapp_cache_misses_totalCounterTotal cache misses
myapp_cache_evictions_totalCounterTotal LRU evictions
myapp_cache_sets_totalCounterTotal cache writes
myapp_cache_hit_rateGaugeCurrent hit rate
myapp_provider_cache_hits_totalCounterProvider prompt cache hits
myapp_tokens_saved_totalCounterTokens saved via provider caching
myapp_cost_saved_usdGaugeEstimated USD saved

Prometheus config example

scrape_configs:
- job_name: chengeta
static_configs:
- targets: ["localhost:9090"]

OpenTelemetry Exporter

from chengeta_ai.core.exporters import OpenTelemetryExporter

exporter = OpenTelemetryExporter(
metrics=manager.metrics,
endpoint="http://otel-collector:4317",
export_interval_ms=10_000,
)
exporter.start()

Pushes chengeta.hit_rate, chengeta.hits, chengeta.misses, and chengeta.cost_saved_usd as observable gauges to any OTEL-compatible backend (Grafana, Datadog, Honeycomb, etc.).


CLI

Quick snapshot without code:

python -m chengeta_ai stats
{
"hits": 142,
"misses": 31,
"evictions": 0,
"sets": 31,
"hit_rate": 0.821,
"miss_rate": 0.179,
"provider_cache_hits": 12,
"estimated_tokens_saved": 8400,
"estimated_cost_saved_usd": 0.025
}