InsightFlare
Edge-native web analytics on Cloudflare. High-throughput via Durable Objects, tiered D1/R2 storage for infinite retention, and privacy-first tracking.
Install / Use
/learn @RavelloH/InsightFlareREADME
InsightFlare (Backend Only)
InsightFlare 是运行在 Cloudflare 上的开源访问分析后端服务。
功能
- 动态
GET /script.js(按request.cf.isEUCountry切换 EU 模式) - 客户端事件采集:
POST /collect - Durable Object 并行写入:内存缓冲、Analytics Engine、WebSocket、Alarm
- Alarm 批量落盘 D1
- 每小时归档:热归档(D1 小时聚合)+ 冷归档(可选 R2 Parquet)
- 查询与管理接口(私有/公开 API)
- Parquet 文件查询支持
HTTP Range Requests
架构
- 单应用:根目录 Next.js Route Handlers + OpenNext + Cloudflare Worker
- 单配置:根目录
wrangler.toml - 入口接口:
/script.js/collect/api/private/*/api/public/*/api/admin/*/api/auth/*/api/archive/*/healthz
workers/cf-worker.js负责:- 导出 Durable Object 类
- 透传
/admin/ws - 执行定时归档任务
快速开始
- 安装依赖
npm ci
- 创建 D1(首次)
npm run cf:d1:create
- 修改根目录
wrangler.toml
- 填入
[[d1_databases]]的database_id - 在
[vars]下添加ANALYTICS_ACCOUNT_ID(Cloudflare Account ID) - 按需开启
[[r2_buckets]] INSIGHTFLARE_EDGE_URL可配置为当前后端服务地址
- 设置 Secret(至少一个)
npm run cf:secret:daily-salt
可选:
npm run cf:secret:bootstrap-admin-password
npm run cf:secret:session-secret
npm run cf:secret:analytics-sql-token
- 本地构建验证
npm run cf:build
- 部署
npm run cf:deploy
Cloudflare Git 集成
如果在 Cloudflare 控制台使用 Git 自动部署,请设置:
- Build command:
npm run ci:build - Deploy command:
npm run ci:deploy
不要跳过 prebuild 直接部署,否则 D1 迁移不会自动执行。
常用命令
- 本地开发:
npm run dev - 预部署 dry-run:
npm run cf:deploy:dry-run - CI dry-run:
npm run ci:deploy:dry-run - 查看线上日志:
npm run cf:tail
关键配置
SESSION_WINDOW_MINUTES:会话窗口(默认30)SCRIPT_CACHE_TTL_SECONDS:/script.js缓存秒数PARQUET_WASM_URL:Parquet wasm 下载地址ANALYTICS_ACCOUNT_ID:Analytics Engine SQL 查询使用的 Cloudflare 账号 IDANALYTICS_SQL_API_TOKEN(Secret):用于 0-90 天 Analytics Engine 查询DISABLE_ANALYTICS_ENGINE:设为true/1可关闭 Analytics Engine 读写,查询回退到 D1/归档
注意事项
- 生产建议使用 Linux/WSL/CI 构建(OpenNext 官方建议)
Related Skills
feishu-drive
334.9k|
things-mac
334.9kManage Things 3 via the `things` CLI on macOS (add/update projects+todos via URL scheme; read/search/list from the local Things database)
clawhub
334.9kUse the ClawHub CLI to search, install, update, and publish agent skills from clawhub.com
codebase-memory-mcp
895High-performance code intelligence MCP server. Indexes codebases into a persistent knowledge graph — average repo in milliseconds. 64 languages, sub-ms queries, 99% fewer tokens. Single static binary, zero dependencies.
