Skip to main content

Monitoring

Whoosh-NG ships with hooks for observability and a Prometheus plugin for production use.

Built-in Metrics​

from whoosh.middleware import MetricsMiddleware, MiddlewareChain
from whoosh.middleware.integration import apply_middleware_to_writer, apply_middleware_to_searcher

chain = MiddlewareChain([MetricsMiddleware()])
writer = apply_middleware_to_writer(ix.writer(), chain.middlewares)
searcher = apply_middleware_to_searcher(ix.searcher(), chain.middlewares)

metrics = chain.get_metrics()
print(metrics)

Prometheus​

pip install whoosh-ng[metrics]
MetricTypeDescription
whoosh_documents_indexed_totalCounterTotal documents indexed
whoosh_searches_executed_totalCounterTotal searches executed
whoosh_indexing_duration_secondsHistogramIndexing latency
whoosh_search_duration_secondsHistogramSearch latency
whoosh_index_size_bytesGaugeCurrent index size

Best practices​

  1. Add MetricsMiddleware early in your base chain.
  2. Expose /metrics in production.
  3. Use /health for load balancer health checks.
  4. Emit DocumentIndexed and SearchExecuted events.