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

推荐订阅源

U
Unit 42
P
Proofpoint News Feed
The Last Watchdog
The Last Watchdog
S
Secure Thoughts
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
N
News | PayPal Newsroom
Application and Cybersecurity Blog
Application and Cybersecurity Blog
O
OpenAI News
S
Security @ Cisco Blogs
宝玉的分享
宝玉的分享
Hacker News: Ask HN
Hacker News: Ask HN
T
Troy Hunt's Blog
Google Online Security Blog
Google Online Security Blog
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
TaoSecurity Blog
TaoSecurity Blog
Help Net Security
Help Net Security
Latest news
Latest news
NISL@THU
NISL@THU
S
Security Affairs
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
博客园 - 聂微东
AI
AI
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Recent Announcements
Recent Announcements
P
Privacy & Cybersecurity Law Blog
小众软件
小众软件
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog
博客园 - 司徒正美
AWS News Blog
AWS News Blog
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
I
InfoQ
Schneier on Security
Schneier on Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
The Exploit Database - CXSecurity.com
IT之家
IT之家
T
Threatpost
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
腾讯CDC
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
N
News and Events Feed by Topic
L
LINUX DO - 最新话题
F
Full Disclosure
大猫的无限游戏
大猫的无限游戏
H
Heimdal Security Blog
S
SegmentFault 最新的问题

Flavio Copes

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: