lablabs / cloudflare-exporter

Prometheus CloudFlare Exporter
Apache License 2.0
316 stars 104 forks source link

Add metrics for workers. #21

Closed pvdvreede closed 3 years ago

pvdvreede commented 3 years ago

This actions issue #17 .

The functionality is there and will introspect the accounts the CF TOKEN has access to and then get worker metrics from there.

Not sure if this is the wanted behaviour as the token will need extra permissions (which i will update the readme with once things are looking good :) ).

Should I add a CF_ACCOUNTS env var to limit accounts to check? If the var does not exists it will not get any worker metrics, so its backward compatible?

martinhaus commented 3 years ago

@pvdvreede thanks for the PR. We don't have CF workers in our setup so it's hard for me to actually test this out. I don't get any errors when running the code from your PR on my accounts with them having no workers. I assume it's compatible for users which don't use this functionality so I'm going to merge this. The code looks good. Thanks for the PR again!

martinhaus commented 3 years ago

@pvdvreede Oh, and more thing. Could you update the readme to reflect the changes you've made. Especially the list of metrics.

pvdvreede commented 3 years ago

yep, will update things, clean it up and rebase soon, thanks!

nouvellonsteph commented 3 years ago

Hey @pvdvreede!

Thanks for your contribution. I was indeed able to fetch the correct data from the several accounts I'm having attached to the token I did use to test this one. The result is the following:

# TYPE cloudflare_worker_errors_count counter
cloudflare_worker_errors_count{script_name="6hourfailure"} 0
cloudflare_worker_errors_count{script_name="billowing-truth-a2bd"} 0
cloudflare_worker_errors_count{script_name="blue-scene-f745"} 0
cloudflare_worker_errors_count{script_name="calm-frost-b418"} 0
cloudflare_worker_errors_count{script_name="cf-china-icp"} 0
cloudflare_worker_errors_count{script_name="cpu-time-oscillator"} 0
cloudflare_worker_errors_count{script_name="dawn-poetry-0f9b"} 0
cloudflare_worker_errors_count{script_name="elastic-helper"} 0
cloudflare_worker_errors_count{script_name="falling-limit-3dcb"} 0
cloudflare_worker_errors_count{script_name="jolly-mud-42d0"} 0
cloudflare_worker_errors_count{script_name="muddy-forest-9137"} 0
cloudflare_worker_errors_count{script_name="patient-heart-c7fc"} 0
cloudflare_worker_errors_count{script_name="patient-thunder-bbd7"} 0
cloudflare_worker_errors_count{script_name="patient-unit-e919"} 0
cloudflare_worker_errors_count{script_name="random-failing-check"} 0
cloudflare_worker_errors_count{script_name="raspy-brook-2546"} 0
cloudflare_worker_errors_count{script_name="restless-cherry-2be0"} 0
cloudflare_worker_errors_count{script_name="royal-glitter-793b"} 0
cloudflare_worker_errors_count{script_name="sgw_v7-317-g2e64e86"} 0
cloudflare_worker_errors_count{script_name="slow-response"} 0
cloudflare_worker_errors_count{script_name="sparkling-sky-4207"} 0
cloudflare_worker_errors_count{script_name="sweet-wildflower-6fe5"} 0
cloudflare_worker_errors_count{script_name="sweet-wind-e828"} 0
cloudflare_worker_errors_count{script_name="test-data-egress"} 0
cloudflare_worker_errors_count{script_name="young-resonance-a7e4"} 0
# HELP cloudflare_worker_requests_count Number of requests sent to worker by script name
# TYPE cloudflare_worker_requests_count counter
cloudflare_worker_requests_count{script_name="6hourfailure"} 6199
cloudflare_worker_requests_count{script_name="billowing-truth-a2bd"} 4
cloudflare_worker_requests_count{script_name="blue-scene-f745"} 4
cloudflare_worker_requests_count{script_name="calm-frost-b418"} 4
cloudflare_worker_requests_count{script_name="cf-china-icp"} 1
cloudflare_worker_requests_count{script_name="cpu-time-oscillator"} 1
cloudflare_worker_requests_count{script_name="dawn-poetry-0f9b"} 156
cloudflare_worker_requests_count{script_name="elastic-helper"} 8
cloudflare_worker_requests_count{script_name="falling-limit-3dcb"} 4
cloudflare_worker_requests_count{script_name="jolly-mud-42d0"} 4
cloudflare_worker_requests_count{script_name="muddy-forest-9137"} 4
cloudflare_worker_requests_count{script_name="patient-heart-c7fc"} 4
cloudflare_worker_requests_count{script_name="patient-thunder-bbd7"} 4
cloudflare_worker_requests_count{script_name="patient-unit-e919"} 6
cloudflare_worker_requests_count{script_name="random-failing-check"} 24
cloudflare_worker_requests_count{script_name="raspy-brook-2546"} 4
cloudflare_worker_requests_count{script_name="restless-cherry-2be0"} 6
cloudflare_worker_requests_count{script_name="royal-glitter-793b"} 4
cloudflare_worker_requests_count{script_name="sgw_v7-317-g2e64e86"} 1321
cloudflare_worker_requests_count{script_name="slow-response"} 24
cloudflare_worker_requests_count{script_name="sparkling-sky-4207"} 4
cloudflare_worker_requests_count{script_name="sweet-wildflower-6fe5"} 4
cloudflare_worker_requests_count{script_name="sweet-wind-e828"} 4
cloudflare_worker_requests_count{script_name="test-data-egress"} 4
cloudflare_worker_requests_count{script_name="young-resonance-a7e4"} 4

As @martinhaus mentioned, it would be nice to update the readme by adding the new counters you've added.

Good job!

m0ar commented 3 years ago

Beat me to it @pvdvreede ! This is super useful :cupcake:

I just tested to build and run this container, but I see nothing related to workers in localhost:8080/metrics and the docker log repeats this line:

time="2021-09-03 14:38:26" level=error msg="graphql: zone '277eecbb012f75864b1362e4f4c860d4' does not have access to the path"

I have tried with just the CF_API_TOKEN and both CF_API_KEY+CF_API_EMAIL. Am I missing something? :thinking:

EDIT: actually, nothing related to Cloudflare at all, am I looking at the metrics for the exporter container itself?

m0ar commented 3 years ago

Seems to work only when I use the Global API key, not at all when I use a token scoped over Account Analytics, Analytics and Zone. Not that it has anything to do with this particular PR, but it is indeed confusing. Also not very principle of least privilege.

@nouvellonsteph could you elaborate on how you setup the correct token?