Skip to main content

Alerts on error rate and response time, by email and signed webhook

A rule on a Route's 5xx share and one on its p95, a mail relay and a signed webhook, fired by stopping a backend, and the system alert when Prometheus is gone.

By Efsun Balcı Observability

What you will have at the end

Two alert rules in the Staging Environment: one that fires when more than half of a Route’s answers in the last five minutes were 5xx, and one that fires when the same Route’s p95 response time crosses 500 ms. Both rules are on one Route: the form offers a Service as a scope too, but Staging has no Service to put one on. Both tell two channels: a mail list through your relay and a webhook that your receiver can verify with an HMAC signature. The article fires them by stopping the Route’s backend, reads what arrived in the mailbox and at the webhook, and follows the episodes in History and on their own pages. Then it stops the Environment’s Prometheus to show the system alert that says so. Every number below is from the install; the times are the console’s, in its own zone, and the mails give the same moments in UTC.

Prerequisites

  • An Environment with a Prometheus connected, as in Connect Prometheus to an Environment. Rules read their numbers there, so an Environment without one has nothing to evaluate.
  • A Route with traffic you can break. Here it is orders-v2-api, /v2/orders/* to the single-node Upstream orders-v2, with the api-breaker Plugin from A failing backend out of rotation still on it; the article stops that node.
  • A mail relay the server can reach and a receiver for the webhook. The lab has a mailbox container that offers STARTTLS on port 1025 with a self-signed certificate, and a small container that prints every request it receives, so the article can show what arrived.
  • A role that may manage alerts. The screenshots below were taken as nora.becker.

The channels first

Open Alerts in the Environment’s navigation and select Settings. The page has three parts: the relay the mail lists send through, the mail lists, and the webhooks.

The mail relay

Set up mail relay takes Host, Port and From address, and an Account that stays empty when the relay accepts mail without signing in. The line under the title is the rule the relay has to meet: STARTTLS is always used, so the relay must offer it on that port; the note under Port says 587 is the usual one. Select Send test mail before saving. On this install the first test was refused:

The mail relay form with Host localhost, Port 1025 and From address alerts@corp.example, and a red banner on top: localhost did not accept the test notification, the certificate is not trusted by the CA bundle of the environment or the system roots, tls: failed to verify certificate: x509: certificate signed by unknown authority The relay answered, but with a certificate nobody vouched for. The form says what to do about it.

The relay’s certificate is checked against the Environment’s CA bundle and the system roots, so a relay with a certificate from your own CA needs that CA in Environment › CA certificates, the same bundle the Environment uses for its other HTTPS connections. With the lab relay’s certificate added there, the test mail was accepted and arrived in the mailbox as [g8] TEST · Staging · Test notification. Then Save.

A mail list and a webhook

Add list takes a name and the addresses; ops-oncall here with one address. Preview message on the same card shows the mail a list receives, exactly as the server writes it, with an example rule.

Add webhook takes a Name, the URL, and an optional Signing key. The help under the URL is the one to read: notifications are POSTed as JSON, and the address should carry no secret, because everyone who can view Alerts sees it; the signing key is how a receiver verifies the sender. The help under the key says what the receiver will get: X-G8-Timestamp and X-G8-Signature, the latter v1= and the hex HMAC-SHA256 of the timestamp, a dot and the body, under the key.

The New webhook dialog: Name ops-chat, URL http://127.0.0.1:18080/alerts with the help that notifications are POSTed as JSON and the address should carry no secret, and the Signing key typed and masked with the help naming X-G8-Timestamp and X-G8-Signature The key is typed once and stored sealed. From here on the Settings page says Stored and nothing else.

The Settings page after both are saved. Example request on the Webhooks card shows a whole delivery, headers and body, computed with an example key, so a receiver can be written and tested before any rule exists.

The Alerts Settings page: the Mail relay card marked Configured with Relay localhost:1025, Encryption STARTTLS checked against the CA bundle of Staging and the system roots, No account, From alerts@corp.example; the Mail lists card with ops-oncall and its address; the Webhooks card with ops-chat, its URL, Signing key Stored and Used by No rules Relay, list, webhook. Used by counts the rules that name each channel; none yet.

Two rules on one Route

Back under Rules, select New rule. The form has three sections and a Changes panel on the right that shows what will be sent when you save.

orders-v2 answering 5xx: under Watch, Scope is one of Environment, Route, Service, Upstream and Consumer; Route here, and Target finds orders-v2-api by name. Signal is Response share, Status 5xx, Threshold 50 %, Window 5 minutes. Under Notify, tick ops-chat and ops-oncall.

The New rule form: Name orders-v2 answering 5xx; under Watch, Scope Route, Target orders-v2-api · 00000000000000010257, Signal Response share, Status 5xx, Threshold 50 %; the Changes panel on the right showing the rule as JSON with the two channel ids, the condition and the scope One signal, one target, one threshold over one window. The panel shows the rule as the server will store it.

orders-v2 slow p95: the same scope and target, Signal Response time, Measured As the client sees it rather than In the backend, Threshold 500 ms, and the help under it says what is compared: the p95 over the window. Window 5 minutes.

Hold, the last field of the section, is the one this article did not set and should have. Its help: fires only when the condition holds this long, and resolves after it clears this long. None here, which is what the measurement below shows the consequence of.

The Watch section of the p95 rule: Scope Route, Target orders-v2-api, Signal Response time, Measured As the client sees it, Threshold 500 ms with the help Compared with the p95 over the window, Window 5 min, and Hold None with the help that the rule fires only when the condition holds this long and resolves after it clears this long p95 as the client sees it, over five minutes. Hold is what keeps a rule from flapping; leave it at None and the next section shows what happens.

Select Create rule. The list shows both with a state: No data · No requests in the window for the Route nobody is calling, Awaiting evaluation for a rule the evaluator has not seen yet. The page says when the last evaluation was; on this install one runs every minute.

The system alert

Under the rules, System alerts lists what the server watches on its own: the engine’s Admin API, requests of a Route not being counted, Prometheus unreachable, the daily cleanup of request records failing, a gateway node that stopped reporting and one that runs a configuration behind the others. Each is Off until it gets channels. The row menu of Prometheus unreachable offers Switch on…, which asks only for the channels:

The Switch on dialog of the Prometheus unreachable system alert: the condition Prometheus cannot be read, for 5 min, and the two channels ops-chat and ops-oncall ticked A system alert has its condition built in; you choose who hears about it.

Stop the backend and watch

The node orders-v2 is stopped at 02:37:27, and a loop sends a request to /v2/orders/ord-10421, waits two seconds and sends the next. The breaker on the Route answers 503 for the dead node; that is a 5xx the client got, and the share rule counts it:

### orders-v2 stopped at 02:37:27, a request, two seconds' pause, the next
02:37:28 503 0.222s
02:37:30 503 0.147s
02:37:32 503 0.193s
…

Twenty-three seconds after the stop, at the evaluator’s next minute, the share rule fired: every request in the window was a 5xx, 100 % against a threshold of 50 %. Two minutes later the p95 rule fired at 1,066.7 ms.

The Route’s records say what raised the p95. Every 5xx of the outage is a 503 with gateway as the Upstream node: the breaker answered and no node was asked, so there was no slow connection attempt. Most of those 503s took no measurable time at the gateway, but six between 02:38:55 and 02:39:29 took 0.45 to 1.7 s there, and the client waited up to 3.5 s for them. Those few slow answers are enough to lift the p95 of a window this small. The records do not say why the gateway was slow to refuse them.

The Rules list with both rules Firing: orders-v2 answering 5xx, 5xx share above 50% over 5 min, and orders-v2 slow p95, p95 response time above 500 ms, each with the channels ops-chat · ops-oncall; the System alerts under them with Prometheus unreachable OK and the others Off; the bell in the header showing 2 Two firing rules, and the bell in the header counts them from any page of the Environment.

What the mail list received

Subject: [g8] FIRING · Staging · orders-v2 answering 5xx
From: alerts@corp.example  To: oncall@corp.example

Alert: orders-v2 answering 5xx
Status: FIRING
Environment: Staging (staging)
Scope: route 00000000000000010257
Summary: 5xx answers were 100% of all requests over the 5 min before 23:37:50 UTC, above the 50% threshold.
Condition: 5xx share above 50% over 5 min
Value: 100%
Started: 2026-10-13T23:37:50Z
Episode: 1
Delivery: bfdc00f9-82af-4483-bb3a-f31eec032552

Plain text, one fact per line, with the sentence a person on call needs first. The mail speaks UTC; 23:37:50 UTC is the 02:37:50 of the console.

What the webhook received

The receiver printed the headers and the body of the first delivery:

User-Agent: g8/0.1.0-dev
Content-Type: application/json
X-G8-Delivery: 7f487e35-3fae-4a71-a1ac-bfb5ac5f0309
X-G8-Status: fired
X-G8-Timestamp: 1791934680
X-G8-Signature: v1=935e76ace6b693e19375066989b223dff42d54ff2a0ba805a81445f7753781d1
{"schema": "g8.alert.v1", "delivery_id": "7f487e35-3fae-4a71-a1ac-bfb5ac5f0309",
 "status": "fired", "reason": null, "at": "2026-10-14T02:37:50.340763+03:00",
 "environment": {"id": "staging", "name": "Staging"},
 "rule": {"id": "558f91f0-1eba-4221-998e-c9fad7fb4982", "name": "orders-v2 answering 5xx",
          "kind": "share", "system": false},
 "scope": {"kind": "route", "id": "00000000000000010257"},
 "condition": {"status": "5xx", "measured": null, "direction": null,
               "threshold": 50, "window_seconds": 300, "for_seconds": 0},
 "value": 100, "detail": "", "detail_text": "", "subjects": [],
 "started_at": "2026-10-14T02:37:50.340763+03:00", "ended_at": null,
 "episode_id": 1, "event_id": 1}

The signature was checked the way the form described it: HMAC-SHA256 under the signing key over the timestamp, a dot and the body exactly as received. For this delivery, with the key in $KEY, the timestamp in ts and the body in body:

printf '%s.' "$(cat ts)" | cat - body | openssl dgst -sha256 -hmac "$KEY"
SHA2-256(stdin)= 935e76ace6b693e19375066989b223dff42d54ff2a0ba805a81445f7753781d1

The same value follows v1= in the header. Every later delivery was checked the same way and matched. X-G8-Delivery is the id a receiver can use to drop a repeated delivery, and X-G8-Status says fired or resolved without parsing the body. The User-Agent names the server’s build; the Staging server of this article is a development build, which calls itself 0.1.0-dev.

Bring the backend back

orders-v2 is started again at 02:40:51, and a second loop starts beside the first, so from then on about one request a second reaches the Route. The breaker had not closed yet: the first 200 is at 02:40:56, and the last 503 at 02:41:10, nineteen seconds after the node was back. In all, the records hold 98 requests answered 503 between 02:37:28 and 02:41:10, every one by the gateway. The share rule resolved at 02:43:50, when the 5xx of the outage had fallen to 30.54 % of the window, under the threshold, and both channels got a second notification with Status: RESOLVED, the ended time and the same episode number.

The p95 rule did something else. It resolved one minute after it fired, at 02:40:50, with the p95 read at 481.3 ms; fired again at 02:42:50 at 971.9 ms, as the slow 503s were still inside the five-minute window; and resolved at 02:47:50 at 275 ms. Two episodes, eight notifications, for one outage. That is what Hold is for: with Hold at 5 minutes the rule fires only once the condition has held for five minutes and resolves only once it has been clear that long, and the one-minute dip would not have reached anyone.

History and the episode’s page

History lists episodes: when each fired, the rule, the scope, the state, the value against the threshold, the duration and how many notifications were sent. The filters narrow it by rule and by state.

The History page with four episodes, all Resolved: Prometheus unreachable on the Environment, 8 minutes, 4 sent; orders-v2 slow p95 twice, 5 minutes and 1 minute, 4 sent each; orders-v2 answering 5xx, 100% against threshold 50%, 6 minutes, 4 sent One row per episode. Four sent is two channels, told twice: fired and resolved.

The fired time of a row opens the episode’s page. Why it fired is the sentence of the mail; under it the rule, the value, the window, when it fired and ended, and why it ended, here the condition cleared. Where to look links to the 5xx request records of the Route in Traffic Explorer and to its Analytics. Notifications is the delivery table: each channel, each notification, the result, the attempts and the last attempt. And Traffic around the alert draws the Route’s Analytics cards for the minutes around the episode: 367 requests between 02:32 and 02:48, 81 of them 5xx, every one a 503 and every one answered by the gateway, which is the breaker. The records hold 98 503s for the same minutes; the note under the chart says why the two differ here: this Prometheus gives estimates, not exact counts.

The top of the episode page of orders-v2 answering 5xx: Resolved, Fired 14 Oct 2026, 02:37:50; Why it fired, 5xx answers were 100% of all requests over the 5 min before 02:37:50, above the 50% threshold; the rule, scope, condition, value, threshold, window, fired, ended, duration 6 minutes and Ended because the condition cleared; Where to look with Open the 5xx request records and Open in Analytics The page a person on call lands on from the mail: the sentence, the numbers, and the two places to look next.

The Notifications table of the episode: ops-chat Webhook Fired Sent 1 attempt 02:38:00, ops-oncall Mail list Fired Sent 1 attempt 02:38:00, and the two Resolved rows at 02:44:00 Each delivery with its result and its attempts. A relay or a receiver that refused would be a row here, with its reason.

The Traffic around the alert chart of the episode: requests per minute between 02:35 and 02:48, red 5xx bars from 02:37 to 02:40, a 02:41 bar mostly green with a red top, then green 2xx bars, and the note under it that the counts are estimates because this Prometheus does not take the anchored range selector The outage as the Route’s own minutes. The taller bars from 02:41 are the two loops running side by side; the red top at 02:41 is the breaker still open after the node came back.

An episode starts when a rule fires and ends when the condition clears or the rule is changed, disabled or deleted; the page says episodes are kept for 90 days after they end.

When Prometheus cannot be read

The Environment’s Prometheus is stopped at 02:48:46. Within a minute every rule’s state reads Not measured · Prometheus could not be reached, and the system alert goes Pending: its condition is Prometheus unreachable for five minutes. It fired at 02:54:50.

The Rules list while Prometheus is down: both rules Not measured, Prometheus could not be reached, and under System alerts the row Prometheus unreachable Firing with the channels ops-chat · ops-oncall; the bell in the header showing 1 The rules say they could not be measured rather than OK, and the system alert says why.

The mail, [g8] FIRING · Staging · Prometheus unreachable, has the same lines as the one above, with Scope: environment, Summary: Prometheus could not be reached., Detail: metrics_store_unreachable and a Cause line with the connection error: dial tcp [::1]:9092: connect: connection refused. Its episode number is 7: episode numbers are not consecutive within one Environment’s History, which here lists 1, 2, 4 and 7.

The webhook got the same as JSON, with "rule": {"kind": "prometheus_unreachable", "system": true}, "scope": {"kind": "environment"} and the cause in detail_text, signed like the rest. The bell in the header lists it from any page of the Environment:

The bell popover in the header: 1 firing alert, Prometheus unreachable, Staging · started 6 minutes ago The firing alerts of the Environment, one line each, from wherever you are in it.

Prometheus is started again at 02:55:53. The system alert resolved at 03:02:50, once it had been readable for five minutes, with Status: RESOLVED, started and ended, to both channels; History shows the episode as 8 minutes, 4 sent. The rules went back to No data and then to OK as the requests resumed.

What to do next

Written by
Efsun Balcı
Engineering intern, G8
Was this helpful?
Next step

See G8 in a demo

We’ll show you the console with APIs and AI traffic like yours, and answer the questions these articles leave open.

  1. 01Demo
  2. 02Proof of conceptOn Docker for a quick start, or on the infrastructure you plan to run G8 on.
  3. 03LicenseWe prepare a quote for your edition and nodes, and you receive a signed license file.