Prometheus metrics exporter for Cloudflare Analytics
Prometheus metrics exporter for Cloudflare Analytics.
This piece of software has one mission: gather Cloudflare Site analytics from the Cloudflare API, and present them in Prometheus' Exposition format, for Prometheus to scrape.
- Tune your configuration. All configuration is done through environment variables:
CLOUDFLARE_EMAIL
: (optional) email used for Cloudflare API email authenticationCLOUDFLARE_KEY
: (optional) key used for Cloudflare API email authenticationCLOUDFLARE_TOKEN
: (optional) token used for Cloudflare API token authenticationCLOUDFLARE_USER_SERVICE_KEY
: (optional) key used for Cloudflare API user service key authenticationCLOUDFLARE_ZONES
: (required) comma-separated list of zone names to scrape for metrics (e.g.example.com,example.org
)CLOUDFLARE_SCRAPE_ANALYTICS_SINCE
: (default:24h
)since
parameter of calls to the Cloudflare Analytics APIEXPORTER_LISTEN_ADDR
: (default:127.0.0.1:9199
) address for the exporter to bind to
- Beware of rate limiting, Cloudflare's API has a base limit of 1200 requests every 5 minutes. I recommend configuring your Prometheis to scrape
cloudflare_exporter
once every 1-5 minutes.
Available on Docker Hub as docker.io/ricardbejarano/cloudflare_exporter
:
1.0
,latest
(Dockerfile) (about13.7MB
)
docker run -it -p 9199:9199 -e CLOUDFLARE_TOKEN="***" -e CLOUDFLARE_ZONES="example.com,example.org" docker.io/ricardbejarano/cloudflare_exporter
First clone the repository, and cd
into it:
cd exporter/
docker build -t cloudflare_exporter .
Now run it:
docker run -it -p 9199:9199 -e CLOUDFLARE_TOKEN="***" -e CLOUDFLARE_ZONES="example.com,example.org" cloudflare_exporter
First clone the repository, and cd
into it.
cd exporter/
make
Now run it:
export CLOUDFLARE_TOKEN="***" # WARNING: remember to erase this from your Bash history
export CLOUDFLARE_ZONES="example.com,example.org"
./exporter
Pro tip: during development, feel free to use make fast
to avoid unnecessary clean
+go get ...
when testing new code.
What are the differences with wehkamp/docker-prometheus-cloudflare-exporter?
cloudflare_exporter
scrapes metrics from the Analytics Dashboard API, available to all Cloudflare customers for freecloudflare_exporter
is not strictly tied to Docker (there's a Docker image, though, see Usage)cloudflare_exporter
is written in Go, instead of Python
What are the differences with criteo/cloudflare-exporter?
cloudflare_exporter
scrapes metrics from the Analytics Dashboard API, available to all Cloudflare customers for freecloudflare_exporter
is written in Go, instead of Python
Not at the moment, as I require an Enterprise account for development and I don't have one. Feel free to contribute that feature!
Does it support Cloudflare Web Analytics?
I finished writing cloudflare_exporter
exactly 1 day before Cloudflare announced their Web Analytics service is now available for free.
That said, I'd love to include support for that. Once the API and the Go API client library support it, I will integrate that into cloudflare_exporter
. Last I checked (Dec 9th, 2020) neither support Web Analytics yet.
I expect Cloudflare to update their official Go API client library to support the new Analytics GraphQL API before deprecation on March 1st, 2020. I also expect the Go API client library not to change its interface in the process, but I will fix whatever incompatibilities surge during the transition, if any.
At this stage, development for cloudflare_exporter
is paused with the following exceptions:
- Bugs in functionality (raise a GitHub Issue)
- Security vulnerabilities (raise a GitHub Issue asking for a GPG public key)
- Third-party contributions (make a pull request)
Basically, any usage analytics data that Cloudflare offers over their APIs, including:
- Cloudflare DNS analytics
- Cloudflare Web Analytics
- Cloudflare Argo analytics
- Cloudflare Site Analytics by colocation
- Cloudflare WAF analytics
- Cloudflare Workers KV analytics
- Cloudflare Spectrum analytics
For now, these are the features that have been decided not to be implemented, and the reasoning behind those decisions:
- Pseudo-metrics about site configuration, to monitor changes to Cloudflare Site configuration. Why? This feature is out of scope (aggregated, usage-derived analytics) for this project.
- Preventive rate limiting, to avoid Cloudflare-side rate limiting. Why? There's already one mechanism available to avoid getting rate limited at the Cloudflare level: increasing
scrape_interval
in Prometheus forcloudflare_exporter
.
See LICENSE for more details.