> ## Documentation Index
> Fetch the complete documentation index at: https://docs.squasher.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Cloudflare analytics metrics

> Pull Cloudflare zone traffic and Worker invocation metrics into Squasher every 5 minutes through your Cloudflare connection.

The Cloudflare connection can pull analytics for your zones and Workers every 5 minutes. Squasher
stores them as OpenTelemetry metrics, next to the Worker logs and traces from
[Cloudflare Workers](/integrations/cloudflare-logs).

The analytics pull is off by default. It is read-only.

## Prerequisites

* A Cloudflare [provider connection](/integrations/provider-connections) on the project.
* These permissions on the connection: **Account Analytics Read**, **Zone Read**, and **Zone
  Analytics Read**. A connection made before the analytics pull existed does not have them. Connect
  it again one time to grant them.

## Turn on the analytics pull

<Tabs>
  <Tab title="Dashboard">
    1. Open your project and select **Settings** in the sidebar, then the **Integrations** tab.
    2. On the **Cloudflare** card, turn on the analytics metrics.
  </Tab>

  <Tab title="CLI">
    ```bash theme={null}
    squasher integrations cloudflare-analytics --project "$SQUASHER_PROJECT_ID" --enable
    ```

    Use `--disable` to stop the pull.
  </Tab>

  <Tab title="API">
    ```bash theme={null}
    curl -X PUT "https://api.squasher.ai/v1/projects/$SQUASHER_PROJECT_ID/provider-connections/cloudflare/analytics" \
      -H "x-squasher-key: $SQUASHER_ADMIN_KEY" \
      -H "Content-Type: application/json" \
      -d '{"enabled": true}'
    ```

    The response gives `enabled` and the `required_permissions` of the pull.
  </Tab>
</Tabs>

## Metrics

Squasher reads the Cloudflare GraphQL Analytics API. Zone metrics are split by status class, cache
status, and data center. Worker metrics are split by Worker.

| Metric | What it counts |
| - | - |
| `cloudflare.zone.requests` | HTTP requests to the zone |
| `cloudflare.zone.bytes` | Bytes that the zone sent |
| `cloudflare.worker.requests` | Worker invocations |
| `cloudflare.worker.errors` | Worker invocations that ended with an error |
| `cloudflare.worker.subrequests` | Subrequests that Workers made |
| `cloudflare.worker.cpu_time` | Worker CPU time, at p50 and p99 in the `cloudflare.quantile` attribute |
| `cloudflare.worker.duration` | Worker wall time |

Each metric has these resource attributes:

| Attribute | Value |
| - | - |
| `cloud.provider` | `cloudflare` |
| `cloud.account.id` | The Cloudflare account ID |
| `faas.name` | The Worker name, on Worker metrics |
| `squasher.source` | `cloudflare.analytics` |

Query the metrics in **Metrics**, or see the zones and Workers with their key metrics under
**Infrastructure**, on the **Providers** tab.

## Check the pull

```bash theme={null}
squasher integrations health --project "$SQUASHER_PROJECT_ID"
squasher integrations resources --project "$SQUASHER_PROJECT_ID" --provider cloudflare
```

| What you see | What to do |
| - | - |
| Freshness is `paused` | The analytics pull is off. Turn it on. |
| Freshness is `stale` | No pull has succeeded for 20 minutes. Read the last error in `squasher integrations health`. |
| Error class `permission` or `auth` | The connection is missing the analytics permissions. Connect Cloudflare again to grant them. |

## Next steps

<CardGroup cols={2}>
  <Card title="Cloudflare Workers" icon="https://mintcdn.com/nextbigthingllc/e12gFqmgX0x4CiVm/icons/brands/cloudflare-workers.svg?fit=max&auto=format&n=e12gFqmgX0x4CiVm&q=85&s=873074586a8a0170b0e7ff09a3774b8c" href="/integrations/cloudflare-logs" width="24" height="24" data-path="icons/brands/cloudflare-workers.svg">
    Send Worker traces and logs to Squasher.
  </Card>

  <Card title="Provider connections" icon="https://mintcdn.com/nextbigthingllc/Fg5aclMlZNSrg_Y3/icons/entity/connection.svg?fit=max&auto=format&n=Fg5aclMlZNSrg_Y3&q=85&s=d0b3ee40d988fcded3129f8427d8e582" href="/integrations/provider-connections" width="24" height="24" data-path="icons/entity/connection.svg">
    Connect other providers and check their state.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.