🚧 FastCMS is under active development — not ready for production use. APIs and features may change without notice.
FastCMS
Advanced

Metrics & Monitoring

Built-in request counters, latency histograms, and error rates. Export to Prometheus for integration with Grafana and alerting systems.

Metrics & Monitoring

FastCMS collects in-process metrics covering every HTTP request — counters, latency percentiles (p50/p95/p99), error rates, and uptime. No external agent required.

Metrics Collected

MetricTypeDescription
fastcms_http_requests_totalCounterTotal HTTP requests since startup
fastcms_http_errors_totalCounterTotal 5xx responses
fastcms_http_request_duration_msHistogramRequest latency with p50/p95/p99/mean
fastcms_uptime_secondsGaugeSeconds since server start

Counters are labelled with method, path, and status so you can slice by endpoint.

API Reference

All metrics endpoints require admin authentication.

JSON Snapshot

GET /api/v1/admin/metrics
Authorization: Bearer <admin_token>

Response:

{
  "counters": {
    "fastcms_http_requests_total{method=GET,path=/health,status=200}": 42,
    "fastcms_http_errors_total": 0
  },
  "histograms": {
    "fastcms_http_request_duration_ms": {
      "count": 42,
      "mean": 3.2,
      "p50": 2.1,
      "p95": 8.4,
      "p99": 15.7
    }
  },
  "gauges": {
    "fastcms_uptime_seconds": 3600.0
  }
}

Prometheus Export

GET /api/v1/admin/metrics/prometheus
Authorization: Bearer <admin_token>

Returns text in standard Prometheus exposition format:

# HELP fastcms_http_requests_total Total HTTP requests
# TYPE fastcms_http_requests_total counter
fastcms_http_requests_total{method="GET",path="/health",status="200"} 42
...

Admin UI

Visit /admin/metrics for a live dashboard that auto-refreshes every 15 seconds.

The dashboard shows:

  • Stat cards — total requests, total 5xx errors, median latency, uptime
  • Latency panel — mean, p50, p95, p99 in milliseconds
  • Counters table — all labeled counters with values
  • Gauges table — current gauge values
  • Prometheus link — opens the raw text export in a new tab

Prometheus + Grafana Setup

  1. Add FastCMS as a scrape target in prometheus.yml:
scrape_configs:
  - job_name: fastcms
    scrape_interval: 15s
    static_configs:
      - targets: ['localhost:8000']
    metrics_path: /api/v1/admin/metrics/prometheus
    bearer_token: <your_admin_access_token>
  1. Import a FastAPI dashboard in Grafana (Grafana ID 7763 is a good starting point), or create panels with PromQL:
# Request rate per second (5m average)
rate(fastcms_http_requests_total[5m])

# 95th percentile latency
fastcms_http_request_duration_ms{quantile="0.95"}

# Error rate
rate(fastcms_http_errors_total[5m])

Reading Metrics Programmatically

import httpx

resp = httpx.get(
    "http://localhost:8000/api/v1/admin/metrics",
    headers={"Authorization": "Bearer <admin_token>"}
)
snapshot = resp.json()

total_requests = snapshot["counters"].get("fastcms_http_requests_total", 0)
p99_latency = snapshot["histograms"]["fastcms_http_request_duration_ms"]["p99"]

print(f"Requests: {total_requests}, p99: {p99_latency}ms")

Implementation Notes

  • Metrics are stored in-process using Python dicts protected by threading.RLock. There is no external dependency (Redis, StatsD, etc.).
  • Counters reset when the server restarts.
  • The histogram implementation is a simplified sliding-window approximation — suitable for dashboards and alerting but not for exact SLA calculations.
  • For production-grade observability, consider forwarding to a time-series database (Prometheus + Thanos, VictoriaMetrics) using the Prometheus export endpoint.

On this page