Giter Site home page Giter Site logo

analytics's Introduction

๐Ÿฅ… Goal

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.

๐Ÿ’ธ Free Tier

This worker has been running for me well under the 10ms CPU time. Meaning it should be completely free to use.

๐Ÿ”‘ Required Variables

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 protected]

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

๐Ÿฅพ Usage

๐ŸŸข Node 20.6+

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.

๐Ÿ— Deployment

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

๐Ÿ“จ MailChannel

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:

  1. have a DNS record managed by Cloudflare. Meaning you can create records for it. You can use nameservers if you bought from another service.
  2. create a new "TXT" record with the name "_mailchannels"
  3. 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.

  1. 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.
  2. Once verified working, set the debug var to false in the worker settings. set to a daily cron of 0 9 * * * and enjoy weekly (unless past alarm state it will email daily) metric emails โ˜•

๐Ÿค– Automation

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=

analytics's People

Contributors

codabool avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.