Skip to content

CubeProxy Request Metrics ​

CubeProxy exposes Prometheus-formatted request metrics for selected sandbox data-plane routes. These metrics help operators observe request traffic, in-flight requests, success and failure rates, and request latency while diagnosing routing or backend problems.

The metrics endpoint is served by a dedicated CubeProxy listener:

text
http://127.0.0.1:18082/metrics

CubeProxy stores the metrics in an in-memory Nginx shared dictionary. A CubeProxy restart resets the counters, gauges, and histogram samples.

Enabling and disabling metrics ​

Request metrics are opt-in and disabled by default. To turn the feature on, set the CUBE_PROXY_METRICS_ENABLE environment variable to a truthy value (1, on, true, or yes):

text
CUBE_PROXY_METRICS_ENABLE=1

Any other value, an empty value, or leaving the variable unset keeps metrics disabled. When disabled, CubeProxy records no request samples, the data-plane request phases skip metrics collection entirely, and no metrics listener is created — nothing binds any port — so the CUBE_PROXY_METRICS_LISTEN value is ignored in that case.

Deployment ​

Each deployment path exposes the toggle as a configuration knob (all default to off):

  • one-click (docker compose): set CUBE_PROXY_METRICS_ENABLE=1 (and optionally CUBE_PROXY_METRICS_LISTEN) in your .env before running the installer.
  • Helm chart: set cubeProxy.metrics.enabled=true (and optionally cubeProxy.metrics.listen) in your values.
  • Terraform (TKE): set cube_proxy_metrics_enabled = true (and optionally cube_proxy_metrics_listen) in your tfvars.

Metrics listener ​

The metrics listener is configured with the CUBE_PROXY_METRICS_LISTEN environment variable. Its default value is:

text
127.0.0.1:18082

For Prometheus to scrape CubeProxy from another host, configure the listener with an address reachable from the Prometheus network. For example:

text
CUBE_PROXY_METRICS_LISTEN=0.0.0.0:18082

The metrics listener exposes only the exact GET /metrics endpoint. Other paths return HTTP 404. The endpoint does not use CubeProxy's normal data-plane routes or admin server.

Network access

The metrics listener does not provide built-in authentication or TLS. Do not expose it to an untrusted network. Bind it to a trusted management address and restrict access with firewall or security-group rules.

Prometheus scrape configuration ​

The endpoint can be scraped with a manual Prometheus job:

yaml
scrape_configs:
  - job_name: cubesandbox-cube-proxy
    metrics_path: /metrics
    scrape_interval: 30s
    scrape_timeout: 10s
    static_configs:
      - targets:
          - <cube-proxy-host>:18082

Replace the target with the internal CubeProxy address that is reachable from Prometheus. If CubeProxy keeps the default listener 127.0.0.1:18082, Prometheus must run on the same host or use a local scrape agent.

Metric families ​

cube_proxy_request_total ​

A Counter containing the number of completed tracked requests.

Labels:

  • route — the normalized CubeProxy route.
  • method — GET or POST.
  • result — success or fail.

A response with an HTTP status from 200 through 399 is recorded as success. Other status codes are recorded as fail.

result reflects the outcome as seen by CubeProxy, based on the HTTP status only. It does not reflect whether a call eventually succeeded inside the sandbox:

  • process.Process/Start and Connect are streaming calls. CubeProxy receives HTTP 200 as soon as the stream opens, so an error the sandbox reports later inside the stream is still recorded as success.
  • A user command that exits with a non-zero code is recorded as success, because the call itself completed normally.

cube_proxy_inflight_requests ​

A Gauge containing the number of currently tracked requests that have started but have not yet been completed.

Labels:

  • route — the normalized CubeProxy route.

cube_proxy_upstream_response_seconds ​

A Histogram of how long the sandbox takes to start responding, in seconds: the time from CubeProxy forwarding a request to the sandbox until it receives the sandbox's response headers. Prometheus exposes the usual histogram samples:

text
cube_proxy_upstream_response_seconds_bucket{...}
cube_proxy_upstream_response_seconds_sum{...}
cube_proxy_upstream_response_seconds_count{...}

The histogram measures service latency rather than total request time, so it is not affected by how long a user's command runs or how large a file is:

  • For process.Process/Start and Connect, it covers routing and starting or attaching to the process, not the command's runtime.
  • For file downloads, it covers the time until the sandbox starts sending the file, not the transfer itself.
  • For file uploads, CubeProxy receives the whole request body before forwarding it, so the client's upload time is excluded. The time to send the body to the sandbox and for the sandbox to write it is included.

Requests that never reach a sandbox, such as errors CubeProxy returns itself, are counted in cube_proxy_request_total but are not recorded in this histogram.

The histogram uses the route, method, and result labels. The current buckets range from 0.001 seconds through 8.192 seconds, plus +Inf.

Current collection scope ​

The current implementation records only these normalized routes:

RouteURI formsTypical use
sandbox_exec/process.Process/* and /sandbox/<sandbox-id>/<container-port>/process.Process/*Sandbox process execution and connection requests.
sandbox_files/files and /sandbox/<sandbox-id>/<container-port>/filesSandbox file requests.

Other URIs are not included in these metrics. The route label is intentionally normalized so sandbox IDs and container ports do not create a separate time series for every sandbox.

Request lifecycle ​

CubeProxy starts tracking a request during its rewrite phase. It increments the route's in-flight gauge and stores the normalized route in the request variables.

At request completion, CubeProxy reads the method, the final status, and the time until the sandbox started responding, then updates the counter and histogram and decrements the in-flight gauge.

The following applies only to the tracked sandbox_exec and sandbox_files routes.

Counted requests: every request whose target sandbox CubeProxy can identify is counted. This includes errors CubeProxy returns directly because the sandbox does not exist, is forbidden, has been deleted, or is temporarily unavailable (404, 403, 410, 503), and the 503 returned when no backend is available. Each request is counted once.

Requests that are not counted: if the target sandbox cannot be identified from the request (neither the Host header nor the E2b-Sandbox-* headers carry routing attributes, or the /sandbox/<sandbox-id>/<container-port> path is malformed), CubeProxy returns HTTP 400 directly. These client errors are not counted.

Verify the endpoint ​

From a host that can reach the listener, query the endpoint:

bash
curl -fsS http://127.0.0.1:18082/metrics

A newly started CubeProxy may expose only HELP and TYPE metadata or no request samples. Complete a tracked sandbox execution or file request before checking the corresponding counter and histogram samples.

PromQL examples ​

Tracked request rate ​

promql
sum by (route, method, result) (
  rate(cube_proxy_request_total[5m])
)

Failed request rate ​

promql
sum by (route, method) (
  rate(cube_proxy_request_total{result="fail"}[5m])
)

Current in-flight requests ​

promql
sum by (route) (
  cube_proxy_inflight_requests
)

P95 sandbox response latency ​

promql
histogram_quantile(
  0.95,
  sum by (le, route, method) (
    rate(cube_proxy_upstream_response_seconds_bucket[5m])
  )
)

Troubleshooting ​

SymptomWhat to check
curl cannot connectConfirm CubeProxy is running, check CUBE_PROXY_METRICS_LISTEN, and verify that the listener address and firewall rules allow the request.
Prometheus cannot reach the endpointThe default listener is loopback-only. Set CUBE_PROXY_METRICS_LISTEN to an internal address reachable from Prometheus and restart CubeProxy.
HTTP 404 from the metrics listenerUse the exact path /metrics. Other paths on the dedicated metrics listener intentionally return 404.
HTTP 200 but no request samplesComplete a tracked sandbox_exec or sandbox_files request and scrape again. Metadata may be present before the first sample.
Expected route is missingOnly the normalized sandbox_exec and sandbox_files routes are currently tracked. Other CubeProxy routes are outside the current collection scope.
Counters reset after restartMetrics are stored in memory. A CubeProxy restart creates a new shared dictionary, so Prometheus should treat the values as normal counter and gauge resets.
Prometheus reports authentication errorsThe metrics listener has no built-in authentication. Check the surrounding firewall, security group, proxy, or network policy configuration.