realtime-analytics
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "realtime-analytics" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-a6b3027fd78120cc326707ef7e9bc868e059e9731df6f2b1fb810c3c80d57cf7. Verify the upstream source and version against https://github.com/TerminalSkills/skills before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
github.com
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Build real-time analytics pipelines from scratch. Used when setting up analytics systems, building dashboards, tracking events in real time, ClickHouse analytics, event ingestion pipelines, or real-time metrics, covering event schema design, batched ingestion services, ClickHouse table optimization, aggregation queries, and dashboard connections.
Introduction source: third_party · TerminalSkills · 1.0.0 Reference
SkillPi interpretation
- Software, accounts and paid services
- Provide a `docker-compose.yml` with: ClickHouse service (pinned version, volume for data) Ingestion service (builds from Dockerfile) Dashboard frontend (builds from Dockerfile or served via nginx) An init container or entrypoint script that creates the events table
- Testing
- Not tested
Browse files
Frontmatter
name: realtime-analytics
description: >-
Build real-time analytics pipelines from scratch. Use when someone asks to
"set up analytics", "build a dashboard", "track events in real time",
"ClickHouse analytics", "event ingestion pipeline", or "live metrics".
Covers event schema design, ingestion services with batching, ClickHouse
table optimization, aggregation queries, and dashboard wiring.
license: Apache-2.0
compatibility: "Node.js 18+, ClickHouse 23.8+, Docker recommended"
metadata:
author: terminal-skills
version: "1.0.0"
category: data-ai
tags: ["analytics", "real-time", "clickhouse", "event-tracking"]Real-Time Analytics
Overview
This skill enables AI agents to build self-hosted, real-time analytics systems. It covers the full pipeline from event ingestion through storage to query and visualization, using ClickHouse as the analytical database for sub-second query performance at scale.
Instructions
Event Schema Design
-
Every event must have these base fields:
event_name— LowCardinality(String) for efficient storagetimestamp— DateTime64(3) for millisecond precisionsession_id— String, client-generated UUIDuser_id— Nullable(String) for anonymous trackingdevice_type— LowCardinality(String): desktop, mobile, tabletcountry_code— LowCardinality(FixedString(2))properties— String containing JSON for event-specific data
-
ClickHouse table optimization rules:
- Use
MergeTree()engine, partition bytoYYYYMM(date) - ORDER BY should start with the most filtered column (usually
event_name) - Add TTL for automatic data expiration (default 90 days)
- Use
LowCardinality()for any string column with fewer than 10,000 distinct values
- Use
Ingestion Service
- Build as a stateless HTTP service accepting
POST /eventswith JSON array body. - Validate incoming events: reject if
event_nameortimestampis missing. - Buffer events in memory. Flush when either condition is met:
- Buffer reaches 1,000 events
- 2 seconds have elapsed since last flush
- Use ClickHouse's
INSERT ... FORMAT JSONEachRowfor batch inserts. - On flush failure, retry 3 times with exponential backoff, then write to a dead-letter file.
- Expose
GET /healthreturning:{ "buffer_size": N, "last_flush": "ISO timestamp", "status": "ok" }.
Aggregation Queries
Write queries as named .sql files. Common dashboard panels:
Active users (last N minutes):
SELECT count(DISTINCT session_id) AS active_users
FROM events
WHERE timestamp > now() - INTERVAL 5 MINUTE;
Funnel analysis (two-step):
SELECT
toStartOfHour(timestamp) AS hour,
countIf(event_name = 'signup_started') AS started,
countIf(event_name = 'signup_completed') AS completed,
round(completed / started * 100, 1) AS conversion_pct
FROM events
WHERE date = today()
GROUP BY hour
ORDER BY hour;
Top features by unique users:
SELECT
JSONExtractString(properties, 'feature') AS feature,
count(DISTINCT user_id) AS unique_users
FROM events
WHERE event_name = 'feature_used' AND date = today()
GROUP BY feature
ORDER BY unique_users DESC
LIMIT 10;
Error rate per minute:
SELECT
toStartOfMinute(timestamp) AS minute,
count() AS error_count
FROM events
WHERE event_name = 'error_occurred'
AND timestamp > now() - INTERVAL 1 HOUR
GROUP BY minute
ORDER BY minute;
Dashboard API Layer
- Create one REST endpoint per dashboard panel (e.g.,
GET /api/dashboard/active-users). - Each endpoint runs its SQL query and returns JSON.
- Add a
time_rangequery param:1h,6h,24h,7d. Adjust the WHERE clause accordingly. - Cache results for 3-5 seconds to avoid hammering ClickHouse on concurrent dashboard loads.
Docker Compose Setup
Provide a docker-compose.yml with:
- ClickHouse service (pinned version, volume for data)
- Ingestion service (builds from Dockerfile)
- Dashboard frontend (builds from Dockerfile or served via nginx)
- An init container or entrypoint script that creates the events table
Examples
Example 1 — Schema for an e-commerce app
Input: "Design analytics events for an e-commerce checkout flow."
Output:
-- Core events: product_viewed, add_to_cart, checkout_started,
-- payment_submitted, order_completed, order_failed
CREATE TABLE events (
event_name LowCardinality(String),
timestamp DateTime64(3),
session_id String,
user_id Nullable(String),
device_type LowCardinality(String),
country_code LowCardinality(FixedString(2)),
properties String,
date Date DEFAULT toDate(timestamp)
) ENGINE = MergeTree()
PARTITION BY toYYYYMM(date)
ORDER BY (event_name, timestamp)
TTL date + INTERVAL 180 DAY;
Properties JSON per event:
product_viewed:{"product_id": "p-42", "category": "electronics", "price_cents": 4999}add_to_cart:{"product_id": "p-42", "quantity": 1}payment_submitted:{"method": "card", "amount_cents": 9998}
Example 2 — Ingestion buffer logic
Input: "Show the buffer flush logic in Node.js."
Output:
const FLUSH_INTERVAL_MS = 2000;
const FLUSH_SIZE = 1000;
let buffer = [];
async function addEvents(events) {
buffer.push(...events);
if (buffer.length >= FLUSH_SIZE) await flush();
}
setInterval(async () => {
if (buffer.length > 0) await flush();
}, FLUSH_INTERVAL_MS);
async function flush() {
const batch = buffer.splice(0, buffer.length);
const rows = batch.map(e => JSON.stringify(e)).join('\n');
await clickhouse.insert({
table: 'events',
values: batch,
format: 'JSONEachRow',
});
}
Guidelines
- Partition wisely. Monthly partitions work for most apps. Daily only if you ingest > 100M events/day.
- Do not use Kafka unless asked. For under 50K events/second, direct HTTP ingestion with in-memory buffering is simpler and sufficient.
- Always add TTL. Unbounded analytical tables grow fast. Default to 90 days; let the user override.
- Test with realistic volume. Generate synthetic events to validate the pipeline handles expected throughput before going live.
- *Avoid SELECT .** Always specify columns in aggregation queries to minimize I/O.
Current listing version
1.0.0
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供端到端实时分析管道构建能力,覆盖事件模式设计、摄取服务、ClickHouse 优化、聚合查询及仪表板连接
- 解决用户在高频刚需场景(如构建分析系统、实时跟踪事件)下的核心痛点,具备高实用价值
Highlights
- 触发词覆盖全面('set up analytics', 'build a dashboard', 'track events in real time', 'ClickHouse analytics', 'event ingestion pipeline', 'live metrics'),边界清晰,无歧义
Areas to improve
-
缺少 When to Use 显式章节 Reported severity: Minor
文档结构完整,但未设置显式的 When to Use 章节,用户需从 description 推断使用场景
Recommendation: 建议添加 When to Use 章节,明确列出典型使用场景和触发条件
Highlights
- Phase/步骤清晰(事件模式设计、摄取服务、聚合查询、仪表板 API、Docker 设置),含端到端示例(e-commerce schema、Node.js buffer logic)
- frontmatter 完整,单文件未超限
Areas to improve
-
部分 frontmatter 字段未在顶层完整定义 Reported severity: Minor
license 字段在顶层 frontmatter 中定义为 Apache-2.0,但未提供完整许可证文本或链接
Recommendation: 建议在顶层 frontmatter 中补充 license 的完整定义或指向标准许可证文件的链接
Highlights
- 工具来源明确(ClickHouse、Node.js、Docker),参数正确(FLUSH_INTERVAL_MS、FLUSH_SIZE)
- 覆盖主要异常(flush 失败重试、dead-letter 文件),不可逆操作(如数据插入)有确认机制(health endpoint)
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Provide a `docker-compose.yml` with: ClickHouse service (pinned version, volume for data) Ingestion service (builds from Dockerfile) Dashboard frontend (builds from Dockerfile or served via nginx) An init container or entrypoint script that creates the events table
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.