4.3 KiB
title | description | weight | influxdb/v2.3/tags | menu | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Downsample data with notebooks | Create a notebook to downsample data. Downsampling aggregates or summarizes data within specified time intervals, reducing the overall disk usage as data collects over time. | 104 |
|
|
Create a notebook to downsample data. Downsampling aggregates or summarizes data within specified time intervals, reducing the overall disk usage as data collects over time.
The following example creates a notebook that queries Coinbase bitcoin price sample data from the last hour, downsamples the data into ten minute summaries, and then writes the downsampled data to an InfluxDB bucket.
-
If you do not have an existing bucket to write the downsampled data to, create a new bucket.
-
Select Past 1h from the time range drop-down list at the top of your notebook.
-
In the Build a Query cell:
- In the FROM column under {{% caps %}}Sample{{% /caps %}}, select Coinbase bitcoin price.
- In the next FILTER column, select _measurement from the drop-down list and select the coindesk measurement in the list of measurements.
- In the next FILTER column, select _field from the drop-down list, and select the price field from the list of fields.
- In the next FILTER column, select code from the drop-down list, and select a currency code.
-
Click {{% icon "notebook-add-cell" %}} after your Build a Query cell to add a new cell and select {{% caps %}}Flux Script{{% /caps %}}.
-
In the Flux script cell:
-
Use
__PREVIOUS_RESULT__
to load the output of the previous notebook cell into the Flux script. -
Use [
aggregateWindow()
](/{{< latest "flux" >}}/stdlib/universe/aggregatewindow/) to window data into ten minute intervals and return the average of each interval. Specify the following parameters:- every: Window interval (should be less than or equal to the duration of the queried time range).
For this example, use
10m
. - fn: [Aggregate](/{{< latest "flux" >}}/function-types/#aggregates)
or [selector](/{{< latest "flux" >}}/function-types/#selectors) function
to apply to each window.
For this example, use
mean
.
- every: Window interval (should be less than or equal to the duration of the queried time range).
For this example, use
-
{{% cloud-only %}}
Use [
to()
](/{{< latest "flux">}}/stdlib/influxdata/influxdb/to/) to write the downsampled data back to an InfluxDB bucket.{{% /cloud-only %}}
{{% oss-only %}}
__PREVIOUS_RESULT__ |> aggregateWindow(every: 10m, fn: mean)
{{% /oss-only %}}
{{% cloud-only %}}
__PREVIOUS_RESULT__ |> aggregateWindow(every: 10m, fn: mean) |> to(bucket: "example-bucket")
{{% /cloud-only %}}
-
-
{{% oss-only %}}
Click {{% icon "notebook-add-cell" %}} after your Flux Script cell to add a new cell and select {{% caps %}}Output to Bucket{{% /caps %}}. Select a bucket from the {{% icon "bucket" %}} Choose a bucket drop-down list.
{{% /oss-only %}}
-
(Optional) Click {{% icon "notebook-add-cell" %}} and select Note to add a note to describe your notebook, for example, "Downsample Coinbase bitcoin prices into hourly averages."
-
{{% oss-only %}}
Click Preview in the upper left to verify that your notebook runs and displays the output.
{{% /oss-only %}}
-
Click Run to run the notebook and write the downsampled data to your bucket.
Continuously run a notebook
To continuously run your notebook, export the notebook as a task:
-
Click {{% icon "notebook-add-cell" %}} to add a new cell, and then select {{% caps %}}Task{{% /caps %}}.
-
Provide the following:
- Every: Interval that the task should run at.
- Offset: (Optional) Time to wait after the defined interval to execute the task. This allows the task to capture late-arriving data.
-
Click {{% icon "export" %}} Export as Task.