惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
C
Check Point Blog
博客园 - Franky
月光博客
月光博客
T
Tenable Blog
博客园 - 聂微东
Cyberwarzone
Cyberwarzone
The GitHub Blog
The GitHub Blog
C
CERT Recently Published Vulnerability Notes
Scott Helme
Scott Helme
IT之家
IT之家
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
CXSECURITY Database RSS Feed - CXSecurity.com
F
Full Disclosure
博客园 - 司徒正美
Project Zero
Project Zero
Y
Y Combinator Blog
A
Arctic Wolf
美团技术团队
博客园 - 叶小钗
S
Securelist
F
Fortinet All Blogs
T
Threatpost
T
Threat Research - Cisco Blogs
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
酷 壳 – CoolShell
酷 壳 – CoolShell
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Recorded Future
Recorded Future
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Schneier on Security
Apple Machine Learning Research
Apple Machine Learning Research
L
LangChain Blog
P
Privacy International News Feed
博客园_首页
S
SegmentFault 最新的问题
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
P
Proofpoint News Feed
Cisco Talos Blog
Cisco Talos Blog
AWS News Blog
AWS News Blog
阮一峰的网络日志
阮一峰的网络日志
G
Google Developers Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
雷峰网
雷峰网
P
Proofpoint News Feed
Latest news
Latest news
G
GRAHAM CLULEY

Flavio Copes

Better Auth: an introduction Cloudflare Artifacts: Git storage built for AI agents Workers Cache: a cache in front of your Cloudflare Worker Cloudflare Drop: drag a folder, get a live site Temporary Cloudflare accounts: agents can now deploy without signing up Moondream 3.1 on Workers AI: fast vision at the edge inferencecost.dev: what will AI inference cost you at 10k users? Sitebase: all the features your website needs, in one place StackPlan: figure out where to deploy your app, and what it How the Cloudflare Pages build cache works The Summer of Code How I generate an Open Graph image for every post New: 90 free tools for developers How I added search to my static site with Pagefind How to rebuild a Cloudflare site on a schedule Cloudflare Email Workers: run code when an email arrives Cloudflare Turnstile: stop bots without annoying CAPTCHAs Cloudflare Workers: secrets and environments Cloudflare Workers observability: logs and traces The AI Workshop (July 2026 cohort) Cloudflare Cron Triggers: run a Worker on a schedule Cloudflare Durable Objects: state that lives in one place Cloudflare Queues: run work in the background Cloudflare R2: object storage without egress fees Cloudflare KV: a key-value store for your Workers Cloudflare D1: a SQL database for your Workers Serving a website with Cloudflare Workers static assets Wrangler: the Cloudflare Workers command line tool Executor: one gateway to connect your AI agent to every tool Cloudflare Workers: your first serverless function Vercel eve: an open framework for building AI agents Flue: the open framework for building AI agents Val Town: write and deploy code in seconds A hands-on guide to The Agency, a collection of AI agents The AI Workshop (June 2026 cohort) The AI Workshop (May 2026 cohort) The AI Workshop (Apr 2026 cohort)
Cloudflare Analytics Engine: store and query metrics
Flavio Copes · 2026-06-29 · via Flavio Copes

By Flavio Copes

How to write custom events from a Worker with Analytics Engine and query them later with SQL. Cheap, high-volume time-series data.

~~~

Say you want to track every time someone uses a feature, then chart it later. You could write each event into your database, but that gets expensive and slow when there are millions of them.

Analytics Engine is built for exactly this. You write huge numbers of events, cheaply, and query them later with SQL. It’s a time-series store, the kind of thing you’d use for usage metrics and dashboards.

Set up a dataset

Your events go into a dataset. You don’t create it ahead of time, you just name it in wrangler.jsonc and it appears:

{
  "analytics_engine_datasets": [
    { "binding": "ANALYTICS", "dataset": "my_app_events" }
  ]
}

Now env.ANALYTICS is ready in your Worker.

Write an event

You record an event with writeDataPoint. It takes three kinds of fields:

export default {
  async fetch(request, env) {
    env.ANALYTICS.writeDataPoint({
      blobs: ['feature-used', 'pricing-page'],
      doubles: [1],
      indexes: ['user-123'],
    })

    return new Response('ok')
  },
}

Let me explain the three fields, because the names aren’t obvious:

  • blobs are strings. The text you want to store: an event name, a page, a country.
  • doubles are numbers. Things you’ll add up or average, like a count or a duration.
  • indexes is the value you’ll group and filter by most. Pick one, like a user id or tenant id.

Notice there’s no await. Writing is fire-and-forget, so it adds basically nothing to your response time. That’s the point.

Query with SQL

Later, you query the data with SQL through Cloudflare’s API. You send a query to an HTTP endpoint with an API token:

curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/analytics_engine/sql" \
  -H "Authorization: Bearer $API_TOKEN" \
  -d "SELECT blob1 AS event, count() AS total
      FROM my_app_events
      WHERE timestamp > now() - INTERVAL '1' DAY
      GROUP BY event"

A couple of things to notice. Your blobs come back as blob1, blob2, and so on, in the order you wrote them. Your doubles are double1, double2. And there’s a timestamp column for free on every event.

So this query counts each event type over the last day. Perfect for a dashboard.

A real use: per-tenant usage

In a SaaS app, I track usage per customer. The tenant id goes in indexes, the event in blobs, and a count in doubles:

env.ANALYTICS.writeDataPoint({
  blobs: ['form-submission'],
  doubles: [1],
  indexes: [tenantId],
})

Then at the end of the month, one SQL query tells me how much each tenant used. No giant table in my main database, no slow queries.

When to use it

Analytics Engine is for events you have a lot of and want to analyze in aggregate: page views, feature usage, API calls, durations.

It’s not for data you need to read back exactly, one record at a time. That’s still D1 or KV. Analytics Engine is for “how many, how often, grouped by what.”

It’s cheap, it’s fast to write, and the SQL makes it easy to slice. The full reference is in the Analytics Engine docs.

~~~

Related posts about cloudflare: