Karta. Metrics
(Karta v1.0.0)
The mail metrics: one function for each thing Karta counts, each of them
an :telemetry.execute/3 event that Karta.PromEx.Mail turns into a
Prometheus metric.
What is measured. The outcome of each recipient of an outgoing
message and the TLS it was delivered over; the replies a client was
refused with, the connections opened and the authentication attempts of
the SMTP listeners; the results of the SPF, DKIM and DMARC checks of
received mail; the spam and virus scan's latency and result; each DNS
lookup (from the cache, from the resolver, or failed); each webhook
request; each bounce and complaint recorded; and, read from the database
every 30 seconds (Karta.Metrics.Report), how much mail waits per server
and queue, how long the oldest waiting recipient has waited, how many
inbound deliveries and webhook deliveries are held or failed, and how
many addresses a server suppresses.
No metric carries what a message says. A label is an outcome, a status class, a reply code, a queue, a pool, a listener, a mechanism, a scan's result or a server's id — never a message id, an address, a subject, a recipient's domain, a HELO name or reply text. Metrics outlive the message they measured, so a label with a customer's data in it would be a copy of that data in Prometheus, Grafana and every backup of them. A server is named by its id (a UUID): an operator maps it to the server in the admin pages, and the metrics never hold the customer's name.
Labels are a closed set. A reply code, an enhanced status class, a
TLS policy's name and a scanner's verdict come from outside Karta — from
a receiving server, from a domain's records, from a scanner. Each is
mapped onto the fixed sets below, and anything else is "other":
without that, a server answering with invented codes would make a new
Prometheus series for every reply it sent.
Never raises. Every function builds a map of strings and calls
:telemetry.execute/3, which reports a failing handler without failing
its caller. The polling report is guarded too: the poller runs before
the database is started.
Summary
Functions
An authentication attempt: the event [:karta, :smtp, :auth] with the
measurement attempts and the metadata listener, mechanism and
result ("ok", "failed" or "temporary"). The user name is never
part of it.
A bounce recorded from a report sent to the return path: the event
[:karta, :bounce] with the measurement reports and the metadata
server, kind ("hard" or "soft") and class. A report that was
recorded before is not counted again.
A complaint recorded from a feedback report: the event
[:karta, :complaint] with the measurement reports and the metadata
server and feedback_type. A report that was recorded before is not
counted again.
An SMTP connection accepted or refused: the event
[:karta, :smtp, :connection] with the measurement connections and
the metadata listener and result ("accepted" or "refused").
The outcome of each recipient of one run of the deliverer, grouped by
outcome, enhanced status class and reply code: the event
[:karta, :delivery, :outcome] with the measurement recipients and the
metadata server, outcome, class and code.
The TLS each recipient's last attempt ran under, grouped by the policy
that decided it and the version negotiated: the event
[:karta, :delivery, :tls] with the measurement deliveries and the
metadata server, policy and result ("tlsv1.3", "tlsv1.2",
"other" or "none").
One DNS lookup: the event [:karta, :dns] with the measurements
lookups and duration (native time) and the metadata type, cache
("hit", "miss" or "none" when the lookup had no cache) and
result ("ok" or why there is no answer). The name looked up is never
part of it.
The inbound deliveries a server has in status ("pending" or
"held"): the event [:karta, :inbound, :deliveries] with the
measurement deliveries.
The outgoing recipients waiting for a server and queue, and the age of
the oldest one that is due: the events [:karta, :outbound, :queue]
(recipients and age in seconds) with the metadata server, queue
and status.
What the checks of a received message found: one
[:karta, :auth, :spf] event per identity checked (the measurement
checks), one [:karta, :auth, :dkim] event per signature result (the
measurement signatures, and "none" for a message without a
signature), and one [:karta, :auth, :dmarc] event per author domain
(the measurement checks). No domain and no address is a label.
A reply of 4xx or 5xx an SMTP listener sent: the event
[:karta, :smtp, :refusal] with the measurement refusals and the
metadata listener (the listener's kind), code and class. A policy
refusal at the end of DATA counts here too, and so does the 452 of a
client that names more recipients than a message may have.
A report Karta sends about a domain: the event [:karta, :report, :sent]
with the measurement reports and the metadata kind and result
(sent, limited, failed, skipped or retry). Never a domain or
an address.
One scan of a received message: the event [:karta, :scan] with the
measurements runs and duration (native time) and the metadata
spam and virus ("ok", "infected", "timeout", "unavailable",
"too_large" or "disabled").
The addresses a server suppresses for a reason, still in force: the
event [:karta, :suppressions] with the measurement entries.
One webhook request: the event [:karta, :webhook, :attempt] with the
measurements attempts and duration (milliseconds) and the metadata
server, result ("2xx", "3xx", "4xx", "5xx" or "none" for
no answer) and state ("succeeded", "pending" or "failed" after
the attempt). The URL, the event and the payload are never part of it.
The webhook deliveries a server has in state ("pending" or
"failed", the dead letters): the event
[:karta, :webhook, :deliveries] with the measurement deliveries.
Functions
An authentication attempt: the event [:karta, :smtp, :auth] with the
measurement attempts and the metadata listener, mechanism and
result ("ok", "failed" or "temporary"). The user name is never
part of it.
@spec bounce(map()) :: :ok
A bounce recorded from a report sent to the return path: the event
[:karta, :bounce] with the measurement reports and the metadata
server, kind ("hard" or "soft") and class. A report that was
recorded before is not counted again.
@spec complaint(map()) :: :ok
A complaint recorded from a feedback report: the event
[:karta, :complaint] with the measurement reports and the metadata
server and feedback_type. A report that was recorded before is not
counted again.
An SMTP connection accepted or refused: the event
[:karta, :smtp, :connection] with the measurement connections and
the metadata listener and result ("accepted" or "refused").
The outcome of each recipient of one run of the deliverer, grouped by
outcome, enhanced status class and reply code: the event
[:karta, :delivery, :outcome] with the measurement recipients and the
metadata server, outcome, class and code.
The TLS each recipient's last attempt ran under, grouped by the policy
that decided it and the version negotiated: the event
[:karta, :delivery, :tls] with the measurement deliveries and the
metadata server, policy and result ("tlsv1.3", "tlsv1.2",
"other" or "none").
@spec dns(Karta.DNS.Record.type(), :hit | :miss | :none, term(), integer()) :: :ok
One DNS lookup: the event [:karta, :dns] with the measurements
lookups and duration (native time) and the metadata type, cache
("hit", "miss" or "none" when the lookup had no cache) and
result ("ok" or why there is no answer). The name looked up is never
part of it.
@spec inbound(term(), atom(), non_neg_integer()) :: :ok
The inbound deliveries a server has in status ("pending" or
"held"): the event [:karta, :inbound, :deliveries] with the
measurement deliveries.
@spec queue(term(), String.t(), atom(), non_neg_integer(), non_neg_integer() | nil) :: :ok
The outgoing recipients waiting for a server and queue, and the age of
the oldest one that is due: the events [:karta, :outbound, :queue]
(recipients and age in seconds) with the metadata server, queue
and status.
@spec received(map()) :: :ok
What the checks of a received message found: one
[:karta, :auth, :spf] event per identity checked (the measurement
checks), one [:karta, :auth, :dkim] event per signature result (the
measurement signatures, and "none" for a message without a
signature), and one [:karta, :auth, :dmarc] event per author domain
(the measurement checks). No domain and no address is a label.
A reply of 4xx or 5xx an SMTP listener sent: the event
[:karta, :smtp, :refusal] with the measurement refusals and the
metadata listener (the listener's kind), code and class. A policy
refusal at the end of DATA counts here too, and so does the 452 of a
client that names more recipients than a message may have.
A report Karta sends about a domain: the event [:karta, :report, :sent]
with the measurement reports and the metadata kind and result
(sent, limited, failed, skipped or retry). Never a domain or
an address.
One scan of a received message: the event [:karta, :scan] with the
measurements runs and duration (native time) and the metadata
spam and virus ("ok", "infected", "timeout", "unavailable",
"too_large" or "disabled").
@spec suppressions(term(), atom(), non_neg_integer()) :: :ok
The addresses a server suppresses for a reason, still in force: the
event [:karta, :suppressions] with the measurement entries.
One webhook request: the event [:karta, :webhook, :attempt] with the
measurements attempts and duration (milliseconds) and the metadata
server, result ("2xx", "3xx", "4xx", "5xx" or "none" for
no answer) and state ("succeeded", "pending" or "failed" after
the attempt). The URL, the event and the payload are never part of it.
@spec webhook_backlog(term(), atom(), non_neg_integer()) :: :ok
The webhook deliveries a server has in state ("pending" or
"failed", the dead letters): the event
[:karta, :webhook, :deliveries] with the measurement deliveries.