Monitoring
Health
Three endpoints on the main endpoint answer an orchestrator's questions. They need no authentication.
| Endpoint | Asks | Answers |
|---|---|---|
GET /livez | Is the node running? | 200 {"status":"ok"} always; it asks nothing of the database, the blob store or the disk |
GET /readyz | Can it do its work? | 200 or 503, with each check: database (SELECT 1), blob_store (reading a key that is not there answers "not found"), spool (a small file can be written and removed in the spool directory; not_configured without SMTP listeners) |
GET /health | Does the database answer? | 200 or 503, as before, with the running version; kept for orchestrators that use it |
GET /readyz
HTTP/1.1 503 Service Unavailable
{"status":"error","checks":{"database":"ok","blob_store":"error","spool":"ok"}}Use /livez for the check that restarts a container and /readyz for
the check that takes a node out of the load balancer. A node whose
database or blob store is down is not ready, and restarting it would not
mend either. Each check has two seconds; the probes read only (an absent
key, one small file in the spool), so a probe every few seconds is cheap.
GET /health answers whether the node can reach its
database (SELECT 1):
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{"database":"ok","status":"ok","version":"1.0.0"}and 503 with {"database":"error","status":"error"} when it cannot. It
is the older, narrower check. None of the three checks the resolver or
the SMTP listeners.
In production the endpoint redirects plain HTTP to HTTPS except for the
hosts localhost and 127.0.0.1; check http://localhost:4000/readyz
from inside the container, or through a trusted proxy
(KARTA_TRUSTED_PROXIES) that sends X-Forwarded-Proto: https.
Metrics
Prometheus metrics are served on a listener of their own, port 9568
(METRICS_PORT), at GET /metrics; every other path is 404. The port
must stay on the internal network: it has no authentication. It is never
routed through the public reverse proxy.
The metrics come from PromEx (Karta.PromEx) and its plugins, all named
karta_prom_ex_*:
| Plugin | Examples |
|---|---|
| Application | karta_prom_ex_application_uptime_milliseconds_count, karta_prom_ex_application_dependency_info |
| BEAM | karta_prom_ex_beam_memory_*, karta_prom_ex_beam_stats_run_queue_count, karta_prom_ex_beam_stats_process_count |
| Phoenix | request counts and durations of the main endpoint |
| Ecto | karta_prom_ex_ecto_repo_query_*_time_milliseconds (queue, execution, decode, idle) |
| Oban | karta_prom_ex_oban_job_processing_duration_milliseconds, karta_prom_ex_oban_job_queue_time_milliseconds, queue lengths (counted every 5 seconds) |
Karta's own:
| Metric | Meaning |
|---|---|
karta_ip_pool_address_held{pool, address} | 1 on the node that holds the IP pool address, 0 on the others. Alert on max by (pool, address) (karta_ip_pool_address_held) == 0: no node delivers that pool's mail. |
karta_warmup_sent{pool, address}, karta_warmup_limit{pool, address} | For each address in its warm-up: the recipients it was used for today (UTC) and today's limit, read from the database every 30 seconds (the same on every node). |
karta_delivery_held_back_recipients{reason, pool} | Recipients whose delivery waited for a limit, without an attempt: warmup, connections or rate (limits per destination); counted on each node, pool empty without one. A steady rise means a pool or a limit is too small for the mail. |
Several replicas
Scrape every replica, not a Service that picks one. Add counters across
replicas (sum(rate(...))); the gauges the replicas read from the database
(karta_outbound_queue_*, karta_inbound_deliveries,
karta_webhook_backlog_deliveries, karta_suppressions_entries) are equal
on all of them, so aggregate those with max, never sum. The dashboard and
the alerts in priv/ do. See Running several replicas.
The mail metrics
Karta.PromEx.Mail counts what happens to mail as it happens, and
reads what waits from the database every 30 seconds
(Karta.Metrics, Karta.Metrics.Report):
| Metric | Meaning |
|---|---|
karta_delivery_outcome_recipients{server, outcome, class, code} | Recipients of outgoing mail by what became of their last attempt (delivered, deferred, bounced), the enhanced status class and the reply code. |
karta_delivery_tls_deliveries{server, policy, result} | Deliveries by the TLS policy that decided them (dane, mta-sts, verified, opportunistic, ...) and the version used (none when it went in clear). |
karta_smtp_refusals{listener, code, class} | Replies of 4xx and 5xx the SMTP listeners sent, including a refused message at the end of DATA and the 452 for a client that names too many recipients. |
karta_smtp_connections{listener, result} | Connections accepted and refused. |
karta_smtp_auth_attempts{listener, mechanism, result} | AUTH attempts by mechanism and result (failed is a wrong credential, temporary a directory that could not answer). |
karta_auth_spf_checks{identity, result}, karta_auth_dkim_signatures{result}, karta_auth_dmarc_checks{result, policy} | What the checks of received mail found. |
karta_scan_runs{spam, virus}, karta_scan_duration_milliseconds{spam, virus} | The spam and virus scan's result and latency; timeout when the time budget ran out. |
karta_dns_lookups{type, cache, result}, karta_dns_duration_milliseconds{type, cache, result} | DNS answers from the cache (hit) and from the resolver (miss), and the lookups that failed. |
karta_webhook_attempts{server, result, state}, karta_webhook_duration_milliseconds{server, result, state} | Webhook requests by answer class; state="failed" is a dead letter. |
karta_bounce_reports{server, kind, class}, karta_complaint_reports{server, feedback_type} | Reports received at the return path, each counted once however often it arrives. |
karta_report_sent_reports{kind, result} | DMARC and TLS reports Karta sends about domains (Reports): sent, limited, failed, skipped, retry. |
karta_outbound_queue_recipients{server, queue, status} | Outgoing recipients waiting, per server and its queue. |
karta_outbound_queue_age_seconds{server, queue, status} | How long the oldest due recipient has waited: mail that should have been tried and was not. |
karta_inbound_deliveries{server, status} | Received messages waiting for their endpoint (pending) or held (held). |
karta_webhook_backlog_deliveries{server, state} | Webhook deliveries pending, and failed (dead letters). |
karta_suppressions_entries{server, reason} | Addresses a server suppresses that are still in force. |
A server is its id. The server label is the server's UUID, never
its name, its slug or a domain: a metric, a dashboard or a backup of them
then holds no customer's name. An operator maps an id to its server in
the admin pages; the id is the same one the API uses. The other labels are
a fixed vocabulary (an outcome, a status class, a reply code, a queue, a
policy, a scanner's verdict); a value from outside it — a reply code a
remote server invented, a class no RFC defines — is counted as other,
so a server cannot make an unbounded number of series.
The dashboard and the alert rules
priv/grafana/karta-mail.json is a Grafana dashboard of the mail
metrics: delivery outcomes and the deferral rate, the queues and their
age, the inbound and webhook backlogs, SMTP refusals and authentication
failures, the checks of received mail, scanning, DNS, bounces and
complaints, TLS and suppressions. Import it in Grafana (Dashboards →
New → Import) and pick the Prometheus data source; its server variable
lists the servers that have measurements.
priv/prometheus/karta-mail-alerts.yml holds six alert rules in plain
PromQL: the delivery deferral rate, the age of the outbound queue, webhook
dead letters, repeated SMTP authentication failures, scanner timeouts and
failed DNS lookups. Load it as a Prometheus rule file, or as a Grafana
managed-alerting group:
rule_files:
- karta-mail-alerts.ymlPromEx's Grafana dashboards for the other plugins exist upstream; Karta
does not upload them (grafana: :disabled).
Error reporting
With SENTRY_DSN set, exceptions in requests, jobs and processes, and every
log message at error level, are sent to that Sentry-protocol service (for
example Sentry, Bugsink or GlitchTip), with the environment prod.
Without it, nothing is sent.
Karta's own log messages avoid message content and credentials: storage and delivery failures are logged without message data, and crash reports of SMTP connections leave out message data and credentials.
Logs
Karta logs to standard output at info level in production
($time $metadata[$level] $message, with the request id). Worth alerting
on:
| Message | Meaning |
|---|---|
storing a message failed at ... | the database or the blob store failed while a message was accepted; the client got a temporary error |
sending a message failed at ... | the same, for the HTTP APIs |
message ... could not be read for delivery | a stored body is missing or cannot be decrypted (check the bucket and the vault keys) |
queued N delivery jobs again: their jobs were gone | the sweep found recipients without a delivery job (jobs that crashed 20 times or were cancelled) |
message retention failed: ... | a retention run failed; it is retried an hour later |
a delivery status notification for message ... was not stored | a DSN could not be stored; the delivery outcome was recorded anyway |
submission: the database failed: ... | SMTP clients got temporary errors |
SMTP connection from ... refused: ... | e.g. a connection from outside KARTA_SMTP_TRUSTED_PROXIES |
IP pool ...: this node no longer holds ... | an IP pool address left this node (a failover, or the address is gone); see IP pools |
IP pools: reading ... failed | the node could not read its interfaces or the pools; it keeps its last view |
Development dashboard
In development, Phoenix LiveDashboard runs at
http://localhost:4000/dev/dashboard. It is not compiled into production
releases.