---
sidebar_label: HTTP metrics
toc_max_heading_level: 3
doc_id: 41fd847f-a610-4ddf-acfc-9ba796c48a84
description: >-
  How Containers scopes record HTTP metrics, and how to get them from the Istio
  gateway when your scopes use Istio.
keywords:
  - containers
  - kubernetes
  - http metrics
  - istio
  - telemetry
  - access logs
  - TRAFFIC_PROXY
  - traffic manager
  - logs-controller
title: HTTP metrics
canonical: 'https://docs.nullplatform.com/docs/agent-backed-scopes/containers/http-metrics'
---
# HTTP metrics

Every Containers scope records HTTP metrics (requests per minute, response time, error rate, and healthchecks) so you can see how it performs. Nullplatform publishes them to the provider you use, like Prometheus or Datadog.

## How metrics are recorded

By default, every application pod runs an nginx container next to your application, called the traffic manager. It receives the scope's HTTP traffic and records each request. The logs-controller DaemonSet then publishes those metrics to your provider.

This works with any ingress, which is why it's the default.

## Get metrics from Istio

If your scopes are exposed through the Istio gateway, Istio already sees every request. Turn on the gateway's telemetry, and the scope's metrics come straight from Istio:

- **Smaller pods**: each pod runs only your application, so it uses less CPU and memory
- **Same metrics**: same names, labels, and providers, with no metrics lost
- **No extra infrastructure**: the logs-controller you already run reads the gateway logs

You choose per scope. Scopes that use Istio metrics and scopes that use the traffic manager run side by side in the same cluster, and requests are never counted twice.

### What changes with Istio metrics

Without the traffic manager, a few things are measured or handled at the gateway:

- **Response time**: measured at the gateway, so it includes the hop from the gateway to the pod
- **Response size**: the size the gateway sends, without nginx gzip compression
- **Healthcheck metrics**: generated from the pod's readiness status, with a response time of 0 ms
- **Proxy limits**: body size and timeouts are the gateway's

## When the traffic manager is required

Istio metrics need the scope's traffic to go through the Istio gateway. Otherwise, the traffic manager is required, and a deployment set to use Istio fails with an explanatory error:

| Case | Why |
|---|---|
| Scopes exposed through a load balancer Ingress, like ALB | Traffic reaches the pods directly, without going through Istio |
| Scopes on ARO clusters (`GATEWAY_TYPE=aro_cluster`) | Traffic goes through OpenShift Routes, not the Istio gateway |
| Scopes with [`TRAFFIC_MANAGER_CONFIG_MAP`](/docs/tutorials/nginx-traffic-config) set | The ConfigMap customizes the traffic manager |

## Turn on Istio metrics

Follow these steps to turn on the Istio gateway telemetry and get a Containers scope's HTTP metrics from it.

### Prerequisites

- Scopes exposed through the Istio gateway (HTTPRoute ingress)
- `nullplatform-base` chart 2.45.0 or later
- `k8s-logs-controller` 1.8.0 or later
- Containers scope (`nullplatform/scopes`) 1.21.0 or later
- An agent whose `np` CLI is version 2.6 or later
- `kubectl` access to the cluster

### 1. Protect the namespaces

Skip this step if your `nullplatform-base` chart is 2.43.1 or later. Older charts create the `gateways` namespace, and sometimes `nullplatform` and `nullplatform-tools`, without a keep policy. The next upgrade deletes them with everything inside, like the gateways, the load balancer, and the certificates, and these steps upgrade the chart.

List the namespaces the release created:

```bash
helm -n nullplatform-tools get manifest nullplatform-base | grep -A3 'kind: Namespace' | grep 'name:'
```

Then annotate each one so the upgrade keeps it:

```bash
kubectl annotate namespace <namespace> helm.sh/resource-policy=keep --overwrite
```

If the `gateways` namespace was already deleted, see [Recover a deleted gateways namespace](#recover-a-deleted-gateways-namespace).

### 2. Turn on the gateway access logs

Two pieces need it: istiod must know the `np-gateway-access-log` provider, which defines the access log format, and the logs-controller must read the gateway logs.

:::note
The versions below are the minimum that support Istio metrics. If you already run a later one, keep yours. Replace `<istio-version>` with the Istio version installed in your cluster.
:::

**istio-metrics-tofu**

Set these variables and apply:

```hcl
module "istio" {
  source = "git::https://github.com/nullplatform/tofu-modules.git//infrastructure/commons/istio?ref=v9.19.0"
  # ...
  gateway_access_log_enabled = true
}

module "base" {
  source = "git::https://github.com/nullplatform/tofu-modules.git//nullplatform/base?ref=v9.19.0"
  # ...
  nullplatform_base_helm_version    = "2.45.0"
  logging_controller_image_tag      = "v1.8.0"
  logging_istio_access_logs_enabled = true
}
```

**istio-metrics-helm**

1. Export the current istiod values:

   ```bash
   helm get values istiod -n istio-system -o yaml > istiod-values.yaml
   ```

2. Append the provider to `meshConfig.extensionProviders` in `istiod-values.yaml`. It's a list, so keep the providers you already have:

   ```yaml
   meshConfig:
     extensionProviders:
       # ...your existing providers
       - name: np-gateway-access-log
         envoyFileAccessLog:
           path: /dev/stdout
           logFormat:
             labels:
               start_time: "%START_TIME%"
               method: "%REQ(:METHOD)%"
               path: "%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%"
               protocol: "%PROTOCOL%"
               code: "%RESPONSE_CODE%"
               response_flags: "%RESPONSE_FLAGS%"
               response_code_details: "%RESPONSE_CODE_DETAILS%"
               connection_termination_details: "%CONNECTION_TERMINATION_DETAILS%"
               upstream_transport_failure_reason: "%UPSTREAM_TRANSPORT_FAILURE_REASON%"
               bytes_received: "%BYTES_RECEIVED%"
               size: "%BYTES_SENT%"
               response_time: "%DURATION%"
               upstream_service_time: "%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%"
               x_forwarded_for: "%REQ(X-FORWARDED-FOR)%"
               agent: "%REQ(USER-AGENT)%"
               request_id: "%REQ(X-REQUEST-ID)%"
               authority: "%REQ(:AUTHORITY)%"
               upstream_host: "%UPSTREAM_HOST%"
               upstream_cluster: "%UPSTREAM_CLUSTER_RAW%"
               upstream_local_address: "%UPSTREAM_LOCAL_ADDRESS%"
               downstream_local_address: "%DOWNSTREAM_LOCAL_ADDRESS%"
               remote: "%DOWNSTREAM_REMOTE_ADDRESS%"
               requested_server_name: "%REQUESTED_SERVER_NAME%"
               route_name: "%ROUTE_NAME%"
   ```

3. Upgrade istiod with those values:

   ```bash
   helm upgrade istiod istio/istiod -n istio-system --version <istio-version> -f istiod-values.yaml
   ```

4. Turn on the gateway access logs in the `nullplatform-base` release, with the logs-controller version that reads them:

   ```bash
   helm upgrade nullplatform-base nullplatform/nullplatform-base -n nullplatform-tools \
     --version 2.45.0 --reuse-values \
     --set logging.controller.image=public.ecr.aws/nullplatform/k8s-logs-controller:v1.8.0 \
     --set logging.istioAccessLogs.enabled=true
   ```

### 3. Check the cluster

Confirm that each gateway has a Telemetry and that the logs-controller reads the gateway logs:

```bash
# One Telemetry per gateway
kubectl get telemetry -n gateways

# The logs-controller reads the gateway logs
kubectl -n nullplatform-tools get ds nullplatform-log-controller \
  -o jsonpath='{.spec.template.spec.containers[0].env[?(@.name=="ISTIO_ACCESS_LOGS_ENABLED")].value}'
```

You should see `np-gateway-access-log-gateway-public` (and `np-gateway-access-log-gateway-private` if you have a private gateway), and `true`.

### 4. Set the scope to use Istio metrics

Create a [scope configuration](/docs/agent-backed-scopes/scope-configurations) for the scope, or for the namespace, account, or organization that contains it:

```json
{
  "deployment": {
    "traffic_proxy": "istio"
  }
}
```

If the scope configuration form doesn't show a `traffic_proxy` setting, [add it to the specification](/docs/agent-backed-scopes/scope-configurations#add-a-setting-to-the-form) first.

To make Istio metrics the default for every scope an agent handles, set the `TRAFFIC_PROXY=istio` environment variable on the agent instead. A scope configuration takes precedence over it.

### 5. Deploy the scope

Start a new deployment. The change goes out with the scope's regular deployment strategy.

### 6. Check the scope

Confirm that the new pods run without the traffic manager. Replace `<namespace>` with the scope's Kubernetes namespace, which is `nullplatform` by default:

```bash
kubectl get pods -n <namespace> -l scope_id=<scope-id> \
  -o custom-columns=NAME:.metadata.name,CONTAINERS:.spec.containers[*].name,PROXY:.metadata.labels.traffic_proxy
```

Each pod runs only the `application` container and has the `traffic_proxy=istio` label. Send traffic to the scope and check its metrics in the scope's **Performance** tab.

## Roll back

Set `traffic_proxy` to `nginx` and deploy again. The scope goes back to recording metrics with the traffic manager.

## Recover a deleted gateways namespace

1. Recreate the namespace and gateways:

   ```bash
   helm -n nullplatform-tools upgrade nullplatform-base nullplatform/nullplatform-base --version <current-version> --reuse-values
   ```

2. Recreate the certificates:

   ```bash
   helm -n cert-manager upgrade cert-manager-config nullplatform/nullplatform-cert-manager-config --version <current-version> --reuse-values
   ```

3. The load balancer comes back with a new hostname. Point the scopes' `DNSEndpoint` objects (`kubectl get dnsendpoint -A`) at the new gateway address. Scope domains don't respond until you do.

   ```bash
   kubectl get gateway gateway-public -n gateways -o jsonpath='{.status.addresses[0].value}'
   ```

## Next steps

- [Scope configurations](/docs/agent-backed-scopes/scope-configurations): set `traffic_proxy` per organization, account, namespace, or scope
- [Configurable HTTP ports](/docs/agent-backed-scopes/containers/configurable-http-ports): main and additional HTTP ports of a Containers scope
- [Scopes: logs and metrics](/docs/telemetry/scopes-logs-and-metrics): configure a custom telemetry provider for scopes
