# Interpolation & the fill modifier explained

## Why interpolation?

Interpolation is not about filling arbitrary large gaps in a metric series, but aligning several series together, to make it possible to perform aggregation across sources.

Most of the time graphing in Datadog is about mixing together data from separate sources into a single line for your graph. However, separate sources might not submit data at the same time and with the same frequency.

``````net.bytes_rcvd    |  3:00:00  3:00:10  3:00:20  3:00:30  3:00:40 ...
------------------+-------------------------------------------------
1: host:A,env:prod|    15                         25
2: host:B,env:test|             10                         40
------------------+-------------------------------------------------
sum (1+2)     |    15?      10?               25?      40?
``````

The above example shows that merging sources directly produces absurd results just because sources are not naturally aligned. Interpolation solves this problem by providing relevant values just for calculations.

``````net.bytes_rcvd    |  3:00:00  3:00:10  3:00:20  3:00:30  3:00:40 ...
------------------+-------------------------------------------------
1: host:A,env:prod|    15       18.3              25        X
2: host:B,env:test|     Y       10                30       40
------------------+-------------------------------------------------
sum (1+2)     |   15 + Y    28.3              55       40 + X
``````

Where X and Y are interpolated using data after and before the interval displayed.

## In which cases does interpolation occur?

Interpolation occurs when more than one source corresponds to your graph query, for example:

• With space aggregation (`avg:system.cpu.user{env:prod}`), if you have two or more hosts with the tag `env:prod`, Datadog computes the average over time using interpolation.
• With group queries (`net.bytes_rcvd{*} by {host}`, no computation across sources may be performed, but providing aligned series makes the graph line mouse-over and comparisons easier.

Interpolation is not needed when you graph one metric submitted from one source, for example `avg:net.bytes_rcvd{host:a}` assuming `host:a` always submits the metric `net.bytes_rcvd` with the same tags.

Interpolation is not performed for multi-part queries, for example:
`avg:system.cpu.user{env:prod},avg:system.cpu.user{env:dev}`

The type of interpolation described in this article is also not performed for arithmetic. When evaluating queries, Datadog’s backend rolls data up into intervals (one for each point in a timeseries graph, see this article for more details). If a query involves arithmetic, and one of these intervals is missing data for part of a query, the query system substitutes 0 for that interval. This behavior cannot be controlled with the fill modifier.

## How to control interpolation?

The default interpolation for gauge type metrics is linear and is performed up to 5 min after real samples. The default for count or rate type metrics is to disable interpolation.

The fill modifier controls interpolation parameters:

• fill(linear, X) gives you a linear interpolation up to X seconds after real samples.
• fill(last, X) just replicates the last sample value up to X secs.
• fill(zero, X) inserts 0 where the interpolation is needed up to X secs.
• fill(null, X) disables interpolation, the value of X doesn’t matter.

## FAQ

There’s a gap in my metric, fill(zero) doesn’t do anything, I still have a long straight line on my graph.
Since graphs are just a series of data points joined by lines, a long period without any data translates into a long straight line and has no need for interpolation to fill values. Interpolation is about aligning series to make aggregation and multi-line graphs possible.

In contrast, a monitor uses a rollup of a time frame to evaluate interpolated values and calculate averages.

I have disabled interpolation but I see my metrics dropping to 0 which is not expected.