InfluxDB
02 / 02

Querying with Flux, Retention & Downsampling

Querying with Flux, Retention & Downsampling

Flux — Pipe-Forward Queries

from(bucket: "metrics")
  |> range(start: -1h)
  |> filter(fn: (r) => r._measurement == "cpu_usage" and r.host == "server01")
  |> aggregateWindow(every: 5m, fn: mean)

Flux chains transformation functions with |>, a functional style distinct from InfluxQL's older SQL-like syntax (SELECT * FROM cpu_usage WHERE time > now() - 1h). aggregateWindow() groups into time buckets and aggregates each — reducing raw points to a chart-friendly resolution.

Retention Policies

Automatically deletes data older than a configured duration — old high-resolution raw data loses value over time and would otherwise accumulate indefinitely.

Downsampling via Tasks

A scheduled task (continuous query in 1.x) runs on a recurring interval — e.g. hourly — aggregating recent raw data and writing the summary into a separate, longer-retention bucket. Common pattern: raw data kept 7 days, hourly averages kept a year, at a fraction of the storage cost.

The Monitoring Stack

Telegraf (collection agent) gathers metrics and writes them via line protocol into InfluxDB (storage/query), commonly visualized with Grafana — the typical "collect → store → visualize" pipeline for infrastructure/application monitoring and IoT data.

Keep your own version of these notes — editable, searchable, and organised by your stack.

Start free