Skip to content

Commit 83b9fd1

Browse files
gferrateclaudeourachealjanine-c
authored
Add time() function to formula querying docs (#37478)
* Add time() function to formula querying docs Add documentation for the time() function and convert the metric arithmetic, min/max, and related subsections into collapsible blocks. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Apply suggestions from code review Co-authored-by: Janine Chan <64388808+janine-c@users.noreply.github.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Racheal Ou <144172411+ouracheal@users.noreply.github.com> Co-authored-by: Janine Chan <64388808+janine-c@users.noreply.github.com>
1 parent 2a44779 commit 83b9fd1

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

content/en/dashboards/querying/_index.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,16 @@ Datadog also supports the ability to graph your metrics, logs, traces, and other
150150

151151
To graph metrics separately, use the comma (`,`). For example, `a, b, c`.
152152

153-
**Note**: Queries using commas are only supported in visualizations, they do not work on monitors. Use [boolean operators][15] or arithmetic operations to combine multiple metrics in a monitor.
153+
**Note**: Queries using commas are only supported in visualizations; they do not work on monitors. Use [boolean operators][15] or arithmetic operations to combine multiple metrics in a monitor.
154154

155-
#### Metric arithmetic using an integer
155+
{{% collapse-content title="Metric arithmetic using an integer" level="h4" %}}
156156

157-
Modify the displayed value of a metric on a graph by performing an arithmetic operation. For example, to visualize the double of a specific metric, click the {{< ui >}}Advanced...{{< /ui >}} link in the graph editor. Then enter your arithmetic in the `Formula` box, in this case: `a * 2`:
157+
Modify the displayed value of a metric on a graph by performing an arithmetic operation. For example, to visualize the double of a specific metric, click the {{< ui >}}Advanced...{{< /ui >}} link in the graph editor. Then enter your arithmetic in the `Formula` box; in this case: `a * 2`:
158158

159159
{{< img src="dashboards/querying/arithmetic_4.png" alt="Formula example - multiply" style="width:75%;" >}}
160+
{{% /collapse-content %}}
160161

161-
#### Arithmetic between two metrics
162+
{{% collapse-content title="Arithmetic between two metrics" level="h4" %}}
162163

163164
Visualize the percentage of a metric by dividing one metric over another, for example:
164165

@@ -181,12 +182,13 @@ status:error / status:info
181182
{{< img src="dashboards/querying/arithmetic_6.png" alt="Formula example - logs ratio" style="width:75%;" >}}
182183

183184
**Note**: Formulas are not lettered. Arithmetic cannot be done between formulas.
185+
{{% /collapse-content %}}
184186

185187
#### Hide a query from the visualization
186188

187189
When a widget has multiple queries and a formula, you can hide individual queries so only the formula result appears on the graph. Click the query's letter label to toggle its visibility on the graph. A blue label indicates the query is displayed; a grey label indicates it is hidden. The hidden query is still used in the formula calculation.
188190

189-
#### Minimum or Maximum between two queries
191+
{{% collapse-content title="Minimum or Maximum between two queries" level="h4" %}}
190192

191193
Use `minimum()` and `maximum()` to compare two queries point by point and return the lower or higher value at each timestamp.
192194

@@ -207,6 +209,19 @@ minimum(status:error, status:warn)
207209
```
208210

209211
{{< img src="dashboards/querying/minmax_logs_platform_example.png" alt="Formula example for 'minimum' showing the lower value between two log queries" style="width:75%;" >}}
212+
{{% /collapse-content %}}
213+
214+
{{% collapse-content title="time() function" level="h4" %}}
215+
216+
The `time()` function returns the current Unix time in seconds as a timeseries. Use it in formulas to compare a metric's timestamp against the present, which helps monitor data freshness or calculate time until an expiration.
217+
218+
For example, to calculate the time elapsed in seconds since the last reported backup, you can use `time()` to find the difference between the present and the timestamp of the backup metric.
219+
220+
```text
221+
time() - max:backup.last_completed_timestamp{*}
222+
```
223+
224+
{{% /collapse-content %}}
210225

211226
### Create an alias
212227

0 commit comments

Comments
 (0)