Skip to main content

Connect Prometheus to an Environment and read Analytics beside its own numbers

The Prometheus URL and its connection test, the label an Environment is read under, the Analytics cards, and the same window in Prometheus with the same count.

By Akif F. Güven Observability

What you will have at the end

An Environment whose Analytics reads from a Prometheus you run: request counts by status class, p50 and p95, the busiest Routes, and the changes from the audit log drawn into the same window. And the proof the site promises: the Analytics card for a window and a Prometheus query for the same window, side by side, with the same number. The article also says what “the first samples of a new series are not counted” means in practice, with the example from the circuit-breaker article.

Prerequisites

  • A Prometheus that scrapes the gateway cluster’s metrics endpoint and puts the Environment’s label on the series. The lab’s scrapes each cluster with a static label, g8_environment, set to the Environment’s slug; the Environment form shows the exact label it will read.
  • A role that may manage Environments, and some traffic. The screenshots below were taken as nora.becker, on Staging and on Sandbox.

The URL and the test

Open Environments, the Environment’s menu, Edit, and under Observability fill Prometheus URL. Test connection asks the Prometheus for its version and for one series under the Environment’s label:

The Observability section of the Staging Environment form: Elasticsearch URL, Username g8-staging-server and the password as Stored with a Replace link, Prometheus URL http://localhost:9092 and the test result Connected · Prometheus 3.15.0 · label g8_environment=staging present, and under it the note with the index pattern g8-staging-access-* and the Prometheus label g8_environment="staging" Connected, and the label is there. The note under the fields is the contract: this Environment is read under this label and nothing else.

A Prometheus that answers but holds no series under the label is reported as connected with “no series labelled … yet”, in amber, which is what a fresh Environment shows until its first scrape; Add your first Environment has that screenshot. Save environment.

What Analytics shows

Analytics in the Environment’s navigation, for the last 24 hours:

The Analytics page of Staging: the Gateway nodes card with one node receiving traffic, the chart Requests · today, last week and where today is heading in 15-minute buckets with the note that the counts are estimates on this Prometheus, and the Requests card with 4.4K requests, 2xx 72 %, 4xx 28 %, 5xx under 1 % Counts by status class, from the Environment’s Prometheus. The note under the chart says the counts are estimates on this Prometheus version; a 3.16, or a 3.7 to 3.15 started with the extended range selectors feature, counts them exactly.

Below it, the response times as the client sees them and as the backends took them, estimated from the histogram buckets the gateway publishes:

The card Response time · as the client sees it: every request the gateway answered in the last 24 hours, a chart over the day, and the line p50 · 26 ms, p95 · 239 ms, p99 · 1,508 ms p50, p95 and p99 over the window. The Backend and Gateway cards under it split the same requests into the backend’s time and the gateway’s own.

The lists: the Routes with the most requests, the most 5xx and the slowest, and the same three for Services and Upstreams.

The card Routes · most requests: a ranked list with payments-api 2.8K, orders-api 442, orders-ha-api 180, orders-contract 140, orders-canary 120, assistant-api 86, orders-mcp 31, chat-api 24, catalog-api 23 and directory-api Who is busy. Each Route’s own Analytics tab is one click away, and reads the same series under its id.

And the card that ties the numbers to the people: Changes in this window, the audit records of the window, which the request chart also draws as markers.

The card Changes in this window: 25 of 140 from the audit log, rows with the time, Route updated, the Route's name and the actor nora.becker · Local A step in the chart has a row here. The actor is named because every change is an audit record.

The same window in Prometheus

The Sandbox Environment is small enough to count by hand. Its Requests card for the last 24 hours:

The Requests card of the Sandbox Analytics: 24 requests in the last 24 hours, by status class 2xx 0, 3xx 0, 4xx 24 at 100 %, 5xx 0 Twenty-four requests, all 4xx.

The Prometheus itself, asked for the increase of the gateway’s request counter over the same 24 hours under the Sandbox label, by status code:

The Prometheus web interface with a query summing the increase of the gateway's request counter over 24 hours for the sandbox label by code, and the table result: code 200 → 0, 401 → 1.00, 404 → 3.00, 429 → 20.01 One plus three plus twenty is twenty-four. The card and the query read the same series the same way; Analytics adds no number of its own.

The fractions after the decimal point are Prometheus’s own extrapolation at the window’s edges, which is the “estimate” the chart note talks about; the card rounds them to whole requests.

What is not counted, and why

Code 200 reads zero in both places, and Your first Route sent six 200s on this Environment, in two new series: one without a Consumer from before the Plugins, at 1, and five as mobile_app, first scraped at 5. Each was the first sample of its series: a counter that is born inside the window has no earlier value to increase from, so Prometheus’s increase over the window, and therefore Analytics, leaves those first samples out. The same thing made the breaker’s two 503s invisible in A failing backend out of rotation. In practice: the requests in the first scrape of a new series, a Route’s first requests or the first answers with a status code it has not given before, are in Traffic Explorer and never in Analytics. The records are the complete list; Analytics is the rate.

What to do next

Written by
Akif F. Güven
Engineer, 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.