Sign inSign up

neverlless/cloudflare-prometheus-exporter

By neverlless

•Updated over 2 years ago

This is a Prometheus exporter for Cloudflare's API.

Image
0

490

neverlless/cloudflare-prometheus-exporter repository overview

This is a Prometheus exporter for Cloudflare's API. It uses the GraphQL API to fetch data from your account and expose it in a format that Prometheus can scrape.

⁠Features from basic exporter

  • Modified the code structure.
  • Removed cli⁠ dependency.
  • Moved the collector to an specific file.
  • You can choose the listening port using -prom-port.
  • Now you can add multiple datasets like waf, http, workers, net or dns.
  • If you have several zones but you only want to extract data from one of them you can use -zone to specify the name of the zone.
  • The metrics are refreshed when the get request is received by prometheus exporter and not a fixed time, following the guidelines by Prometheus⁠
  • Modified "http" dataset to return more metrics
  • Added "waf" dataset
  • Added "workers" dataset
  • Added "dns" dataset

⁠Supported metrics

  • HTTP

    • Bytes (zoneName)

    • Request (zoneName)

    • CachedBytes (zoneName)

    • CachedRequest (zoneName)

    • EncryptedBytes (zoneName)

    • EncryptedRequests (zoneName)

    • Bytes (contentType, zoneName)

    • Request (contentType, zoneName)

    • Bytes (country, zoneName)

    • Request (country, zoneName)

    • Threats (country, zoneName)

    • Bytes (cacheStatus, contentType, method, zoneName)

    • Requests (sslVersion, zoneName)

    • Requests (HTTPVersion, zoneName)

    • Requests (responseCode, zoneName)

  • WAF

    • Events (action, asName, country, ruleID, zoneName)
  • Workers

    • CPUTime
    • Errors
    • Requests
    • SubRequests
  • DNS / DNS Firewall

    • Total Requests
    • Cached Requests
    • Staled Requests
    • Requests time (median,average, 90th percentile, 99th percentile)
  • Network

    • Bits (attackID)
    • Packets (attackID)

⁠Usage

cloudflare_exporter -h
Usage of ./cloudflare_exporter:
  -account string
       Account ID to be fetched
  -dataset string
       The data source you want to export, valid values are: http, net, dns, workers, waf (default "http,waf")
  -email string
       The email address associated with your Cloudflare API token and account
  -key string
       Your Cloudflare API token
  -prom-port string
       Prometheus Addr (default "0.0.0.0:2112")
  -zone string
       Zone Name to be fetched

You can also use the following env variables instead of cli arguments:

  • CF_KEY : Your Cloudflare API token
  • CF_EMAIL : The email address associated with your Cloudflare API token and account
  • CF_ACCOUNT : Account ID to be fetched
  • CF_ZONE : Zone Name to be fetched
  • CF_DATASET : The data source you want to export, valid values are: http, net, waf, workers, vnds, dns
  • CF_PROM_PORT : Prometheus listening address

Once launched with valid credentials, the binary will spin a webserver on http://localhost:2112/metrics⁠ exposing the metrics received from Cloudflare's GraphQL endpoint.

Repository: https://github.com/neverlless/cloudflare_exporter⁠

Tag summary

Content type

Image

Digest

sha256:4285c8630…

Size

7 MB

Last updated

over 2 years ago

docker pull neverlless/cloudflare-prometheus-exporter