# Cloudflare Prometheus Exporter

## Get Cloudflare dashboard in 3 minutes

Visualize requests, errors, durations, workers, caching, and more in Better Stack using the [Cloudflare Prometheus Exporter](https://github.com/cloudflare/cloudflare-prometheus-exporter).

### Get Cloudflare metrics

Create an exporter Worker, set up a token and secrets.

#### 1. Deploy exporter

Deploy the exporter to Cloudflare: 
**[One-click deploy to Cloudflare](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/cloudflare-prometheus-exporter)**

#### 2. Create Cloudflare token

Create a Cloudflare token with the necessary permissions: 
[One-click create token with pre-filled permissions](https://dash.cloudflare.com/profile/api-tokens?permissionGroupKeys=%5B%7B%22key%22%3A%22analytics%22%2C%22type%22%3A%22read%22%7D%2C%7B%22key%22%3A%22account_analytics%22%2C%22type%22%3A%22read%22%7D%2C%7B%22key%22%3A%22workers_scripts%22%2C%22type%22%3A%22read%22%7D%2C%7B%22key%22%3A%22ssl_and_certificates%22%2C%22type%22%3A%22read%22%7D%2C%7B%22key%22%3A%22firewall_services%22%2C%22type%22%3A%22read%22%7D%2C%7B%22key%22%3A%22load_balancers%22%2C%22type%22%3A%22read%22%7D%2C%7B%22key%22%3A%22account_logs%22%2C%22type%22%3A%22read%22%7D%2C%7B%22key%22%3A%22magic_transit%22%2C%22type%22%3A%22read%22%7D%5D&name=Cloudflare%20Prometheus%20Exporter)

You should see the permissions as listed below. Create the token and copy its value for later.

![Cloudflare API token permissions](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/7bb8df17-69e2-48fa-50ec-bce4eea68500/lg2x =2094x1358)

#### 3. Add Worker secrets

Navigate to your Worker in Cloudflare -> **Settings**. 

Enter the API token and basic auth under **Variables and Secrets**:

- Add the `CLOUDFLARE_API_TOKEN` secret and paste in the created token value.
- Add `BASIC_AUTH_USER` and `BASIC_AUTH_PASSWORD` secrets with credentials of your choice.

![Add Cloudflare secrets](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/5930e762-2199-4a1a-00eb-3a5550503200/lg2x =1608x797)

### Finish the setup in Better Stack

Create a source, add the Worker URL and HTTP authentication.

#### 1. Create source

[Create source](https://telemetry.betterstack.com/team/0/sources/new?platform=prometheus_scrape&name=Cloudflare ";_blank") of type **Prometheus scrape** in Better Stack.

#### 2. Add Worker URL

Fill in **URLs to scrape**. Use the Worker URL followed by `/metrics`:

```
[label Example URL]
https://cloudflare-prometheus-exporter.your-domain.workers.dev/metrics
```

#### 3. Use HTTP authentication

Navigate to **Advanced settings** and enter the **HTTP authentication** credentials. Use the `BASIC_AUTH_USER` and `BASIC_AUTH_PASSWORD` secret values.

![Fill in basic auth in Better Stack](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/e069e5b8-3885-4aa7-6161-3f7d68a53b00/md1x =2364x1004)

### Visit the dashboard

Check out your Cloudflare data and analytics in a pre-made [Cloudflare Prometheus Exporter dashboard](https://telemetry.betterstack.com/team/0/dashboards/go/cloudflare-prometheus-exporter ";_blank").


## Need help?

Please let us know at hello@betterstack.com.  
We're happy to help! 🙏

