Provides pricing and uses the MailChannel integration with CloudFlare. This will give a percent report on all class A, class B, and storage size metrics.
Then if any of them are above 50% of the free tier usage it will email you an alert. However, every Monday an email will be sent regardless to get an idea of where your usage stands.
This worker has been running for me well under the 10ms CPU time. Meaning it should be completely free to use.
create a .dev.vars file with the following contents
You can get your account id from the right on this page
CLOUDFLARE_ACCOUNT=account_id
CLOUDFLARE_API_TOKEN=global_or_scoped_token
EMAIL=destination@email.com
Update the DOMAIN & NAME variable found in wrangler.toml
create a new line for
DEBUG=true
to help with your initial deploy
[vars]
DOMAIN="pom-pom-purin.com"
NAME="Hacker"
DEBUG=true
For local testing I'm using node --env-file
which requires 20.6+
. If you have a lower version use the dotenv package.
Keep in mind there is currently no way to use MailChannel to test locally so that logic is removed entirely in the local.js
file.
Use wrangler CLI. Add the three secrets required:
wrangler secret put CLOUDFLARE_ACCOUNT
CLOUDFLARE_ACCOUNT=
CLOUDFLARE_API_TOKEN=
EMAIL=
Then deploy with wrangler
wrangler deploy
Integration with MailChannel is dead simple. However, there is little good info online about how to do the setup. The only real documentation I've found has been here
This is how I integrated:
- have a DNS record managed by Cloudflare. Meaning you can create records for it. You can use nameservers if you bought from another service.
- create a new "TXT" record with the name "_mailchannels"
- In the Content input follow this format
v=mc1 auth=example.com cfid=example.workers.dev
Since I have the codabool.com domain mine looks like this
This auth domain must match the domain variable found in
wrangler.toml
# example _mailchannels record for codabool.com
v=mc1 auth=codabool.com cfid=codabool.workers.dev
The cfid
can be tricky to configure right. I believe you will need to setup a subdomain for your workers on this page. Also keep in mind that since these are DNS changes it can take a couple minutes to propgate and testing record changes may not be reflected immediately.
- Verify it's working by testing your worker. This worker is only runnable through a scheduled cron in it's current state. So, put it on a
* * * * *
cron at the triggers tab. Then activate a log stream to capture a log event for debugging. - Once verified working, set the debug var to
false
in the worker settings. set to a daily cron of0 9 * * *
and enjoy weekly (unless past alarm state it will email daily) metric emails β
I have automatted builds which require setting these two GitHub Action secrets:
this will deploy the worker on any push to the main branch. Keep in mind Global API keys are not allowed for this. You will need to create a scoped token here
CLOUDFLARE_API_TOKEN=
CLOUDFLARE_ACCOUNT=