Streaming Detection
Streaming Detection
rsigma engine daemon runs RSigma as a long-running service: it keeps a compiled engine in memory, reads events from a continuous source, writes detections to one or more sinks, and exposes a small HTTP API for health checks, metrics, and management. Use it when you need state to survive restarts, hot-reload across rule changes, or a Prometheus-scrapeable detection engine.
The daemon can also run several named rulesets side by side with --ruleset or daemon.rulesets, each with its own pipelines and correlation state. See Rulesets.
Unreleased
This page covers the daemon’s lifecycle, input and output options, hot-reload, state persistence, and the HTTP API surface. For NATS-specific operations (auth, replay, consumer groups, DLQ) see NATS Streaming. For OTLP ingestion see OTLP Integration.
What the daemon does
┌───────────────┐ ┌──────────────────┐ ┌───────────────┐
events ───────► │ Event source ├───►│ LogProcessor ├───►│ Sinks ├───► detections
│ stdin/HTTP │ │ + RuntimeEngine │ │ stdout/file │
│ NATS/OTLP │ │ (Engine + Corr) │ │ NATS/DLQ │
└───────────────┘ └──────────────────┘ └───────────────┘
▲
│
hot-reload triggers
(file watcher, SIGHUP,
POST /api/v1/reload,
atomic ArcSwap)
A single daemon process binds one event source, one or more output sinks, a management HTTP API, optional SQLite state persistence, and an optional dead-letter queue for events that fail processing. State and rules can be reloaded without restart.
Start the daemon
Start with --input http so the process stays up while you probe it. Detections go to stdout by default; the management API binds --api-addr (default 0.0.0.0:9090):
rsigma engine daemon -r rules/ --input http --api-addr 127.0.0.1:9090
Wait until rules are loaded, which happens almost instantly, then post an NDJSON event and check readiness:
curl -sS http://127.0.0.1:9090/readyz
# ok
curl -sS -X POST http://127.0.0.1:9090/api/v1/events \
-H 'Content-Type: application/x-ndjson' \
--data '{"CommandLine":"whoami /priv"}'
# {"accepted":1}
Matching detections appear on the daemon’s stdout as NDJSON. Scrape GET /metrics or GET /api/v1/status for counters.
A fuller production-shaped start adds a pipeline, SQLite correlation state, and a file sink for fan-out:
rsigma engine daemon \
--rules /etc/rsigma/rules/ \
--pipeline /etc/rsigma/pipelines/ecs.yml \
--input http \
--output stdout \
--output file:///var/log/rsigma/detections.ndjson \
--state-db /var/lib/rsigma/state.db \
--api-addr 127.0.0.1:9090
For one-shot evaluation without state, use engine eval. A one-shot batch that must carry correlation state between runs uses engine daemon --input stdin per batch. The daemon’s default --input stdin is for a long-lived writer that keeps the pipe open (a collector process). If that writer closes stdin, the daemon treats the source as exhausted and shuts down after draining in-flight events. With --stdin-mode stream, it keeps running until a shutdown signal instead.
Input sources
The --input flag selects the primary event source:
| Source | Flag | What it does |
|---|---|---|
| stdin | --input stdin (default) |
Read NDJSON from standard input. Intended for a long-lived writer; when stdin closes, the daemon drains and exits, unless --stdin-mode stream keeps it running until a signal. Prefer --input http for interactive testing, engine eval for one-shot evaluation without state, and engine daemon --input stdin for a batch that carries state between runs. |
| HTTP | --input http |
Accept NDJSON POST requests on /api/v1/events. |
| NATS JetStream | --input nats://host:port/subject |
Subscribe to a JetStream subject with at-least-once delivery. Requires the daemon-nats feature. |
| Unix socket | --input unix:///path/to.sock |
Accept newline-delimited events over a Unix domain socket (Unix only). Co-located log shippers (rsyslog omuxsock, syslog-ng unix-stream, Vector, Fluent Bit) write to it directly without a TCP port. |
OTLP ingestion is always available alongside the primary source when the daemon is built with the daemon-otlp feature. Agents can post to /v1/logs (HTTP, protobuf or JSON) or use the gRPC LogsService/Export on the same --api-addr port.
See NATS Streaming for auth, replay, consumer groups, and DLQ. See OTLP Integration for agent recipes.
Input format and timestamp extraction
By default the daemon auto-detects the line format (JSON, syslog, plain text). Use --input-format to lock it in for predictable performance and validation:
rsigma engine daemon -r rules/ --input-format json
rsigma engine daemon -r rules/ --input-format syslog --syslog-tz +05:30
rsigma engine daemon -r rules/ --input-format logfmt
rsigma engine daemon -r rules/ --input-format cef
For correlation windows, the daemon tries a configurable list of timestamp fields. Prepend your own with --timestamp-field:
rsigma engine daemon -r rules/ --timestamp-field time --timestamp-field _ts
When an event has no parseable timestamp, the daemon falls back to the wall clock by default. Pass --timestamp-fallback skip to instead drop the event from correlation state (detections still fire). This is what you want for forensic replay of historical data.
Window modes
A correlation rule’s optional window attribute controls how its timespan is anchored to the stream, and the engine evaluates each mode directly:
sliding(the default, and what an absentwindowmeans): a trailing per-event window. When an event arrives at timet, the correlation is evaluated over(t - timespan, t], so two events correlate whenever they are withintimespanof each other regardless of any fixed boundary.tumbling: fixed, boundary-aligned, non-overlapping buckets of sizetimespan. The per-group state resets when an event lands in a new bucket. Use this when you want calendar-style buckets (for example a per-hour quota), accepting that events on opposite sides of a boundary are not compared.session: a dynamic window that stays open while consecutive in-group events are withingapof each other, and closes aftergapof inactivity. It restarts once the total span would exceedtimespan(the hard cap). This is the only mode that catches a low-and-slow chain whose steps are each close together but whose total span exceeds any fixedtimespan.
window and gap are an RSigma extension (a portable-spec version was declined upstream), so the primary spelling is the rsigma.* engine-extension namespace and the bare keys are kept as aliases. Both of these are equivalent:
# Primary: rsigma.* extension keys (top level, like rsigma.suppress)
rsigma.window: session
rsigma.gap: 5m
# Alias: first-class keys under the correlation section
correlation:
window: session
gap: 5m
The rsigma.* spelling wins if both appear. The engine reads the resolved value either way.
Window decisions follow arrival order, the same contract as the existing sliding window: the engine reasons about the events currently retained per group, not a global watermark. One asymmetry is deliberate: a tumbling window discards a late event that belongs to an earlier, already-passed bucket rather than letting it reset the active bucket, so out-of-order stragglers cannot wipe an accumulating count. Window bookkeeping is derived from the per-group timestamps already tracked, so persisted state (--state-db) stays compatible and survives upgrades.
All three modes have the same per-event cost (the window decision is O(1)), so choosing session over sliding is free at evaluation time; what differs is how long state is retained per group. See Performance Tuning for the memory characteristics and the Benchmarks page for measured numbers under high-cardinality and long-lived-session stress.
Output sinks
The --output flag is repeatable, so one daemon can fan out to several sinks. Each match is cloned to every configured sink via a bounded mpsc channel:
| Sink URI | Behavior |
|---|---|
stdout |
NDJSON to stdout. Default. Line sinks also accept ?format=ocsf for OCSF Detection Finding JSON. |
file:///path/to/file.ndjson |
Append NDJSON to a file, rotating only if you wrap it externally (logrotate, etc.). |
nats://host:port/subject |
Publish via JetStream with server-confirmed persistence. Requires daemon-nats. |
otlp(s)://host:port |
Export detections over OTLP/gRPC (s = TLS). Each attempt has a 10s deadline, tunable with ?timeout=.
Added in v0.25.0 Requires daemon-otlp. |
otlphttp(s)://host:port |
Export detections over OTLP/HTTP to /v1/logs (s = TLS). Each attempt has a 10s deadline, tunable with ?timeout=.
Added in v0.25.0 Requires daemon-otlp. |
unix:///path/to.sock |
Write NDJSON to a collector listening on a Unix domain socket (Unix only). Reconnects once on a transient write failure. |
Failed deliveries are routed to the dead-letter queue when --dlq is configured:
rsigma engine daemon -r rules/ \
--input nats://localhost:4222/events.> \
--output stdout --output file:///var/log/rsigma/detections.ndjson \
--dlq file:///var/log/rsigma/dlq.ndjson
Pipeline and back-pressure tuning
A handful of flags control how aggressively the daemon batches and how much it buffers under load:
| Flag | Default | What it controls |
|---|---|---|
--buffer-size |
10000 | Bounded mpsc capacity for source-to-engine and engine-to-sink channels. |
--batch-size |
128 | Max events the engine pulls per mutex acquisition, capped at --buffer-size. Batches enable parallel detection and amortize lock contention under load. |
--drain-timeout |
5 | Seconds the daemon waits for in-flight events on shutdown. |
For a 50 K/s ingest target, --buffer-size 50000 --batch-size 64 --drain-timeout 10 is a reasonable starting point. The rsigma_input_queue_depth, rsigma_output_queue_depth, and rsigma_back_pressure_events_total metrics tell you when you are sized too small. See the observability guide for details.
Hot-reload
Three triggers cause the daemon to re-read its rules, pipelines, and the enrichers, alert-pipeline, and risk files, debounced at 500 ms:
- A file system change to any
.ymlor.yamlfile under the rules directory, or in the directory of a pipeline file passed via-por of the--enrichers,--alert-pipeline, or--riskfile. Unreleased - A
SIGHUPsignal (Unix only). This also triggers re-resolution of dynamic sources. - A
POST /api/v1/reloadrequest.
If the new configuration fails to parse, the daemon keeps the old engine running and increments rsigma_reloads_failed_total. Successful reloads atomically swap the in-memory engine via ArcSwap, so in-flight events finish on the old engine and new events evaluate against the new one without dropping any.
Correlation windows carry over to the new engine for correlations that still exist after the reload. Rules load while events keep flowing through the old engine; the window state is then copied across and the engines swapped while ordered batches are briefly paused, so counts and windows include every event processed during the load.
Builtin pipelines (ecs_windows, sysmon) are embedded in the binary and are not file-watched.
State persistence
Without --state-db, correlation state lives only in memory and is lost on restart. With --state-db:
rsigma engine daemon -r rules/ --state-db /var/lib/rsigma/state.db
The daemon loads any existing snapshot on startup, saves periodically (every 30 s by default, tunable with --state-save-interval), and saves on graceful shutdown. The database is a single SQLite file in WAL journal mode that holds one JSON snapshot row per kind of state (correlation, alert pipeline, risk, and dispositions). Each save captures all of them back to back and writes them in one transaction, so a crash mid-save leaves the previous save intact rather than a mix of old and new state.
Added in v0.25.0
For example, an event_count correlation that has seen 4 of 5 required events resumes at 4 after a restart, not 0.
State restore during NATS replay
When you restart with a NATS replay flag (--replay-from-sequence, --replay-from-time, --replay-from-latest), the daemon stores the last-acked sequence and timestamp alongside the snapshot. On the next start, decide_state_restore compares the replay start point against the stored position:
- Replay starts after the stored position (forward catch-up): state is restored safely.
- Replay starts at or before the stored position (backward replay or forensic investigation): state is cleared, preventing double-counting.
Override the automatic decision with --keep-state (always restore) or --clear-state (always start fresh). The two flags are mutually exclusive.
rsigma engine daemon -r rules/ --input nats://localhost:4222/events.> \
--replay-from-sequence 1001 --state-db /var/lib/rsigma/state.db
See NATS Streaming for the full replay matrix.
HTTP API
The daemon binds an HTTP API listener on --api-addr (default 0.0.0.0:9090). It serves both REST and Prometheus endpoints, plus OTLP/gRPC and OTLP/HTTP when the feature is enabled. With the optional daemon-tls build feature and --tls-cert/--tls-key, the same listener terminates HTTPS for every protocol on one socket (ALPN negotiates h2 and http/1.1). Every build refuses to start on a non-loopback TCP --api-addr without TLS or --allow-plaintext, and without authentication (bearer tokens or --tls-client-ca) or --allow-unauthenticated.
Added in v0.25.0 Loopback and unix:// addresses need neither, for local development. See the TLS reference for the flag table and hot-reload semantics.
Auth is off by default. Enable a single admin bearer token with --api-token-env, or configure per-token roles in daemon.api.auth. Pair non-loopback listeners with TLS or a TLS-terminating proxy so tokens are never sent in cleartext. See HTTP API: Authentication.
The table below is a subset of the core surface. The full catalog (incidents, silences, risk, fields, correlations, dispositions, audit, and more) is in HTTP API.
| Path | Method | Purpose |
|---|---|---|
/healthz |
GET | Liveness probe. Always 200 once the listener is up. |
/readyz |
GET | Readiness probe. 200 once rules are loaded, 503 otherwise. |
/metrics |
GET | Prometheus text format, 118 metric names under --all-features (110 always-present + 3 OTLP + 2 TLS + 3 STIX source, gated on the matching build features). |
/api/v1/status |
GET | Counters, state-entry counts, uptime. |
/api/v1/rules |
GET | Rule counts and rules-directory path. |
/api/v1/reload |
POST | Trigger an immediate rules reload. |
/api/v1/events |
POST | Ingest events (only when --input http). NDJSON body. |
/api/v1/sources |
GET | Status of dynamic sources. |
/api/v1/sources/resolve |
POST | Force re-resolution of all (or some) dynamic sources. |
/api/v1/tap |
GET | Stream a bounded, redactable window of the live event stream as NDJSON. Disabled by default; enable with daemon.tap.enabled: true. See engine tap. |
/api/v1/detections/stream |
GET | Stream live detections as NDJSON, with optional level and rule filters. Disabled by default; enable with daemon.tail.enabled: true. See engine tail. |
/v1/logs |
POST | OTLP log ingestion (application/x-protobuf or application/json). |
Wire /readyz to your orchestrator’s startup probe and /healthz to the liveness probe. Scrape /metrics at 15-30s intervals.
Logging
Stderr carries structured JSON logs through tracing-subscriber. Verbosity is controlled with RUST_LOG (default info):
RUST_LOG=info,tower_http=debug rsigma engine daemon -r rules/
Useful filter targets and the spans they enable are documented in the observability guide, including:
tower_http=debugfor per-request HTTP access logs.rsigma=debugfor batch processing spans (batch_size,matches,elapsed_ms).rsigma_runtime::sources=debugfor dynamic pipeline source resolution.rsigma_eval=debugfor correlation engine internals (chain depth, hard-cap eviction).
Graceful shutdown
SIGINT (Ctrl+C) and SIGTERM both trigger the same shutdown path:
- Stop accepting new events.
- Drain in-flight events from the input channel into the engine and through to the sinks, up to
--drain-timeoutseconds. - Persist the final correlation snapshot to SQLite if
--state-dbis configured. - Close NATS connections, flush sinks, exit 0.
If the drain timeout expires before the queue empties, the daemon force-exits with a Drain timeout reached, exiting log line. In-flight events that did not reach a sink are routed to the DLQ when --dlq is set, or lost otherwise.
Production checklist
| Item | Why |
|---|---|
--rules points to a versioned directory under config management. |
Hot-reload should be a deliberate operation, not an accident. |
--pipeline references either a builtin (ecs_windows, sysmon) or a versioned file in the same directory. |
Same. |
--state-db is set and points to durable storage. |
Correlation state survives restarts. |
--dlq is configured. |
Parse errors and sink failures land somewhere you can audit. |
--api-addr is bound to an internal interface or loopback, behind a TLS-terminating proxy, or paired with --tls-cert/--tls-key (and --tls-client-ca for agent pinning), and API auth is enabled (--api-token-env or daemon.api.auth). |
Without auth, network position is the only guard. Never expose a plaintext management listener to the public internet. |
| The container runs read-only with capabilities dropped. | See the Docker guide. |
Prometheus scrapes /metrics. |
Detect back-pressure, parse errors, DLQ events. |
/readyz is wired to the orchestrator’s startup probe. |
Avoid sending traffic to a daemon that has not loaded rules yet. |
See also
- CLI reference:
engine daemonfor every flag. - NATS Streaming for auth, replay, consumer groups, and DLQ.
- OTLP Integration for Alloy, Vector, Fluent Bit, and OTel Collector recipes.
- Alert Pipeline, Enrichers, and Webhooks for post-evaluation surfaces the daemon can attach.
- Observability for
--log-format, RUST_LOG targets, and tracing spans. - HTTP API for the full endpoint reference and authentication.
- Security for TLS, API auth, and egress policy.
- Prometheus metrics for the 118-metric catalog.
- Docker for hardened production containers.