Historian & Time-Series
Industrial MQTT → TimescaleDB pipeline, anomaly detection, downsampling
Overview
The Historian provides an industrial-grade MQTT-to-TimescaleDB time-series pipeline. It subscribes to MQTT topics on the Unified Namespace (UNS), automatically creates hypertables, and stores data with configurable retention policies, downsampling, and crash recovery.
Architecture
Features
- Auto Table Creation — Hypertables are created automatically when new MQTT topics are first seen
- Retention Policies — Configurable per-table data retention (e.g., 90 days raw, 1 year aggregated)
- Downsampling — Continuous aggregates for 1-minute, 1-hour, and 1-day rollups
- Disk Buffer — Writes to local disk when the database is unreachable, replays on reconnect
- Backpressure — Throttles ingestion when the database falls behind to prevent memory exhaustion
- COPY Protocol — Uses PostgreSQL COPY for bulk inserts, significantly faster than row-by-row INSERT
- Dead-Letter Queue — Messages that fail 3 retries are moved to a dead-letter topic for investigation
MCP Tools (6 History Tools)
The Historian exposes 6 tools via MCP for LLM-driven time-series analysis:
history_get_trendRetrieve time-series data for a variable over a time range with optional downsampling
history_compareCompare trends of multiple variables side-by-side over the same time window
history_aggregateCompute aggregations (min, max, avg, sum, count) over configurable time buckets
history_anomaliesDetect anomalies using statistical methods (z-score, IQR) on historical data
history_machinesList all machines with historian data, including variable counts and time ranges
history_variablesList all recorded variables for a machine with metadata (type, unit, sample count)
Topic Profiles
Topic profiles define how MQTT topics are routed to TimescaleDB tables. Each profile specifies:
- Topic Pattern — MQTT topic filter (supports wildcards)
- Target Table — TimescaleDB hypertable name
- Field Mapping — JSON path to extract timestamp, value, and tags
- Retention — Per-profile data retention period
REST API
The Historian exposes a REST API for management and data exploration:
Route ManagementCreate, update, and delete MQTT topic subscriptions and routing rules.
Profile ManagementConfigure topic profiles with field mappings, retention, and downsampling settings.
Data ExplorerQuery historical data with time range, aggregation, and filtering parameters.
Resilience
The Historian is designed for industrial reliability:
- Disk Buffer — When TimescaleDB is unreachable, messages are buffered to local disk and replayed automatically on reconnect
- Backpressure — If the write queue exceeds a configurable threshold, the MQTT client pauses consumption to prevent OOM
- 3-Retry Dead-Letter — Failed messages are retried 3 times with exponential backoff before being moved to a dead-letter topic
- COPY Protocol — Bulk inserts via PostgreSQL COPY are atomic and significantly faster than individual INSERTs