Real-time streaming API analytics with Kafka and ClickHouse - stream API events, aggregate with windowing, and query dashboards live.
Agentic Workflow: Read -> Reason -> Act (api-analytics-streaming)
You are Api Analytics Streaming (sre) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — sre context for api-analytics-streaming
- Domain: Real-time streaming API analytics with Kafka and ClickHouse - stream API events, aggregate with windowing, and query dashboards live.
- streaming-analytics: Stream API events and run real-time aggregations —
kafka-topics.sh --bootstrap-server localhost:9092 --create --topic api-events --
- Check
knowledge and prerequisites: prometheus, grafana, elasticsearch
2. Reason — think for api-analytics-streaming
- For
streaming-analytics: Stream API events and run real-time aggregations — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with api-analytics-streaming tools
- Tools:
Glob, Grep, Read, Kafka-topics.sh, Kafka-console-producer.sh (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
api-analytics-streaming:a165fab5
API Analytics (Real-time Streaming)
What this skill does
Stream API events in real time: produce events to Kafka, ingest into ClickHouse, and query windowed aggregations for live dashboards.
When to use
- Live dashboards with second-level freshness
- High-volume event ingestion (millions/day)
- Time-series analysis with SQL
Real commands
# Create the topic
kafka-topics.sh --bootstrap-server localhost:9092 \
--create --topic api-events --partitions 6 --replication-factor 1
# Produce events from a JSONL file
kafka-console-producer.sh --bootstrap-server localhost:9092 --topic api-events < events.jsonl
# Verify consumption
kafka-console-consumer.sh --bootstrap-server localhost:9092 \
--topic api-events --from-beginning --max-messages 5
# Start ClickHouse
docker run -d -p 8123:8123 -p 9000:9000 clickhouse/clickhouse-server
# Create the events table
curl -s -X POST 'http://localhost:8123/?query=CREATE%20TABLE%20IF%20NOT%20EXISTS%20api_events%20(time%20DateTime,%20endpoint%20String,%20status%20UInt16)%20ENGINE%3DMergeTree%20ORDER%20BY%20time'
# Events per minute, last rows
curl -s -X POST 'http://localhost:8123/?query=SELECT%20toStartOfMinute(time)%20as%20m,%20count()%20FROM%20api_events%20GROUP%20BY%20m%20ORDER%20BY%20m%20DESC%20LIMIT%205' | column -t
# Status distribution last 10 minutes
curl -s 'http://localhost:8123/?query=SELECT%20status,%20count()%20FROM%20api_events%20WHERE%20time%20%3E%20now()-600%20GROUP%20BY%20status'
Pipeline
API -> Kafka (api-events) -> ClickHouse -> dashboards
Best practices
- Partition by API key or endpoint for parallelism
- Use MergeTree ordering by time for range scans
- Batch inserts (min 1000 rows) for throughput
- Monitor consumer lag with kafka-consumer-groups
Testing
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic api-events --max-messages 1
curl -s 'http://localhost:8123/?query=SELECT%20count()%20FROM%20api_events'
Capabilities
streaming-analytics
Stream API events and run real-time aggregations
Parameters:
topic (string): Kafka topic for events
query (string): SQL against ClickHouse
window (string): Window function, e.g. toStartOfMinute
Commands:
kafka-topics.sh --bootstrap-server localhost:9092 --create --topic api-events --partitions 6 --replication-factor 1
kafka-console-producer.sh --bootstrap-server localhost:9092 --topic api-events < events.jsonl
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic api-events --from-beginning --max-messages 5
docker run -d -p 8123:8123 -p 9000:9000 clickhouse/clickhouse-server
curl -s -X POST 'http://localhost:8123/?query=SELECT%20toStartOfMinute(time)%20as%20m,%20count()%20FROM%20api_events%20GROUP%20BY%20m%20ORDER%20BY%20m%20DESC%20LIMIT%205' | column -t
Examples:
References
1---2name: "api-analytics-streaming"3description: "Real-time streaming API analytics with Kafka and ClickHouse - stream API events, aggregate with windowing, and query dashboards live. Use when working with streaming analytics or when the user mentions streaming analytics."4license: "MIT"5compatibility: "Requires prometheus, grafana, elasticsearch, node.js, python. Needs network access."6metadata:7 source: https://skillmd.com/skills/opknock/api-analytics-streaming8 author: Kdesk9 version: 2.0.010 category: sre11allowed-tools: "Glob Grep Read Bash(curl:*) Bash(docker:*) Bash(kafka-console-consumer.sh:*) Bash(kafka-console-producer.sh:*) Bash(kafka-topics.sh:*)"12---1314Real-time streaming API analytics with Kafka and ClickHouse - stream API events, aggregate with windowing, and query dashboards live.1516## Agentic Workflow: Read -> Reason -> Act (api-analytics-streaming)1718You are **Api Analytics Streaming** (sre) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — sre context for `api-analytics-streaming`21- Domain: Real-time streaming API analytics with Kafka and ClickHouse - stream API events, aggregate with windowing, and query dashboards live.22- **streaming-analytics**: Stream API events and run real-time aggregations — `kafka-topics.sh --bootstrap-server localhost:9092 --create --topic api-events --`23- Check `knowledge` and `prerequisites: prometheus, grafana, elasticsearch`2425### 2. Reason — think for `api-analytics-streaming`26- For `streaming-analytics`: Stream API events and run real-time aggregations — decide which checks to run27- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs2829### 3. Act — execute with `api-analytics-streaming` tools30- Tools: `Glob`, `Grep`, `Read`, `Kafka-topics.sh`, `Kafka-console-producer.sh` (see frontmatter `tools`/`allowed-tools`)31- Use `safe_path` for any write; record evidence (paths, checksums)32- Fingerprint: `api-analytics-streaming:a165fab5`3334# API Analytics (Real-time Streaming)3536## What this skill does37Stream API events in real time: produce events to Kafka, ingest into ClickHouse, and query windowed aggregations for live dashboards.3839## When to use40- Live dashboards with second-level freshness41- High-volume event ingestion (millions/day)42- Time-series analysis with SQL4344## Real commands45```bash46# Create the topic47kafka-topics.sh --bootstrap-server localhost:9092 \48 --create --topic api-events --partitions 6 --replication-factor 14950# Produce events from a JSONL file51kafka-console-producer.sh --bootstrap-server localhost:9092 --topic api-events < events.jsonl5253# Verify consumption54kafka-console-consumer.sh --bootstrap-server localhost:9092 \55 --topic api-events --from-beginning --max-messages 55657# Start ClickHouse58docker run -d -p 8123:8123 -p 9000:9000 clickhouse/clickhouse-server5960# Create the events table61curl -s -X POST 'http://localhost:8123/?query=CREATE%20TABLE%20IF%20NOT%20EXISTS%20api_events%20(time%20DateTime,%20endpoint%20String,%20status%20UInt16)%20ENGINE%3DMergeTree%20ORDER%20BY%20time'6263# Events per minute, last rows64curl -s -X POST 'http://localhost:8123/?query=SELECT%20toStartOfMinute(time)%20as%20m,%20count()%20FROM%20api_events%20GROUP%20BY%20m%20ORDER%20BY%20m%20DESC%20LIMIT%205' | column -t6566# Status distribution last 10 minutes67curl -s 'http://localhost:8123/?query=SELECT%20status,%20count()%20FROM%20api_events%20WHERE%20time%20%3E%20now()-600%20GROUP%20BY%20status'68```6970## Pipeline71```72API -> Kafka (api-events) -> ClickHouse -> dashboards73```7475## Best practices76- Partition by API key or endpoint for parallelism77- Use MergeTree ordering by time for range scans78- Batch inserts (min 1000 rows) for throughput79- Monitor consumer lag with kafka-consumer-groups8081## Testing82```bash83kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic api-events --max-messages 184curl -s 'http://localhost:8123/?query=SELECT%20count()%20FROM%20api_events'85```8687## Capabilities8889### streaming-analytics90Stream API events and run real-time aggregations9192**Parameters:**93- `topic` (string): Kafka topic for events94- `query` (string): SQL against ClickHouse95- `window` (string): Window function, e.g. toStartOfMinute9697**Commands:**98- `kafka-topics.sh --bootstrap-server localhost:9092 --create --topic api-events --partitions 6 --replication-factor 1`99- `kafka-console-producer.sh --bootstrap-server localhost:9092 --topic api-events < events.jsonl`100- `kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic api-events --from-beginning --max-messages 5`101- `docker run -d -p 8123:8123 -p 9000:9000 clickhouse/clickhouse-server`102- `curl -s -X POST 'http://localhost:8123/?query=SELECT%20toStartOfMinute(time)%20as%20m,%20count()%20FROM%20api_events%20GROUP%20BY%20m%20ORDER%20BY%20m%20DESC%20LIMIT%205' | column -t`103104**Examples:**105- kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic api-events --property print.key=true --max-messages 10106- curl -s 'http://localhost:8123/?query=SELECT%20status,%20count()%20FROM%20api_events%20WHERE%20time%20%3E%20now()-600%20GROUP%20BY%20status'107- kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group analytics --describe108109## References110- [Kafka Documentation](https://kafka.apache.org/documentation/)111- [ClickHouse Docs](https://clickhouse.com/docs)