Skip to main content
Version: 0.18.x-dev

Admin API

Snakeway includes a built-in administrative API for monitoring proxy health, inspecting upstream services, viewing traffic statistics, and triggering configuration reloads. All endpoints are served on the address configured in bind_admin under the /admin/ path, and all responses are JSON-formatted.

Configuration​

The Admin API listens on the address specified by bind_admin in your ingress configuration. See the Admin Bind reference for the full set of fields.

A minimal block looks like:

bind_admin = {
interface = "127.0.0.1"
port = 8440
tls = {
mode = "manual"
cert = "/etc/snakeway/admin.crt"
key = "/etc/snakeway/admin.key"
}
auth = {
bearer = {
token_file = "/etc/snakeway/admin.tokens"
}
}
}

Authentication​

Every admin request must present a bearer token in the Authorization header:

curl -H "Authorization: Bearer $TOKEN" https://127.0.0.1:8440/admin/health

Requests without an Authorization header, with a non-Bearer scheme, or with an unknown token receive a 401 Unauthorized response and a WWW-Authenticate: Bearer realm="snakeway-admin" header.

Token file format​

The file referenced by auth.bearer.token_file contains one token per line:

a9f1c38de4b67029c5d1e97f4a0ebac12d3b8ffc84e1d27a05f6cb9e83d21a04
7b4e19a2c5f8d3046e9b71c8a52f9e1d4c07bfa6e93d1c24b87a90fed362014c

Rules:

  • Each token must be at least 32 bytes after trimming whitespace. Use a high-entropy source such as openssl rand -hex 32.
  • Blank lines are rejected to avoid masking format mistakes.
  • Comment lines (starting with #) are rejected. The format is intentionally unambiguous.
  • Duplicate tokens are reported as warnings, not errors.

The file should be owned by the Snakeway process user and have mode 0600 (or equivalent ACL). Filesystem permissions are the at-rest control. Snakeway does not hash tokens.

Token rotation​

Multiple tokens in the file are all accepted concurrently. The rotation workflow is:

  1. Generate a new token and append it to token_file.
  2. Run snakeway reload (or POST /admin/reload).
  3. Migrate callers to the new token.
  4. Remove the old token from token_file.
  5. Run snakeway reload again.

Because both tokens are valid during steps 2 to 4, there is no window where a caller must choose between the old and new token.

Defense in depth​

Authentication is the innermost of three layers:

  1. Reachability via bind_admin.interface (no wildcard binds).
  2. Transport via mandatory TLS.
  3. Authentication via bearer token (this section).

Continue to restrict the listener to a trusted interface and configure TLS. Authentication limits who can call the API given they can reach it. It does not replace network-level restriction. This mirrors the guidance published by the Envoy project and Caddy project for their own admin interfaces.

Endpoint reference​

GET /admin/health​

Reports process liveness.

curl http://localhost:8081/admin/health

Example response:

{
"status": "ok"
}

The endpoint returns 200 OK while the process is running. It does not inspect upstream health or circuit breaker state. For per-upstream health, use GET /admin/upstreams.

GET /admin/upstreams​

Provides a detailed view of all registered upstreams, including their current health status, circuit breaker state, and request counters.

curl http://localhost:8081/admin/upstreams

Example response:

{
"services": {
"api": {
"127.0.0.1:8080": {
"endpoint": "127.0.0.1:8080",
"upstream_id": 12345,
"weight": 1,
"latency_milliseconds": 12,
"health": {
"healthy": true
},
"circuit": "closed",
"active_requests": 0,
"total_requests": 150,
"total_successes": 148,
"total_failures": 2,
"circuit_params": {
"enabled": true,
"failure_threshold": 5,
"open_duration_milliseconds": 10000,
"half_open_max_requests": 1,
"success_threshold": 2,
"count_http_5xx_as_failure": true
},
"circuit_details": {
"consecutive_failures": 0,
"opened_at_rfc3339": null,
"half_open_in_flight": 0,
"half_open_successes": 0
}
}
}
}
}

The circuit field reflects the current circuit breaker state: "closed" (normal operation), "open" (upstream is failing, requests are rejected), or "half_open" (probe requests are being sent to test recovery).

The upstream_id field is the value used as the upstream label on metrics and in structured logs, such as circuit_transition events. Use it to map a metric series or log line back to the endpoint shown here. It is derived from the upstream's address and stays stable across reloads.

The latency_milliseconds field is a moving average of the time each successful request to that upstream took, in milliseconds. Recent requests count more than older ones. It is null until the upstream has served a successful request.

GET /admin/stats​

Returns aggregated traffic statistics per service, including active connections and cumulative counters.

curl http://localhost:8081/admin/stats

Example response:

{
"traffic": {
"api": {
"active_requests": 5,
"total_failures": 12,
"total_requests": 1500,
"total_successes": 1488
},
"static": {
"active_requests": 0,
"total_failures": 0,
"total_requests": 450,
"total_successes": 450
}
},
"websocket": [
{
"route_id": {
"kind": "Service",
"path": "/chat",
"target": "chat"
},
"active": 3,
"max": 100
}
]
}

traffic holds the counters for each service. websocket holds the connection count for each WebSocket route that has served a connection. active is the number of open connections, and max is the configured limit, or null when there is no limit.

Metrics per service:

MetricDescription
active_requestsNumber of requests currently in flight.
total_requestsCumulative requests handled for this service. A reload keeps the count when the service and its upstreams stay in the configuration.
total_successesRequests that resulted in a successful response (typically 2xx and 3xx).
total_failuresRequests that resulted in an error (4xx, 5xx, or connection failures).

POST /admin/reload​

Asks Snakeway to reload its configuration from disk. The response returns at once, before the reload runs.

curl -X POST http://localhost:8081/admin/reload

Example response:

{
"message": "reload requested",
"epoch": 3
}

The epoch number identifies this reload request. To learn how the reload finished, use GET /admin/reload.

This endpoint always returns 200 OK for a valid request. A reload that fails after the request returns is reported by GET /admin/reload as load_failed or build_failed. A change that needs a new process is reported as rejected or upgrade_started. Apart from the 401 Unauthorized described in Authentication, the only other response is 405 Method Not Allowed for a method other than GET or POST.

GET /admin/reload​

Shows how the last reload finished. If you reload from a deploy script, poll this endpoint until epoch is equal to or greater than the epoch that POST /admin/reload returned. Do not wait for an exact match, because a newer reload can finish before you poll.

After a zero-drop upgrade, POST /admin/reload returns upgrade_started with the epoch of that request. The new process starts its own reload sequence, so its GET /admin/reload reports epoch: 0 and result: none until its first reload. In that case, poll the new process's /admin/health or wait for it to begin serving instead of waiting for the epoch.

curl http://localhost:8081/admin/reload

Example response (applied):

{
"epoch": 3,
"result": "applied"
}

Example response (rejected):

{
"epoch": 4,
"result": "rejected",
"reason": "restart_required",
"settings": ["server.pid_file"]
}
resultMeaning
noneNo reload has finished since Snakeway started. epoch is 0.
appliedThe new configuration is in use.
upgrade_startedThe change needs a new process, and Snakeway started a zero-drop upgrade.
upgrade_failedSnakeway could not start the new process. error has the cause, and the running process keeps its configuration.
rejectedSnakeway did not apply the reload. See reason and settings, then restart Snakeway to apply the change.
load_failedThe configuration files could not be loaded or did not pass validation. error has the cause.
build_failedThe configuration loaded, but Snakeway could not build the new runtime state. error has the cause.

A rejected reload has one of two reasons. restart_required means that settings lists server.pid_file or server.upgrade.sock, which only a restart can change. upgrade_unsupported means that the change needs a zero-drop upgrade, and Snakeway cannot start one. That happens when Snakeway does not run on Linux, or when server.pid_file is not set.

GET /admin/certs​

Returns the current certificate inventory. Only available when TLS automation is configured. When no certificates are present (or TLS automation is not enabled), the response contains an empty list.

curl http://localhost:8081/admin/certs

Example response:

{
"certs": [
{
"id": "a1b2c3d4",
"domains": [
"example.com",
"api.example.com"
],
"issued_at": "2026-03-01T00:00:00Z",
"not_after": "2026-05-30T00:00:00Z",
"expires_in_seconds": 3542400,
"state": "Valid"
}
]
}

Fields per certificate:

FieldDescription
idInternal certificate identifier.
domainsDomain names covered by the certificate.
issued_atTimestamp when the certificate was issued.
not_afterCertificate expiration timestamp.
expires_in_secondsSeconds remaining until expiration.
state"Valid" or "Expired".

Circuit breaker transition logs​

When an upstream's circuit state changes, Snakeway emits a structured log event:

{
"timestamp": "2026-03-21T15:27:00.000Z",
"level": "INFO",
"fields": {
"event": "circuit_transition",
"service": "api",
"upstream": "UpstreamId(12345)",
"from": "closed",
"to": "open",
"reason": "failure_threshold_exceeded",
"failures": 5
}
}

Transition reasons:

  • failure_threshold_exceeded: Too many consecutive failures in Closed state triggered the circuit to open.
  • cooldown_expired: The configured open duration elapsed, transitioning from Open to HalfOpen.
  • half_open_failure: A failure during HalfOpen immediately re-opens the circuit.
  • success_threshold_reached: Enough successful probes in HalfOpen state closed the circuit.

Using the Admin API for monitoring​

The /admin/stats and /admin/upstreams endpoints are designed to be polled by monitoring systems. A simple monitoring script might look like this:

# Check that the process is running
curl -sf http://localhost:8081/admin/health || echo "Snakeway is not running"

# Fetch stats for a Prometheus exporter or custom dashboard
curl -s http://localhost:8081/admin/stats | jq .

# Inspect a specific service's upstream health
curl -s http://localhost:8081/admin/upstreams | jq '.services.api'

Stats counters are kept across a reload for every upstream that stays in the configuration. A counter resets when its upstream or service leaves the configuration, or when the process restarts. For long-term trend analysis, export the counters to an external time-series database at a regular polling interval.