Monitoring
The health endpoints, Prometheus metrics, Grafana dashboards and alerts, the GKE uptime and alert policies, and the log exporters.
On this page
The engine reports its own state three ways: health endpoints for probes and dashboards, Prometheus metrics, and logs. On GKE, Terraform adds Cloud Monitoring alert policies that page a person. This page explains each one and which to use for what. In the engine UI, the Dashboard shows the same checks on its Engine services card, beside what needs a person now.
Here is who reads what.
flowchart LR
Kubelet[Kubelet] -->|/api/live, /api/ready| Engine[Engine pods]
Uptime[Cloud Monitoring uptime check] -->|/api/ready| Engine
Deploy[Deploy build] -->|/api/health| Engine
Prom[Prometheus] -->|/api/metrics, bearer token| Engine
Engine -->|logs| CM[Cloud Logging]
Engine -->|batched events| Ext[Datadog, CloudWatch or Splunk]Health endpoints
Three public routes answer without a sign-in and are exempt from the IP allowlist, so probes from the cluster always reach them.
| Route | Answers | Used by |
|---|---|---|
/api/live | Is the process able to answer? | Kubernetes liveness and startup probes |
/api/ready | Can this pod take traffic? | Kubernetes readiness, the Cloud Monitoring uptime check |
/api/health | What is the state of every dependency? | Dashboards, the post-deploy check, smoke-test.sh |
/api/live
Returns {"alive": true} and touches no dependency. A PostgreSQL, Redis, Medplum or medhook.dev outage never makes the kubelet restart healthy pods.
/api/ready
Checks PostgreSQL (SELECT 1), Redis (PING) and the signed license, which it verifies locally on every probe. It makes no network call to medhook.dev. The whole probe has a 5-second budget.
| Check | ok when | Otherwise |
|---|---|---|
postgres | the query succeeds | timeout or unreachable: <message> |
redis | the ping succeeds | timeout or unreachable: <message> |
license | the signed license verifies and has not been revoked or passed its wind-down | invalid |
It returns 200 with {"ready": true, "checks": {...}} when all three are ok, and 503 with "ready": false otherwise. A pod that is not ready leaves the load balancer but is not restarted.
/api/health
A deep status report. Each check runs in parallel with its own 2-second limit, so the answer arrives in about that time even if a dependency hangs.
| Check | Looks at |
|---|---|
postgres | a SELECT 1 |
redis | a PING |
medplum | the bundled FHIR server's health check |
mllp | the MLLP listener's health route |
license | the cached license: valid, grace, invalid or pending |
memory | process memory against the container limit |
sandbox | which runtime custom JavaScript and expressions get: isolated-vm, or unavailable |
executionArchive | off, ok, or misconfigured with the reason when EXECUTION_ARCHIVE_DIR is set but cannot be used |
Without a sign-in, /api/health answers the overall status and each check's status word only, for example {"status":"healthy","checks":{"postgres":{"status":"up"},"sandbox":{"status":"isolated-vm"},…}}. Signed in (a session or a bearer token), it adds the latencies, kinds and counts, memory, the license's expiry and PHI flag, the AI provider and budget, the platform and uptime. /api/version works the same way: anyone gets name, version, commit and buildDate; signed in adds node, fhirVersions, adapters and features.
The overall status is one of three values.
| Status | When | HTTP |
|---|---|---|
healthy | everything is up and the license is valid | 200 |
degraded | Medplum or MLLP is down, the license is not valid (including grace), memory is high, the sandbox is not isolated-vm, or the execution archive is misconfigured | 200 |
unhealthy | PostgreSQL or Redis is down | 503 |
The body also carries the build version, uptime and executionQueue (running, pending and capacity). The route allows 60 requests per minute per IP address. smoke-test.sh fails unless checks.sandbox is isolated-vm: without it, custom JavaScript and expressions do not run.
Prometheus metrics
The engine serves Prometheus text at /api/metrics. Prometheus presents METRICS_TOKEN (at least 32 characters) as a bearer token, and the token works on this route only. The route allows 10 requests per minute per IP address. On GKE, Prometheus scrapes every engine pod every 15 seconds.
| Metric | Type | What it counts |
|---|---|---|
medhook_workflow_executions_total | counter | executions, by status and workflow_id |
medhook_workflow_execution_duration_seconds | histogram | execution time, by workflow_id |
medhook_workflow_duration_seconds, medhook_node_duration_seconds | histogram | time per workflow (workflow_id, status) and per step (workflow_id, node_type, status) |
medhook_adapter_operations_total | counter | adapter calls, by adapter_type, operation and status |
medhook_adapter_operation_duration_seconds | histogram | adapter call time, by adapter_type and operation |
medhook_http_requests_total | counter | HTTP requests, by method, path and status |
medhook_http_request_duration_seconds | histogram | HTTP request time, by method and path (the route template, not the raw URL) |
medhook_active_executions | gauge | executions running now |
medhook_execution_queue_size, medhook_execution_queue_pending | gauge | the execution queue |
medhook_redis_connected | gauge | 1 when Redis answers |
medhook_license_valid, medhook_license_grace_active | gauge | license honoured, and in its wind-down after the term end |
medhook_license_last_success_timestamp_seconds | gauge | last successful license check |
medhook_license_phi_enabled | gauge | 1 when the license is valid and allows PHI |
medhook_phi_blocked_executions_total | counter | executions blocked by PHI enforcement, by workflow_id and trigger_type |
medhook_ip_allowlist_unavailable_total | counter | allowlist lookups that failed, by fail_open or fail_closed |
medhook_log_export_failures_total | counter | log export flushes that failed, by provider |
medhook_log_export_dropped_events_total | counter | log export events dropped, by provider and reason (overflow, rejected, retries_exhausted) |
medhook_log_export_queue_depth | gauge | log export events waiting, by provider |
medhook_lanes_held | gauge | ordering lanes held after a failed message (onError: hold) |
medhook_destination_queue_depth | gauge | messages waiting in a destination queue, by workflow_id and destination_id |
medhook_destination_queue_oldest_seconds | gauge | age of the oldest message in a destination queue, by workflow_id and destination_id |
medhook_history_write_failures_total | counter | execution history writes that failed, by kind |
medhook_adapter_concurrent_calls | gauge | calls holding a concurrency slot, by adapter type |
medhook_alert_notify_failures_total | counter | engine alert notifications that failed, by channel and action |
medhook_alert_eval_truncated_total | counter | engine alert evaluations that hit their row cap, by kind |
medhook_inbound_dedup_hits_total | counter | inbound resends answered from an earlier delivery without running again, by trigger_type |
medhook_inbound_dedup_key_reused_total | counter | inbound messages that reused an earlier message's key (MSH-10) with different content, run as new messages, by trigger_type. A sender that keeps doing this reuses control IDs. |
process_resident_memory_bytes | gauge | the engine process's resident memory |
medhook_mllp_messages_total | counter | HL7v2 messages answered by the MLLP listener, by listener and ACK code (AA, AE, AR, or CA, CE, CR in msh15 mode) |
medhook_mllp_acks_suppressed_total | counter | messages whose MSH-15 asked for no ACK, by listener |
medhook_mllp_active_connections | gauge | open MLLP connections, by listener; Messages › Connections shows who they are |
The three medhook_mllp_* metrics come from the MLLP listener's own /metrics route, not from the engine's /api/metrics.
Grafana dashboards and alert rules
Grafana loads a medhook-engine dashboard and its alert rules from apps/engine/grafana/provisioning. Change the default admin password before you expose it.
Prometheus evaluates these rules. The Helm chart ships the same set.
| Alert | Severity | Fires when |
|---|---|---|
RedisConnectionDown | critical | medhook_redis_connected is 0 for 30 seconds |
HighWorkflowFailureRate | warning | more than 5% of executions fail over 5 minutes |
WorkflowExecutionTimeout | warning | p99 execution time is above 300 seconds for 2 minutes |
HighAdapterFailureRate | warning | more than 10% of adapter operations fail over 5 minutes |
HighMemoryUsage | warning | resident memory is above 512 MB for 5 minutes |
SlowWorkflowExecutions | warning | p95 execution time is above 60 seconds for 10 minutes |
TooManyActiveExecutions | warning | more than 50 active executions for 5 minutes |
HighHTTPErrorRate | warning | more than 10% of requests return 5xx over 5 minutes |
MllpNakRatioHigh | critical | more than 5% of HL7v2 messages get AE, AR, CE or CR over 10 minutes |
The Docker Compose stack also provisions Grafana's own alert rules, for example engine unreachable, API 5xx rate, sustained adapter failures, rate-limited inbound triggers, an ordering lane held for more than 10 minutes (medhook_lanes_held) and failed execution-history writes (medhook_history_write_failures_total). A held lane means a trigger with onError: hold stopped after a failed message: the messages behind it wait. Release it by replaying the failed message from Needs action on Messages until it succeeds, or by skipping it there. A failed history write means the database refused a write: a manual run answers 503 HISTORY_UNAVAILABLE, and a running one stops before its next step. To send them to Slack, set GF_ALERTING_WEBHOOK_URL in .env and restart Grafana.
GKE uptime check and alert policies
Terraform (terraform/gke/modules/medhook/monitoring.tf) creates an uptime check and alert policies in your project. Set these in terraform.tfvars before the first apply. A production plan fails without a notification channel.
| Variable | What it is |
|---|---|
alert_emails | addresses to page. Terraform makes an email channel for each. |
alert_notification_channels | existing channels, by name, for example PagerDuty or Slack |
alert_uptime_host | the engine host name. It defaults to the host of engine_public_url. |
The uptime check requests https://<alert_uptime_host>/api/ready every 60 seconds over TLS with certificate validation, and expects a 2xx answer.
| Alert policy | Fires when |
|---|---|
| MedHook engine is down | the uptime check fails for 3 minutes: unreachable, or /api/ready answers 503 |
| MedHook pods are restarting | more than alert_pod_restart_threshold (default 2) container restarts in the medhook namespace within 10 minutes |
| MedHook engine error rate is high | more than alert_error_log_threshold (default 5) error log lines per minute over 5 minutes |
| MedHook contract term ended (license wind-down or expired) | the contract term has ended and the license is in its wind-down, or the wind-down has ended. A medhook.dev outage never triggers it. |
| MedHook Cloud SQL is down | Cloud SQL reports the instance down for 2 minutes |
| MedHook VPN tunnel is down | a Classic tunnel, or one interface of an HA tunnel, is not established for vpn_tunnel_down_minutes (default 5). One incident per tunnel. It pages even when the engine's tunnel watcher is stopped. |
| MedHook HA VPN BGP session is down | with peers in ha_vpn_peers, one of their BGP sessions is down for vpn_tunnel_down_minutes. One incident per session. |
| MedHook tunnel watcher is stale | with a failover pair or HA VPN, the engine's tunnel watcher logs no heartbeat for tunnel_watcher_stale_minutes (default 15): failover and HA re-establish are not running. |
Each environment's tunnel alerts cover only its own tunnels, even when staging and production share a project: HA tunnels are matched by the environment's name prefix, and HA tunnels created before that naming are listed in vpn_ha_tunnel_alert_include.
Engine alert rules
The engine also runs its own alert rules, under Settings → Alert rules or /api/alert-rules. Every 30 seconds it checks each enabled rule: error rate, no messages (for the workflow, or per sender), queue size, latency, a tunnel down, a secret about to expire, an HL7 field value, failures that match an error condition, or a polling workflow whose polls keep failing. Each rule has a priority, P1, P2 or P3, and notifies by PagerDuty, Slack, Microsoft Teams, a text message (through the Text channel connected in Settings → Notifications), a webhook or email (through the engine's mail transport, ENGINE_EMAIL_FROM with RESEND_API_KEY or ENGINE_EMAIL_WEBHOOK_URL). A rule's active hours are in its own time zone, which starts at the workspace time zone.
- Resolve. When the condition clears, the channel gets a resolve: PagerDuty
resolvewith the samededup_key, SlackRESOLVED, a webhookstatus: "resolved". - Delivery. A rule shows as firing only once its notification was delivered. A failed send shows Not delivered, retrying and is retried after 30 seconds, doubling up to 15 minutes. Watch
medhook_alert_notify_failures_total. - One sender. With several replicas, each notification is claimed in Postgres first, so exactly one replica sends it.
Per sender. One workflow often takes messages from many healthcare organizations, and a No messages rule on the whole workflow stays quiet while one of them has stopped sending. Set Watch on a No messages rule to watch senders one by one. The sender is the sending facility, MSH-4, as Messages search shows it.
| Watch | Watches |
|---|---|
| All messages | the workflow (or every workflow) as a whole, as before |
| Per sender | every sender that sent in the last Senders seen in days (1, 3, 7, 14 or 30; 7 by default) |
| One sender | the sender you name. The picker lists the senders seen in the last 7 days; you can also type one. |
Quiet for is how long a sender may send nothing. Each sender quiet for longer is its own incident, opened once and resolved when that sender sends again: its own trigger and resolve, a PagerDuty dedup_key per sender, and an alert that names the sender and how long it has been quiet, for example DEMO_HEALTH_NORTH quiet for 2 h 14 min (last message today 12:46 CT). The rules table lists each quiet sender under its rule. A sender that has not sent within the lookback is not watched, so a sender that has never sent never alerts; one that has been quiet that long is resolved with a note that it is no longer watched. With active hours, only quiet time inside them counts: with 08:00 to 18:00 and a 1 h limit, a clinic whose last message was at 17:30 alerts at 08:30 the next morning if nothing has come in, not at 08:00. On-call quiet hours hold a P2 or P3 sender's alert as they do any rule's, and the incident still shows in the table. Per-sender rules are checked live; the 30-day dry run does not replay them.
The engine keeps each sender's last message time for the rule, and each pass reads only the executions that arrived since the last pass, through the start-time index, so the check stays light however many senders a workflow has. Changing the rule's condition, workflow, name, channel or target resolves its open sender incidents and starts it fresh.
Error match. A rule of kind Error match counts failed messages (status failed or partial) whose failure matches every condition you set, and fires when the count in the window is above the threshold (blank means any one failure). The conditions apply to the same failing step:
| Condition | Matches |
|---|---|
| Error type | the class of the step's error: Connection, Timeout, Authentication, Rate limited, Not found, HTTP 4xx, HTTP 5xx, Validation or Other. None ticked means any type. |
| Failing step | the step's id or name, case-insensitive |
| Adapter | the adapter type of the failing step, for example fhir-rest, mllp or sftp |
| Error text contains | any of up to 10 strings (200 characters each), case-insensitive, matched as plain text against the error text, for example service unavailable or ECONNRESET |
The type is read from the error text: an adapter SDK code (TIMEOUT, RATE_LIMITED, AUTHENTICATION_FAILED, …), a network error (ECONNREFUSED, ENOTFOUND), or an HTTP status. When no step failed, the run's own error is used and the step and adapter conditions do not match. The strings are matched against error text only, never message content, and the notification carries the count, for example EHR outage — 3 matching failures, never the error text. Regular expressions are not supported: error text can come from an upstream system, and a backtracking pattern over it could stall the engine. A rule that carries one (errorPattern) is refused on save. The 30-day dry run replays an error match rule like any other.
Polling is failing. A rule of kind Polling is failing watches one polling workflow, or every polling workflow in the workspace when Workflow is All polling workflows. It fires on the same test as the workflow's Needs you row: the last poll failed (a poll that waits on purpose, for the max in flight or a full backlog, does not count) and no poll has read the source for three intervals, at least 15 minutes. Only enabled workflows whose deployed trigger is polling count. It has no threshold or window. The alert names each workflow and the kind of failure, never the error text, for example Polling is failing — polling is failing: Demo Health REST sweep (reading the source fails). The kinds are: reading the source fails, the source's pages are not in cursor order, a full page shares one cursor value, and an item doesn't run. The email links to the workflow's Overview, which has the reason, when ENGINE_PUBLIC_URL is set. The rule resolves when a poll reads the source again. A rule watching every polling workflow opens one incident while any of them fails, not one per workflow. It is checked live; the 30-day dry run does not replay it.
Tunnel events. A rule of kind Tunnel events is not checked every 30 seconds: the tunnel watcher sends it as things happen to a tunnel in the rule's workspace: down, degraded (one HA interface), failed over, re-established, recovered, traffic back on the primary, and watcher paused. Each event is sent once per rule, even with several replicas, and a failed send is retried with the same backoff. Recovered and traffic-back events are resolves. The message names the rule, the tunnel and the event, for example Tunnel events · clinic-lab — Failed over to the backup tunnel (primary down 45s). See Self-healing watcher.
Send test. Open a saved rule and choose Send test to send one [TEST] message through its channel and target. The result shows next to the button: delivered, or the error the channel returned. Admins only; each test is audited.
The watcher's own metrics: medhook_tunnel_watcher_actions_total (by action: promote, failback, reprovision, suppressed), medhook_tunnel_watcher_errors_total (by stage, for example a failed Google Cloud read) and medhook_tunnel_watcher_last_tick_seconds, the time of its last successful read. Alert when the last tick is more than a few minutes old.
After you apply the Terraform policies, send a test: Monitoring, Alerting, Notification channels, your channel, Send test notification. Alerts never contain message content. Never paste PHI into the ticket or chat an alert opens.
Log exporters
The engine can ship execution logs and audit events to Datadog, AWS CloudWatch or Splunk. An admin sets it up under Settings → Notifications, in the Log export block: pick the provider, enter its fields, Save, then Send test event. The API is GET, POST and DELETE /api/settings/log-export, admin only.

| Provider | You enter |
|---|---|
| Datadog | API key, site (default datadoghq.com), service (default medhook-engine) |
| AWS CloudWatch | access key ID, secret access key, region (default us-east-1), log group (default /medhook/engine), log stream (default execution-logs) |
| Splunk HEC | HEC URL, HEC token, index, source |
How it behaves:
- Events share one queue. The engine flushes every 5 seconds, or sooner when the queue reaches 100 events.
- A batch that fails on a network error, a timeout, 408, 429 or a 5xx is retried after 2, 4, 8 and 16 seconds, up to 5 attempts. Any other 4xx drops it at once. Each request times out after 10 seconds, one flush runs at a time, and a shutdown spends up to 5 seconds draining the queue.
- The queue holds at most 10,000 events and drops the oldest past that. Watch
medhook_log_export_dropped_events_total(by reason) andmedhook_log_export_queue_depth. - Every event is scrubbed first: bearer tokens, URL credentials,
key=valuesecrets and upstream response bodies are removed. - With log export on, every audit event is also sent, as type
auditwith itschainSeq, once it is committed. Events written by the CLI tools stay in the database chain only. - Exporting never blocks a workflow. It enqueues and returns.
- The API never returns a stored credential. A
GETshows only whether one is configured, and the panel's credential fields stay empty: leave one blank to keep the saved value. - A request with a field the engine does not know is refused with
400. - Send test event sends one event using the form as filled in, saves nothing, and says whether the provider accepted it. A rejected test answers 502 with the provider's status.
- A save or a clear applies on every engine replica within 30 seconds.
- The Splunk HEC URL must be
httpswith no user name or password in it. A HEC host on a loopback, link-local, metadata or private address is refused unlessSSRF_ALLOWLISTnames it.
Where the settings are kept
The engine stores the panel's settings in Postgres, in one row. The credentials in it (the Datadog API key, the AWS keys, the Splunk HEC token) are encrypted with the master key, like the other values in Keys and secrets. So they survive a restart and are re-encrypted when you run rotate-master-key. An engine that kept them in Redis before this release moves them to Postgres the first time it loads them, then deletes the Redis copy.
Each save is audited as settings.log_export_updated, and each clear as settings.log_export_cleared. The audit event lists field names only, never a value.
Saved settings or environment variables
You can also set the exporter with environment variables, filled from your secrets manager: LOG_EXPORT_PROVIDER and the provider's variables, such as DATADOG_API_KEY, AWS_ACCESS_KEY_ID with AWS_SECRET_ACCESS_KEY, or SPLUNK_HEC_URL with SPLUNK_HEC_TOKEN. See Environment variables.
Saved settings win. Once anyone saves in the panel, even with the provider set to None, the engine uses the saved settings and ignores the environment variables, at once and after every restart. While nothing is saved, the panel shows the provider the environment variables chose.
To go back to the environment variables, choose Clear saved settings in the panel and confirm, or call DELETE /api/settings/log-export. That deletes the saved row, credentials included, and the engine applies the environment config at once. The button shows only while settings are saved.
Capacity and backlog
Inbound deliveries are recorded first and run after the answer, so a slow destination shows up as a backlog, not as failed senders.
- What runs. Each replica runs at most
MAX_CONCURRENT_WORKFLOWSexecutions at once (one queue per process). Pending work waits in Postgres, and any replica picks it up. Replays, retries and cron ticks take the same queue. - When senders are told to resend. A workflow with
WORKFLOW_MAX_PENDING(5000) pending executions refuses more: HTTP triggers answer 503NOT_ACCEPTEDwithRetry-After, and MLLP answersAE. So does a replica that is shutting down. A rising 503 orAErate with a healthy database means a backlog: find the slow destination. - Destinations.
MAX_CONCURRENT_ADAPTER_CALLSapplies per adapter profile, per process. A profile's Max concurrent calls, all engines and Max calls per second, all engines cap it across replicas, and a step that cannot get a slot withinADAPTER_SLOT_WAIT_MSfails without sending and retries.medhook_adapter_concurrent_callsat the cap means the destination is the bottleneck. - Ordering. An ordered lane, such as one MLLP sending facility, runs one message at a time. A channel whose destinations run one after another holds its lane for all of them together.
- History. A step output over
EXECUTION_NODE_RESULT_MAX_BYTES(10 MiB) is stored as a truncated marker. Large repeated outputs are stored once. - Webhook answers. A webhook trigger in
response.mode: destinationholds the request open up to itstimeoutMs(60 seconds at most). Each replica holds at mostWEBHOOK_SYNC_MAX_WAITERS(50) such waits. Give the load balancer an idle timeout longer than the longesttimeoutMs. - FHIR subscriptions. A failed subscription sync is audited as
trigger.fhir-subscription.sync-failed, and a callback that arrives before Medplum has the saved criteria astrigger.fhir-subscription.out-of-scope.
Checklist
- The uptime check and the alert policies above exist, and a test notification arrived.
- Probes use
/api/liveand/api/ready, never/api/health. - Prometheus has
METRICS_TOKEN, and the Grafana admin password is changed. -
medhook_license_grace_activeand the license alert are on someone's radar. - A log exporter is set up if your security team needs logs outside the cluster.
-
/api/healthshowschecks.sandboxasisolated-vm. - Someone watches
medhook_lanes_heldand Needs action on Messages, and engine alert rules notify a channel you tested.