Datadog syntax: Difference between revisions

From wikinotes
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
= Documentation =
<blockquote>
{| class="wikitable"
|-
| facets || https://docs.datadoghq.com/logs/explorer/facets/#manage-facets
|-
| functions || https://docs.datadoghq.com/dashboards/functions/#overview
|}
</blockquote><!-- Documentation -->


= Entering Queries =
= Example =
<blockquote>
<blockquote>
There is both a JSON query (all-text), and a UI-aided query.
Perform queries
 
<syntaxhighlight lang="yaml">
<syntaxhighlight lang="yaml">
# there is the JSON query syntax (described here)
# and a UI-assisted JSON query syntax where the code is abstracted.
Notebooks:
Notebooks:
   - New Notebook:
   - New Notebook:
     - </>  # on the far right of the query, this toggles interactive "json-syntax" queries
     - </>  # on the far right of the query, this toggles interactive "json-syntax" queries
</syntaxhighlight>
</syntaxhighlight>
</blockquote><!-- Entering Queries -->


= Syntax =
<syntaxhighlight lang="promql">
sum:my_metric{*}.as_count()  # sum counts per-sample of `my_metric`
sum:my_metric{env:prod}      # `my_metric`, where tag `env=prod`
</syntaxhighlight>
</blockquote><!-- Example -->
 
= Components =
<blockquote>
<blockquote>
Queries are composed of a <code>term</code> and an <code>operator</code>.
terms
<syntaxhighlight lang="yaml">
facet:  @host, @url          # provided by the application, applies to all metrics
tag:    status, perform_time  # assigned to your specific metric when emitted
</syntaxhighlight>
operator
<syntaxhighlight lang="yaml">
</syntaxhighlight>
</blockquote><!-- Components -->
= Datatypes =
<blockquote>
Metrics are assigned datatypes
<syntaxhighlight lang="promql">
<syntaxhighlight lang="promql">
sum:my_metric{*}.as_count()  # sum counts per-sample of `my_metric`
 
</syntaxhighlight>
</blockquote><!-- Datatypes -->
 
= Operators =
<blockquote>
You can do operator math.
 
<syntaxhighlight lang="promql">
node.avail_memory / node.total_memory
</syntaxhighlight>
 
<syntaxhighlight lang="promql">
*  # multiply
/  # divide
+  # add
-  # subtract
</syntaxhighlight>
</blockquote><!-- Operators -->
 
= Filters =
<blockquote>
== Glob/Wildcard ==
<blockquote>
You can glob-match metrics.
<syntaxhighlight lang="promql">
jobs:*{*}   # jobs.* with no tag matchers
</syntaxhighlight>
</blockquote><!-- Glob/Wildcard -->
 
== Tag-Search ==
<blockquote>
Tag-Search lets you conditionally match metrics by tag.
<syntaxhighlight lang="promql">
AND  # metric with both tags
OR  # metric with either tag
-    # (AND|OR) exclude results with another matcher
</syntaxhighlight>
 
<syntaxhighlight lang="promql">
perform_time{(env:prod AND env:staging)}
perform_time{(env:prod AND -user:test)}
</syntaxhighlight>
</blockquote><!-- Tag-Search -->
 
== Comparison/Ranges ==
<blockquote>
Exclude records by numerical operators, or ranges
<syntaxhighlight lang="promql">
foo.response_time:>100
foo.response_time:[100 TO 200]
</syntaxhighlight>
</blockquote><!-- Joins -->
</blockquote><!-- Comparison/Ranges -->
 
= Aggregation (Samples) =
<blockquote>
rollup lets you change the sample-size, to a time period in seconds.
 
<syntaxhighlight lang="promql">
avg:perform_time{*}.rollup(avg, 60)  # average-perform time, within 60s windows
</syntaxhighlight>
 
You cannot use numeric filters on aggregated samples, but there are helpful functions.
<syntaxhighlight lang="promql">
cutoff_min(avg:perform_time{*}.rollup(avg, 60), 10)  # only show samples that exceed 10
</syntaxhighlight>
</syntaxhighlight>
</blockquote><!-- Syntax -->
</blockquote><!-- Aggregation (Samples) -->
 
= Functions =
<blockquote>
Several functions are available. See docs
 
https://docs.datadoghq.com/dashboards/functions/#overview
</blockquote><!-- Functions -->

Latest revision as of 22:48, 5 May 2022

Documentation

facets https://docs.datadoghq.com/logs/explorer/facets/#manage-facets
functions https://docs.datadoghq.com/dashboards/functions/#overview

Example

Perform queries

# there is the JSON query syntax (described here)
# and a UI-assisted JSON query syntax where the code is abstracted.
Notebooks:
  - New Notebook:
    - </>  # on the far right of the query, this toggles interactive "json-syntax" queries
sum:my_metric{*}.as_count()  # sum counts per-sample of `my_metric`
sum:my_metric{env:prod}      # `my_metric`, where tag `env=prod`

Components

Queries are composed of a term and an operator.

terms

facet:  @host, @url           # provided by the application, applies to all metrics
tag:    status, perform_time  # assigned to your specific metric when emitted

operator

Datatypes

Metrics are assigned datatypes

Operators

You can do operator math.

node.avail_memory / node.total_memory
*  # multiply
/  # divide
+  # add
-  # subtract

Filters

Glob/Wildcard

You can glob-match metrics.

jobs:*{*}   # jobs.* with no tag matchers

Tag-Search

Tag-Search lets you conditionally match metrics by tag.

AND  # metric with both tags
OR   # metric with either tag
-    # (AND|OR) exclude results with another matcher
perform_time{(env:prod AND env:staging)}
perform_time{(env:prod AND -user:test)}

Comparison/Ranges

Exclude records by numerical operators, or ranges

foo.response_time:>100
foo.response_time:[100 TO 200]

Aggregation (Samples)

rollup lets you change the sample-size, to a time period in seconds.

avg:perform_time{*}.rollup(avg, 60)  # average-perform time, within 60s windows

You cannot use numeric filters on aggregated samples, but there are helpful functions.

cutoff_min(avg:perform_time{*}.rollup(avg, 60), 10)  # only show samples that exceed 10

Functions

Several functions are available. See docs

https://docs.datadoghq.com/dashboards/functions/#overview