Prometheus exporter for Cloudflare analytics (Free plan supported)
469
██████╗███████╗ ███████╗██╗ ██╗██████╗ ██████╗ ██████╗ ████████╗███████╗██████╗
██╔════╝██╔════╝ ██╔════╝╚██╗██╔╝██╔══██╗██╔═══██╗██╔══██╗╚══██╔══╝██╔════╝██╔══██╗
██║ █████╗ █████╗ ╚███╔╝ ██████╔╝██║ ██║██████╔╝ ██║ █████╗ ██████╔╝
██║ ██╔══╝ ██╔══╝ ██╔██╗ ██╔═══╝ ██║ ██║██╔══██╗ ██║ ██╔══╝ ██╔══██╗
╚██████╗██║ ███████╗██╔╝ ██╗██║ ╚██████╔╝██║ ██║ ██║ ███████╗██║ ██║
╚═════╝╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝
A Prometheus exporter for Cloudflare analytics that works with zones on the Free plan.
📈 Traffic per zone and per host, security events, edge certificates, tunnels and Zero Trust for every zone and account your token can see, Free plan included.
Popular Cloudflare exporters, such as
lablabs/cloudflare-exporter
and Cloudflare's own exporter, skip zones on the Free plan. They rely on
GraphQL datasets (for example httpRequests1mGroups or
firewallEventsAdaptiveGroups) that Free zones cannot query. Both are good
tools for paid plans. This exporter covers the case they leave out: it reads
the datasets that Free zones can query (httpRequests1hGroups,
httpRequestsAdaptiveGroups, firewallEventsAdaptive), asks Cloudflare which
fields each zone may use, and adds the richer ones when a zone's plan allows it.
| On a Free-plan zone | cloudflare-exporter | Exporters that skip Free zones |
|---|---|---|
| HTTP traffic (requests, bytes, cache, page views, visitors) | ✅ | ❌ zone skipped |
| Requests by HTTP status code | ✅ | ❌ zone skipped |
| Per-host requests by status class, near real time | ✅ | ❌ zone skipped |
| Edge certificate expiry | ✅ | varies |
| Security (firewall) events by action and source | ✅ | ❌ zone skipped |
| Cloudflare Tunnel health (status, connections, connectors) | ✅ | varies |
| Zero Trust: service token expiry, WARP devices, Gateway DNS, Access logins | ✅ | varies |
| Multi-arch image (amd64 + arm64) | ✅ | varies |
| Background collection (scrapes never call the API) | ✅ | varies |
httpRequests1hGroups, per-host traffic from httpRequestsAdaptiveGroups and security events from firewallEventsAdaptive, all readable by Free zonessettings node per zone (enabled datasets, page sizes, available fields) and uses firewallEventsAdaptiveGroups, origin status, bytes and origin response time automatically when the zone may query themCF_ZONES), minus exclusions (CF_EXCLUDE_ZONES)httpRequestsOverviewAdaptiveGroupsothercloudflared versions for Cloudflare Tunnels and WARP Connectors (available on every plan)SCRAPE_INTERVAL; /metrics serves the cache, so scrapes are instant and never spend API quotaother; status, HTTP version, action and source are small enumerationstruncated flag when that is not enoughup and last-success timestamps, API error counters, collection duration--help/healthz endpointIf you like this project, consider buying me a coffee ☕💛
docker run -d --name cloudflare-exporter \
-p 8080:8080 \
-e CF_API_TOKEN=your-read-only-token \
luisra51/cloudflare-exporter:latest
curl -s http://localhost:8080/metrics | grep '^cloudflare_'
services:
cloudflare-exporter:
image: luisra51/cloudflare-exporter:latest
restart: unless-stopped
ports:
- "8080:8080"
environment:
CF_API_TOKEN: ${CF_API_TOKEN}
# CF_ZONES: "<zone-id-1>,<zone-id-2>" # optional allowlist
SCRAPE_INTERVAL: 5m
LOG_FORMAT: json
go install github.com/luisra51/cloudflare-exporter/cmd/cloudflare-exporter@latest
CF_API_TOKEN=your-read-only-token cloudflare-exporter
Or from source:
git clone https://github.com/luisra51/cloudflare-exporter.git
cd cloudflare-exporter
task build && CF_API_TOKEN=your-read-only-token ./bin/cloudflare-exporter
A fake Cloudflare API with synthetic data is bundled:
task run:fake
# then open http://localhost:8080/metrics
The exporter only needs read access.
In the Cloudflare dashboard go to My Profile → API Tokens → Create Token.
Choose Create Custom Token.
Add these permissions, all set to Read:
| Scope | Permission | Used for |
|---|---|---|
| Zone | Zone | zone discovery and plan (/zones) |
| Zone | Analytics | HTTP traffic (httpRequests1hGroups) |
| Zone | Firewall Services | security events |
| Account | Account Analytics | account-wide traffic |
| Account | Account Settings | account name |
| Account | Cloudflare Tunnel | tunnel metrics (optional) |
| Zone | SSL and Certificates | edge certificate metrics (optional) |
| Account | Access: Service Tokens | service token expiry (optional) |
| Account | Zero Trust | WARP device counts (optional) |
Under Zone Resources and Account Resources, include only what you want to monitor.
Create the token and pass it as CF_API_TOKEN.
Without the account permissions, set CF_ACCOUNT_METRICS=false. The
Cloudflare Tunnel permission is only needed for tunnel metrics: without it the
exporter logs one warning, reports cloudflare_exporter_up{dataset="tunnels"} 0
and keeps collecting everything else (or set CF_TUNNEL_METRICS=false).
Every optional group works the same way: a missing permission produces one
warning naming it, cloudflare_exporter_up{dataset="..."} 0, and no effect on
the other metrics.
| Feature group | Flag | Permissions (all Read) | dataset in cloudflare_exporter_up |
|---|---|---|---|
| Per-host traffic | CF_HOST_METRICS | Zone → Analytics | httpRequestsAdaptiveGroups |
| Edge certificates | CF_CERT_METRICS | Zone → SSL and Certificates | certificate_packs |
| Tunnels | CF_TUNNEL_METRICS | Account → Cloudflare Tunnel | tunnels, tunnel_connectors |
| Service tokens | CF_ZEROTRUST_METRICS | Account → Access: Service Tokens | access_service_tokens |
| WARP devices | CF_ZEROTRUST_METRICS | Account → Zero Trust | devices |
| Gateway DNS | CF_ZEROTRUST_METRICS | Account → Account Analytics (Gateway in use) | gatewayResolverQueriesAdaptiveGroups |
| Access logins | CF_ZEROTRUST_METRICS | Account → Account Analytics (Access in use) | accessLoginRequestsAdaptiveGroups |
Every setting is an environment variable and a flag; flags win. Prefer the environment variable for the token, since flags are visible in the process list.
| Env var | Flag | Default | Description |
|---|---|---|---|
CF_API_TOKEN | --api-token | — (required) | Cloudflare API token |
CF_ZONES | --zones | all zones the token sees | Comma-separated zone IDs to collect |
CF_EXCLUDE_ZONES | --exclude-zones | — | Comma-separated zone IDs to skip |
CF_ACCOUNTS | --accounts | accounts of the discovered zones | Comma-separated account IDs; restricts zone discovery and selects accounts for account metrics |
LISTEN | --listen | :8080 | HTTP listen address |
METRICS_PATH | --metrics-path | /metrics | Metrics endpoint path |
SCRAPE_INTERVAL | --scrape-interval | 5m | How often to query Cloudflare in the background |
CF_HOURLY_DELAY | --hourly-delay | 10m | Wait this long after an hour ends before reporting it |
CF_TOP_COUNTRIES | --top-countries | 20 | Countries per zone; the rest are summed as country="other"; 0 disables country metrics |
CF_FIREWALL_EVENTS | --firewall-events | true | Collect security events |
CF_ACCOUNT_METRICS | --account-metrics | true | Collect account-level metrics |
CF_TUNNEL_METRICS | --tunnel-metrics | true | Collect Cloudflare Tunnel health metrics |
CF_HOST_METRICS | --host-metrics | true | Collect per-host traffic (httpRequestsAdaptiveGroups) |
CF_HOST_EXACT_STATUS | --host-exact-status | false | Also export per-host requests by exact status code |
CF_TOP_HOSTS | --top-hosts | 50 | Hosts per zone; the rest are summed as host="other"; 0 = no limit |
CF_ADAPTIVE_WINDOW | --adaptive-window | 5m | Length of the rolling window for near-real-time data |
CF_ADAPTIVE_DELAY | --adaptive-delay | 3m | How long ago the rolling window ends, to let data arrive |
CF_CERT_METRICS | --cert-metrics | true | Collect edge certificate pack metrics |
CF_ZEROTRUST_METRICS | --zerotrust-metrics | true | Collect Zero Trust metrics |
CF_DEVICES_INTERVAL | --devices-interval | 1h | How often to re-read the WARP device list (it can be large) |
CF_CONCURRENCY | --concurrency | 4 | Maximum concurrent Cloudflare API requests |
CF_HTTP_TIMEOUT | --http-timeout | 30s | Timeout per API request |
CF_API_URL | --api-url | https://api.cloudflare.com/client/v4 | API base URL (for testing) |
LOG_LEVEL | --log-level | info | debug, info, warn, error |
LOG_FORMAT | --log-format | text | text or json |
| — | --version | Print version and exit |
| Path | Description |
|---|---|
/metrics | Prometheus metrics (configurable with METRICS_PATH) |
/healthz | Liveness: always 200 with {"status":"ok","zone_discovery_succeeded":...,"last_collection":...} |
/ | Small landing page |
CF_HOURLY_DELAY (default 10m) after an hour ends so
Cloudflare can finish aggregating it. At 12:05 you see 10:00–11:00; from
12:10 you see 11:00–12:00.SCRAPE_INTERVAL, so late data is picked up.*_window_start_timestamp_seconds gauge with
the start of the hour it describes.cloudflare_exporter_up{dataset="..."} drops to 0. Zones that disappear
from discovery are removed.cloudflare_zone_hourly_firewall_events_truncated is 1 and the
count is a lower bound.CF_DEVICES_INTERVAL).CF_ADAPTIVE_WINDOW (default 5 minutes) ending CF_ADAPTIVE_DELAY
(default 3 minutes) ago, aligned to the minute, re-read every cycle. With
defaults at 12:10:30 you see 12:02–12:07. Divide by
cloudflare_zone_host_window_seconds for a per-second rate. Keep
SCRAPE_INTERVAL at or below the window to avoid gaps.CF_DEVICES_INTERVAL). Disable what you don't need if you have many zones.zone is the zone name and account the account name.
All with labels zone and account.
| Metric | Extra labels | Description |
|---|---|---|
cloudflare_zone_hourly_window_start_timestamp_seconds | Start of the hour the HTTP metrics describe | |
cloudflare_zone_hourly_requests | Requests | |
cloudflare_zone_hourly_cached_requests | Requests served from cache | |
cloudflare_zone_hourly_encrypted_requests | HTTPS requests | |
cloudflare_zone_hourly_bytes | Bytes sent to clients | |
cloudflare_zone_hourly_cached_bytes | Bytes served from cache | |
cloudflare_zone_hourly_encrypted_bytes | Bytes sent over HTTPS | |
cloudflare_zone_hourly_page_views | Page views | |
cloudflare_zone_hourly_threats | Requests classified as threats | |
cloudflare_zone_hourly_unique_visitors | Unique visitor IPs | |
cloudflare_zone_hourly_requests_by_status | status | Requests by edge response status |
cloudflare_zone_hourly_requests_by_http_version | http_version | Requests by client HTTP protocol |
cloudflare_zone_hourly_requests_by_country | country | Requests by client country (top N + other) |
cloudflare_zone_hourly_threats_by_country | country | Threats by client country |
cloudflare_zone_hourly_bytes_by_country | country | Bytes by client country |
All with labels zone and account.
| Metric | Extra labels | Description |
|---|---|---|
cloudflare_zone_hourly_firewall_window_start_timestamp_seconds | Start of the hour the security metrics describe | |
cloudflare_zone_hourly_firewall_events | action, source | Events by action (block, managed_challenge, log, ...) and source (firewallCustom, waf, securitylevel, ...) |
cloudflare_zone_hourly_firewall_events_truncated | dataset | 1 if the count hit the API row limit and is a lower bound |
| Metric | Labels | Description |
|---|---|---|
cloudflare_account_hourly_window_start_timestamp_seconds | account, account_id | Start of the hour |
cloudflare_account_hourly_requests | account, account_id | Requests across all zones |
cloudflare_account_hourly_cached_requests | account, account_id | Cached requests |
cloudflare_account_hourly_bytes | account, account_id | Bytes |
cloudflare_account_hourly_cached_bytes | account, account_id | Cached bytes |
Covers Cloudflare Tunnels (cfd_tunnel) and WARP Connectors
(warp_connector) that are not deleted, in the same accounts as the account
metrics. Read on every collection cycle from the REST API
(/accounts/{id}/tunnels and /accounts/{id}/{type}/{tunnel}/connections,
one call per tunnel; if that call fails, connections are taken from the
list response and arch is unknown). All with labels account and tunnel (the tunnel name).
The connector's public origin IP is never exported, by design.
| Metric | Extra labels | Description |
|---|---|---|
cloudflare_tunnel_info | account_id, tunnel_id, type, config_src | Always 1; type is cfd_tunnel or warp_connector, config_src is cloudflare, local or unknown |
cloudflare_tunnel_status | status | State set: 1 for the current status (healthy, degraded, down, inactive), 0 for the others |
cloudflare_tunnel_up | 1 if the status is healthy or degraded | |
cloudflare_tunnel_connections | Edge connections | |
cloudflare_tunnel_connections_pending_reconnect | Connections flagged as pending reconnect (Cloudflare has deprecated this flag; it may always be 0) | |
cloudflare_tunnel_connections_by_colo | colo | Edge connections by Cloudflare data center |
cloudflare_tunnel_connectors | Distinct connectors (cloudflared / WARP Connector instances) | |
cloudflare_tunnel_connector_info | connector_id, version, arch | Always 1, one per connector |
cloudflare_tunnel_active_since_timestamp_seconds | When the tunnel last became active (absent if never) | |
cloudflare_tunnel_inactive_since_timestamp_seconds | When the tunnel last became inactive (absent if Cloudflare reports none) |
httpRequestsAdaptiveGroups)All with labels zone and account. host is capped by CF_TOP_HOSTS,
the rest summed as host="other". Counts are sampled estimates.
| Metric | Extra labels | Description |
|---|---|---|
cloudflare_zone_host_window_start_timestamp_seconds | Start of the window | |
cloudflare_zone_host_window_seconds | Length of the window | |
cloudflare_zone_host_requests | host, status_class | Requests by edge status class (1xx…5xx, unknown) |
cloudflare_zone_host_requests_by_status | host, status | Requests by exact edge status (only with CF_HOST_EXACT_STATUS=true) |
cloudflare_zone_host_bytes | host | Bytes sent to clients (only if the zone may query edgeResponseBytes) |
cloudflare_zone_host_origin_5xx_requests | host | Requests whose origin answered 5xx (only if the zone may query originResponseStatus) |
cloudflare_zone_host_origin_requests | host | Requests that reached the origin, originResponseStatus > 0 (only if the zone may query originResponseStatus) |
cloudflare_zone_host_origin_response_time_seconds | host | Average origin response time over the requests that reached the origin, weighted by count; absent for a host with no origin requests in the window (only if the zone may query originResponseDurationMs and originResponseStatus) |
cloudflare_zone_host_truncated | 1 if the query hit the API row limit and counts are a lower bound |
The optional fields are requested only when the zone's settings node lists
them in availableFields; if Cloudflare still refuses, the query is retried
with the base fields.
Requests that never reach the origin (cache hits, edge redirects, clients that
close early) have originResponseStatus = 0 and Cloudflare reports their
average origin time as -1. They are left out of the origin metrics, so
cloudflare_zone_host_origin_response_time_seconds is the average over
cloudflare_zone_host_origin_requests only.
/zones/{id}/ssl/certificate_packs?status=all)| Metric | Labels | Description |
|---|---|---|
cloudflare_zone_certificate_packs | zone, account | Certificate packs of the zone (all statuses) |
cloudflare_zone_certificate_pack_info | zone, account, pack_id, type, status, certificate_authority | Always 1 |
cloudflare_zone_certificate_pack_active | zone, account, pack_id, type | 1 if the pack status is active |
cloudflare_zone_certificate_pack_expiry_timestamp_seconds | zone, account, pack_id, type, status | Earliest expiry among the pack's certificates (absent if none reported) |
Service tokens and devices are read from the REST API; Gateway DNS and Access logins from account-level GraphQL over the rolling window. No per-device data and no service token client IDs are exported.
| Metric | Labels | Description |
|---|---|---|
cloudflare_access_service_tokens | account | Access service tokens |
cloudflare_access_service_token_expiry_timestamp_seconds | account, name | Expiry of each token |
cloudflare_access_service_token_last_seen_timestamp_seconds | account, name | Last use, when Cloudflare reports it |
cloudflare_zerotrust_devices | account | WARP devices |
cloudflare_zerotrust_devices_by_last_seen | account, last_seen | Devices by time since last seen; exclusive buckets 24h, 7d, 30d, older, never |
cloudflare_zerotrust_devices_by_os | account, os | Devices by device_type (windows, mac, linux, android, ios, chromeos) |
cloudflare_zerotrust_window_start_timestamp_seconds | account | Start of the Gateway DNS / Access window |
cloudflare_zerotrust_window_seconds | account | Length of that window |
cloudflare_gateway_dns_queries | account, decision, decision_code | Gateway DNS queries by resolver decision (sampled estimate); decision is the documented name (blockedByCategory, allowedOnNoPolicyMatch, blockedRule, ...) or unknown |
cloudflare_access_logins | account, result | Access login attempts, success or failure (sampled estimate) |
| Metric | Labels | Description |
|---|---|---|
cloudflare_zone_info | zone, zone_id, account, account_id, plan, status | Always 1; plan is free, pro, business, enterprise, ... |
cloudflare_exporter_up | scope, target, dataset | 1 if the last attempt succeeded; scope is zone, account or exporter; dataset is zones, settings, httpRequests1hGroups, firewallEvents, httpRequestsOverviewAdaptiveGroups, tunnels, tunnel_connectors, httpRequestsAdaptiveGroups, certificate_packs, access_service_tokens, devices, gatewayResolverQueriesAdaptiveGroups or accessLoginRequestsAdaptiveGroups |
cloudflare_exporter_last_success_timestamp_seconds | scope, target, dataset | Time of the last success |
cloudflare_exporter_api_errors_total | api, operation | Failed API calls (api = rest or graphql) |
cloudflare_exporter_collections_total | result | Collection cycles: success, partial, failure |
cloudflare_exporter_collection_duration_seconds | Duration of the last cycle | |
cloudflare_exporter_last_collection_timestamp_seconds | When the last cycle finished | |
cloudflare_exporter_zones | Zones being collected | |
cloudflare_exporter_build_info | version, revision, goversion | Always 1 |
Standard go_* and process_* metrics are exported too.
Sample output:
cloudflare_zone_info{accoun
Content type
Image
Digest
sha256:e84085509…
Size
5 MB
Last updated
19 days ago
docker pull luisra51/cloudflare-exporter