Skip to content

Metrics & dashboards

OctoFHIR exports Prometheus metrics on /metrics. The console’s Performance page reads them back from Prometheus, not from the server it is talking to: behind a load balancer each request may reach another instance, so only Prometheus, which scrapes every instance, has the whole picture. The page appears once [metrics.prometheus] is configured.

docker compose up -d starts Prometheus on localhost:9095, scraping the server you run with cargo run (host.docker.internal:8888) every 5 seconds. The example config (octofhir.example.toml) already points the console at it:

[metrics.prometheus]
url = "http://localhost:9095"
selector = '{job="octofhir"}'
scrape_interval_secs = 5

Open Performance (g m) in the console. The header shows 1/1 up: Prometheus scrapes the one instance. To try exporting dashboards to Grafana as well, run docker compose --profile grafana up -d (see Grafana).

Two things are needed: Prometheus scrapes /metrics of every instance, and the server knows where that Prometheus is and which of its series are this deployment’s.

Scrape the instances directly, not through the load balancer — through it, each scrape would reach a random instance. Put them all under one job.

Static targets (VMs, docker compose):

prometheus.yml
global:
scrape_interval: 15s
scrape_configs:
- job_name: octofhir
metrics_path: /metrics
static_configs:
- targets: ["fhir-1.internal:8888", "fhir-2.internal:8888"]
labels:
env: prod

Kubernetes with the Prometheus Operator — a ServiceMonitor on the server’s Service. The operator names the job after the Service, so the selector below matches on it:

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: octofhir
namespace: fhir
spec:
selector:
matchLabels:
app: octofhir
endpoints:
- port: http # the Service port name for 8888
path: /metrics
interval: 15s

Kubernetes without the operator — discover the pods and keep the pod name as instance, so dashboards show octofhir-7d9f… rather than an IP:

scrape_configs:
- job_name: octofhir
kubernetes_sd_configs:
- role: pod
namespaces: { names: [fhir] }
relabel_configs:
- source_labels: [__meta_kubernetes_pod_label_app]
regex: octofhir
action: keep
- source_labels: [__meta_kubernetes_pod_container_port_number]
regex: "8888"
action: keep
- source_labels: [__meta_kubernetes_pod_name]
target_label: instance

Protecting /metrics. By default /metrics is public (it shows route names and load, no data). To require a token, set it on the server and give the scrape job the same token:

[metrics]
endpoint_token = "a-long-random-string" # or OCTOFHIR__METRICS__ENDPOINT_TOKEN
- job_name: octofhir
authorization:
credentials: a-long-random-string # or credentials_file: /etc/prometheus/octofhir-token

Check it works: in Prometheus run up{job="octofhir"} — one series per instance, value 1.

[metrics.prometheus]
url = "http://prometheus:9090"
selector = '{job="octofhir"}'
scrape_interval_secs = 15
  • url — the Prometheus HTTP API, reachable from every instance (the console queries through whichever instance answers it). A sub-path is fine: https://mimir.example.com/prometheus.
  • selector — label matchers that pick out this deployment’s series. It is added to every dashboard query, so it must match the labels your scrape setup attaches: {job="octofhir"} for the static config above, {job="octofhir", namespace="fhir"} with the operator, or {job="octofhir", env="prod"} when staging and production share one Prometheus.
  • scrape_interval_secs — the job’s scrape interval. Charts never use a finer step, and $__rate_interval covers at least four scrapes so rate() always has enough samples. If it is lower than the real interval, rates come back empty.

Restart the server. Performance appears in the sidebar; until then the page shows what to add.

[metrics.prometheus]
url = "https://mimir.example.com/prometheus"
selector = '{job="octofhir", env="prod"}'
scrape_interval_secs = 30
bearer_token = "…" # or basic_username + basic_password
headers = { "X-Scope-OrgID" = "fhir-prod" } # tenant header for Mimir / Cortex
timeout_secs = 10 # per query
max_range_days = 30 # longest range a dashboard may ask for
max_points = 2000 # per series; longer ranges get coarser steps

Every Prometheus-compatible query API works: Prometheus, VictoriaMetrics (url = "http://victoriametrics:8428"), Mimir, Cortex, Thanos Query. The server only reads from it; give it a read-only credential. Settings can also come from the environment, e.g. OCTOFHIR__METRICS__PROMETHEUS__URL and OCTOFHIR__METRICS__PROMETHEUS__BEARER_TOKEN.

Dashboards can look back max_range_days (30 by default), but only as far as Prometheus keeps data (--storage.tsdb.retention.time, 15 days by default). One instance exports from a few hundred to a few thousand series — latency histograms per route and per FHIR interaction dominate — which at a 15 s interval is in the order of tens of MB per day.

The page reports problems above the dashboard:

Message Cause
Prometheus is unreachable url is wrong or blocked from the server, or the credentials are rejected. The message has the details.
Prometheus does not scrape this server Prometheus answers, but up has no series matching selector. Check the scrape job and that the selector uses the labels it attaches.
A panel’s warning icon That query failed; hover the icon for Prometheus’ error.
Charts with gaps Instances restarted or scrapes failed for a while — gaps are real missing data.
Rates empty on short ranges scrape_interval_secs is lower than the job’s real interval.

All names start with octofhir_.

Metric Type Labels
http_requests_total counter method, path, status_class Requests by route (ids normalized to {id})
http_request_duration_seconds histogram method, path Request latency, 1 ms – 10 s buckets
http_active_connections gauge Requests being served
fhir_interactions_total counter interaction, resource_type, status_class FHIR REST interactions: read, vread, search-type, create, update, patch, delete, history-*, operation, batch, …
fhir_interaction_duration_seconds histogram interaction, resource_type Their latency
storage_operation_duration_seconds histogram operation, resource_type, outcome Every database call: reads, writes, searches; tx_* calls run inside a transaction
db_pool_connections_active / _idle / _max gauge PostgreSQL pool of this instance
pg_connections gauge state Client connections to the database: active, idle, idle in transaction…
pg_connections_waiting_on_locks, pg_longest_transaction_seconds gauge Lock waits; age of the oldest open transaction
pg_transactions_total, pg_deadlocks_total counter outcome Commits and rollbacks; deadlocks
pg_blocks_total counter source Blocks read from the buffer cache or disk (cache hit ratio)
pg_rows_total, pg_temp_bytes_total counter operation Rows fetched/inserted/updated/deleted; temp-file bytes
pg_database_size_bytes, pg_table_size_bytes, pg_table_rows, pg_table_dead_rows gauge table Database and table sizes, rows, rows awaiting vacuum (non-empty tables only)
fhir_resources gauge resource_type Stored resources per type (estimate from table statistics)
cache_hits_total, cache_misses_total counter tier Resource cache (L1 local, L2 Redis)
tokio_workers, tokio_alive_tasks, tokio_global_queue_depth gauge Async runtime
tokio_worker_busy_seconds_total, tokio_worker_parks_total gauge worker Per worker; rate() of busy time is utilization
process_cpu_seconds_total, process_resident_memory_bytes, process_threads, process_open_fds, … gauge The process
build_info gauge version Always 1

Every metric carries # HELP, which the console shows in completions and hovers.

The pg_* metrics are read from PostgreSQL’s statistics views when Prometheus scrapes — at most every 10 seconds, abandoned after 2 seconds. They describe the shared database, so every instance reports the same values: aggregate them with max, not sum.

The built-in System dashboard is grouped in collapsible sections: overview stats, HTTP throughput and latency, FHIR interactions by resource type, routes, the database (size, busy connections, cache hit ratio, storage latency by operation, lock waits, the longest transaction, transactions, tables, the slowest storage calls), the Tokio runtime and the process. It is read-only; Duplicate & edit makes your own copy.

  • Variables. instance narrows every panel to some instances; the selection is kept in the URL (?var-instance=…) so a link reproduces the view.
  • Time. Pick 15 minutes to 7 days, or drag across any chart to zoom into that span; the zoom stays in the URL and history, Zoom out doubles it, × returns to live.
  • Refresh. Follows the scrape interval by default; 15 s to 5 min or off.
  • Panels. Hover a chart for values across all charts at once; click a legend entry to show only that series, ⌘-click to toggle it. View opens a panel full-size, Query shows its PromQL.

In edit mode panels move by their header and resize from their corner on a 24-column grid, like Grafana’s. Add panel opens the panel editor:

  • each query is written in the Builder or as Code. The builder picks a metric (with its help text), label filters with suggested values, a function (rate, increase, a histogram quantile, *_over_time), an aggregation with by labels and an optional top-k, and shows the PromQL it writes. Anything beyond that — ratios, label_replace, offsets — goes in the code editor, which completes metric names, label names and values, functions and durations, and underlines syntax errors as the server’s parser reports them. PromQL is what is saved; a query written as code opens in the builder only if the builder can read it back;
  • the preview follows your edits; ⌘Enter or Run refreshes it at once;
  • Explain (the tree icon) shows the query as a tree and runs every step on its own — rate(…), then sum by (…), then the division — with the number of series each returns and a few samples. When a panel is empty, it shows which step lost the series: a filter that matches nothing, a by that drops the label a division joins on. The same view is under Query in any panel’s menu;
  • $__rate_interval (at least four scrapes), $__interval (the step), $__range (the time range) and dashboard variables such as $instance are substituted before the query runs, the same names Grafana uses;
  • panel types are time series (lines or stacked bars), stat (value with trend and warning/error thresholds) and table (one row per label set, one column per query).

Add section inserts a collapsible row.

Saved dashboards are Dashboard resources, so they have history and access policies, and can be provisioned by script:

Terminal window
curl -X PUT "$BASE/fhir/Dashboard/team-overview" \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/fhir+json" \
-H "X-Skip-Validation: true" -d @team-overview.dashboard.json

Download dashboard JSON in the export menu gives you that file.

The server parses every query and adds the configured selector to each series selector in it, so a dashboard only ever reads this deployment’s series even when Prometheus is shared. A query that names another job gets both matchers and comes back empty. Ranges are capped at max_range_days, steps never go below the scrape interval and are coarsened to stay under max_points per series, and queries time out after timeout_secs.

Grafana is optional. Every dashboard, built-in or yours, exports to it from the export menu:

  • Download JSON — a Grafana dashboard with its queries already scoped to the selector. In Grafana use Dashboards → New → Import; it asks which Prometheus datasource to use.
  • Push — enter your Grafana URL and a service-account token (Editor role), pick the datasource and folder, and the dashboard is created, or updated if pushed before. The token is sent with the request only: it is not stored on the server or written to its logs, and the console forgets it when the tab closes. Requests to Grafana go through the server’s outbound policy.

Import dashboard… (in the ⋯ menu, or ⌘K) goes the other way: drop in a Grafana dashboard JSON — an export or the API’s {"dashboard": …} — or a dashboard downloaded from this console. PromQL panels (time series, graph, stat, singlestat, table; gauges become stats), collapsed and expanded rows, units, decimals, min/max, thresholds, fixed series colours, per-query units, label_values(…) variables and the shared-crosshair setting carry over. Panels of other types or datasources (text, logs, Loki, SQL) and other variable types are listed as not imported before you create the dashboard.

The built-in dashboards are also in the repository under deploy/observability/grafana/. To try the push locally: docker compose --profile grafana up -d starts Grafana on localhost:3030 (admin / admin) with the compose Prometheus as its datasource.