Grafana and other tools¶
How-to guideThe steps for one task.
What each tool you may already run receives from Apinx, and the one setting that connects it. Every recipe is the smallest configuration that works; Observability has every option and what the gateway does when a tool is away.
| Tool | What it receives | Setting |
|---|---|---|
| Prometheus, Grafana | Metrics: requests, latency, refusals, backend attempts, queues | Scrape GET /metrics on the console port |
| Grafana Loki, with the Apinx dashboard | The access log, one line per request | access_log.sink: http, format: loki |
| Grafana Tempo, Jaeger | One span per request, in the same trace as your backend's spans | otel.enabled, otel.endpoint |
| Anything that accepts OTLP | Spans, and the metrics too with otel.metrics |
otel.* |
| Elasticsearch, OpenSearch (Kibana, OpenSearch Dashboards) | The access log | access_log.sink: http, format: elasticsearch |
| Seq | The access log as structured events | access_log.sink: http, format: seq |
| Vector, Fluent Bit, Logstash | The access log as newline-delimited JSON | access_log.sink: tcp |
| Syslog servers and SIEMs | The access log as RFC 5424 messages | access_log.sink: syslog |
| Load balancers, uptime monitors | Liveness and readiness | GET /healthz, GET /readyz |
| Postman | Collections in, collections out | Admin › Import & export; Postman on an API |
| HashiCorp Vault, a KMS | The master key that wraps every stored secret | security.master_key_provider |
The settings are process settings in apinx.yaml (or APINX_… environment variables), read
at start: restart the service after changing them. Every setting is in the
process configuration reference.
Apinx Cloud
In Apinx Cloud the process settings on this page are the platform's. An organization connects its own trace collector from Admin › Observability › Traces in your own tool (details); the Traffic and Analytics screens cover the rest.
Prometheus and Grafana¶
Every instance serves Prometheus metrics at GET /metrics on the console port (:9000 by
default). No session is needed, so Prometheus scrapes it as it is:
# prometheus.yml
scrape_configs:
- job_name: apinx
static_configs:
- targets: ["gw-a.internal:9000", "gw-b.internal:9000"]
- Scrape each instance on its own address, not through the load balancer: each instance
counts its own requests, and Prometheus's
instancelabel tells them apart. - Keep the port private.
/metricsneeds no session, so let only Prometheus reach it: a private address inconsole.listen, or a firewall rule. Where nginx fronts the console on each server, as in Deploying on Linux, an exact location keeps it to your Prometheus server's address:location = /metrics { allow 10.0.0.5; deny all; proxy_pass http://127.0.0.1:9100; }.
In Grafana, add the Prometheus data source and build panels from the series below. No ready dashboard ships for the metrics; the access log dashboard is described in the next section.
| Question | PromQL |
|---|---|
| Requests per second, by operation | sum by (route) (rate(apinx_proxy_requests_total[5m])) |
| Share of calls answered 5xx | sum(rate(apinx_proxy_requests_total{status_class="5xx"}[5m])) / sum(rate(apinx_proxy_requests_total[5m])) |
| p99 latency, by operation | histogram_quantile(0.99, sum by (le, route) (rate(apinx_proxy_request_duration_seconds_bucket[5m]))) |
| Refusals, by Apinx error code | sum by (code) (rate(apinx_proxy_rejected_total[5m])) |
| Backend attempts that failed, by upstream | sum by (upstream) (rate(apinx_upstream_attempts_total{outcome!="ok"}[5m])) |
| Requests in flight | sum(apinx_proxy_inflight_requests) |
| Responses cut before they were whole, by who cut them | sum by (by) (rate(apinx_proxy_aborted_total[5m])) |
| Access log lines lost | increase(apinx_accesslog_dropped_total[15m]) + increase(apinx_accesslog_failed_total[15m]) |
status_class is 2xx to 5xx; outcome on backend attempts is ok, 5xx or error (no
answer at all); by on cut responses is client, backend, timeout or fault. The route label is the operation; after the first 2,000 operations a process
serves, later ones share the route other, and the Analytics page keeps every one. The
runbook lists the signals worth an
alert.
Grafana Loki and the Apinx dashboard¶
Each line is pushed with the labels job="apinx" and node, plus any you add with
labels: [env=prod]. A multi-tenant Loki takes its tenant in
headers: ["X-Scope-OrgID: team-a"]; a Loki behind an authenticating proxy takes the
Authorization value in APINX_ACCESS_LOG_HTTP_API_KEY, written in full (Bearer …).
The dashboard. A ready Grafana dashboard ships with Apinx as
deploy/grafana/apinx-access-log.json (Grafana 10 or later):
- In Grafana, Dashboards › New › Import.
- Upload dashboard JSON file and choose
apinx-access-log.json. - Pick your Loki data source for the Loki input, then Import.
It shows the period's requests, error rate, 5xx, p99 latency, rate-limited calls (429) and bytes out; requests per minute by outcome; p50 and p99 per minute; the busiest operations; errors by status and cause; and the error lines, newest first. The Node and API selectors at the top filter every panel.
To explore on your own: {job="apinx"} | json | status >= 500.
Grafana Tempo or Jaeger¶
otel:
enabled: true
endpoint: tempo.internal:4317 # OTLP over gRPC
insecure: true # a collector on a private network without TLS
Enable the OTLP gRPC receiver in Tempo; Jaeger accepts OTLP on port 4317. Each request becomes
one span named by its method and operation (GET orders-get-order), with the policy steps and
backend attempts as events. A traceparent the client sends becomes the span's parent, and the
backend and every service callout receive the span's own, so your services' spans hang under the
gateway's. otel.sampling sets the share of traces exported (1 exports every request); a
request whose client sent a sampled traceparent is always exported.
From a log line to its trace. While the export is on, every access log line carries the
request's trace_id (with it off, only when the client sent a traceparent). In Grafana, add a
derived field to the Loki data source (name trace_id, regex "trace_id":"(\w+)", an internal
link to your Tempo data source) and each line of a sampled request opens its trace.
Anything that accepts OTLP¶
The same otel block reaches any OTLP endpoint: an OpenTelemetry Collector, Grafana Cloud, the
Datadog Agent with its OTLP receiver on, Honeycomb, and others. These are examples, not a list
of what is supported: the gateway speaks OTLP over gRPC (the default) or over HTTP with
protobuf.
otel:
enabled: true
endpoint: otel-collector.internal:4317
insecure: true
metrics: true # the Prometheus metrics over OTLP as well, every otel.interval
On the collector, an otlp receiver with the grpc protocol, then route traces and metrics
to whatever exporters you use. A collector in between is the easy way to send the same
traces to several places.
otel:
enabled: true
protocol: http
endpoint: https://otlp.example.com/otlp # the base URL; /v1/traces is appended
headers: ["X-Scope-OrgID: team-a"] # when the service wants extra headers
The Authorization value the service gives you (Bearer …, Basic …) goes in
APINX_OTEL_AUTHORIZATION; a token on its own is sent as Bearer <token>. With protocol: http the endpoint is the
service's base URL: the gateway appends /v1/traces (and /v1/metrics), and a path the
URL already has, such as /otlp, is kept.
What every span carries: service.name (otel.service_name, apinx by default), the
instance's cluster.node as service.instance.id, and the status, API, operation, upstream,
application, error code and cache outcome as attributes. Turn on otel.metrics only for a
collector that takes metrics; Jaeger and Tempo refuse them, and /metrics serves Prometheus
either way.
Elasticsearch or OpenSearch, with Kibana or OpenSearch Dashboards¶
access_log:
sink: http
http:
url: https://es.example.com/_bulk
format: elasticsearch
index: apinx-access
Put the Authorization value in APINX_ACCESS_LOG_HTTP_API_KEY, written in full:
ApiKey <encoded key> for an Elasticsearch API key, Basic <base64 of user:password> for an
OpenSearch user. Each line becomes one document with the access log's fields; time is the
request time in RFC 3339, UTC. Write to an index: a data stream needs an @timestamp field,
which only an ingest pipeline that copies time would add.
Then, in Kibana, Stack Management › Data views › Create data view with the index pattern
apinx-access* and time as the timestamp field; in OpenSearch Dashboards, Dashboards
Management › Index patterns with the same choices.
Seq¶
Create an API key with the Ingest permission in Seq and put it in
APINX_ACCESS_LOG_HTTP_API_KEY; it is sent as X-Seq-ApiKey. Events arrive with the request
time as @t, the level Warning for a 4xx and Error for a 5xx, the message
{method} {host}{path} {status}, and every field of the line as a property.
Vector, Fluent Bit or Logstash¶
access_log:
sink: tcp
tcp:
address: collector.internal:5170
tls: false # true when the collector's socket speaks TLS
One JSON object per line on a TCP socket. On the collector:
A collector that takes newline-delimited JSON over HTTP works too: sink: http with the
default format: ndjson.
Syslog servers and SIEMs¶
access_log:
sink: syslog
syslog:
network: tls # udp (the default), tcp or tls
address: syslog.example.com:6514
RFC 5424 messages with the JSON line as the message, octet-counted on TCP and TLS. APP-NAME is
apinx (syslog.app_name), HOSTNAME is the instance's cluster.node (or the host name), the
facility is local0 (syslog.facility), and the severity follows the status: informational,
warning for a 4xx, error for a 5xx. Any server that reads RFC 5424 over that transport takes
it, rsyslog and syslog-ng included.
Health checks¶
| Endpoint | Answers |
|---|---|
GET /healthz |
200 while the process is up |
GET /readyz |
200 when every component started and the store answers; 503 names the failing check |
Both are on the console port and need no session. Point your load balancer's health check and
your uptime monitor at /readyz. See Health.
Several instances¶
With high availability, point every instance at the same destination and let the tools tell the instances apart:
- Logs: every line carries
node(cluster.node, or the host name); in Loki it is also a label, and the dashboard's Node selector filters by it. - Traces:
service.instance.idis the instance'scluster.node. - Metrics: scrape each instance; Prometheus adds
instance. - The console's own Traffic screen:
inspector.shared: trueon every instance keeps the captured requests in the Redis the rate limits already use, so a trace is found whichever instance served it (details).
API tools¶
Postman. Bring an API in from a collection (v2.0 or v2.1) under Admin › Import & export › Import an API › Postman collection: one operation per request, the collection's auth as suggested policies, no credential ever imported (Importing a Postman collection). Going the other way, Postman in an API's page header, or on a product's page, downloads a v2.1 collection for its callers: one request per operation and method, credentials and required headers as collection variables with placeholders, example bodies. No key or secret is ever in it. The same collection comes from the Admin API with the address callers use:
curl -H "Authorization: Bearer $TOKEN" \
"https://console.example.com/api/v1/apis/$API_ID/postman?base_url=https://api.example.com&tests=true" \
-o orders.postman_collection.json
tests=true adds a basic test to every request, so the collection runs in the Postman runner or
with newman in CI.
OpenAPI. An OpenAPI 3 document becomes an API with one operation per path and method, and
its request schemas become validate policies
(Importing an OpenAPI document).
WSDL. A SOAP service's WSDL becomes a JSON API, one operation per SOAP operation (SOAP backends as JSON APIs).
The Admin API in your tools. Every instance publishes its own description at
GET /api/v1/openapi.json (OpenAPI 3.1, no session needed): import it into Postman, or into any
tool that reads OpenAPI, to call the Admin API with a bearer token
(Admin API).
Scripts and CI. apinxctl exports, imports, diffs and publishes the configuration, and
apinx gateway validate checks a file with no server
(The command line, Configuration as code).
Secrets: Vault and KMS¶
On premises, the master key that wraps every stored secret can stay in the system you already use for keys, instead of an environment variable or a file:
security:
master_key_provider: vault
vault:
address: https://vault.example.com:8200
transit_key: apinx # the Transit key that wraps Apinx's data keys
# transit_mount: transit # the default
The token goes in APINX_SECURITY_VAULT_TOKEN. Vault wraps and unwraps Apinx's data keys;
it is never called on the request path.
Secret fields of the configuration may also hold references resolved on the gateway host:
env:NAME, file:/path and vault:path#field (Vault KV version 2), set by administrators, on
premises only. Security has the rules and the
rotation of both key layers.