Prometheus promql: Difference between revisions

From wikinotes
No edit summary
Line 21: Line 21:
= Comments =
= Comments =
<blockquote>
<blockquote>
<syntaxhighlight lang="go">
<syntaxhighlight lang="bash">
# a comment
# a comment
</syntaxhighlight>
</syntaxhighlight>
Line 42: Line 42:
== Floats ==
== Floats ==
<blockquote>
<blockquote>
<syntaxhighlight lang="go">
<syntaxhighlight lang="bash">
23
23
-2.43
-2.43
Line 60: Line 60:
These metric selectors can be composed and filtered.
These metric selectors can be composed and filtered.


<syntaxhighlight lang="go">
<syntaxhighlight lang="bash">
{__name__="your_metric_name"}            // query all (you can match multiple metrics this way)
{__name__="your_metric_name"}            # query all (you can match multiple metrics this way)


your_metric_name                        // query all
your_metric_name                        # query all
your_metric_name[5min]                  // lump data into 5min clumps
your_metric_name[5min]                  # lump data into 5min clumps
your_metric_name{job="foo",group="bar"}  // filter by metric-labels
your_metric_name{job="foo",group="bar"}  # filter by metric-labels
</syntaxhighlight>
</syntaxhighlight>
</blockquote><!-- Metric-Selector -->
</blockquote><!-- Metric-Selector -->
Line 72: Line 72:
<blockquote>
<blockquote>
label metrics support various matchers/operators
label metrics support various matchers/operators
<syntaxhighlight lang="go">
<syntaxhighlight lang="bash">
// equal
# equal
!=  // not-equal
!=  # not-equal
=~  // regex match
=~  # regex match
!~  // not regex match
!~  # not regex match
</syntaxhighlight>
</syntaxhighlight>
</blockquote><!-- Operators -->
</blockquote><!-- Operators -->
Line 85: Line 85:
are these aggregates averages? sums? greatest-value?
are these aggregates averages? sums? greatest-value?
}}
}}
<syntaxhighlight lang="go">
<syntaxhighlight lang="bash">
your_metric_name[5min]  // lump data into 5min clumps
your_metric_name[5min]  # lump data into 5min clumps
</syntaxhighlight>
</syntaxhighlight>


Units
Units
<syntaxhighlight lang="go">
<syntaxhighlight lang="bash">
ms  // milliseconds
ms  # milliseconds
// seconds
# seconds
// minutes
# minutes
// hours
# hours
// days
# days
// weeks
# weeks
// years
# years
</syntaxhighlight>
</syntaxhighlight>
</blockquote><!-- Clustering Metrics -->
</blockquote><!-- Clustering Metrics -->
Line 103: Line 103:
== Query Time Ranges ==
== Query Time Ranges ==
<blockquote>
<blockquote>
<syntaxhighlight lang="go">
<syntaxhighlight lang="bash">
your_metric_name offset 5min  // query 5min-ago until present
your_metric_name offset 5min  # query 5min-ago until present


your_metric_name @ 1609746000  // query at exactly '2021-01-04T07:40:00+00:00'
your_metric_name @ 1609746000  # query at exactly '2021-01-04T07:40:00+00:00'
</syntaxhighlight>
</syntaxhighlight>
</blockquote><!-- Offset Time Ranges -->
</blockquote><!-- Offset Time Ranges -->
</blockquote><!-- Queries -->
</blockquote><!-- Queries -->

Revision as of 00:48, 18 February 2022

PromQL is prometheus's query language.
It's syntax is inspired by golang.
You can query prometheus from

  • HTTP API
  • in the UI's graph?

Documentation

official docs https://prometheus.io/docs/prometheus/latest/querying/basics/
official examples https://prometheus.io/docs/prometheus/latest/querying/examples/
re2 (regex engine) https://github.com/google/re2/wiki/Syntax


Comments

# a comment

Datatypes

Strings

# string
"foo"
`foo`

# string-literal
'foo\nbar'

Floats

23
-2.43
3.4e-9
0x8f
-Inf
NaN

Queries

Metric-Selector

The most basic query you can use is your_metric_name which queries all samples for that metric.
These metric selectors can be composed and filtered.

{__name__="your_metric_name"}            # query all (you can match multiple metrics this way)

your_metric_name                         # query all
your_metric_name[5min]                   # lump data into 5min clumps
your_metric_name{job="foo",group="bar"}  # filter by metric-labels

Operators

label metrics support various matchers/operators

=   # equal
!=  # not-equal
=~  # regex match
!~  # not regex match

Clustering Metrics

TODO:

are these aggregates averages? sums? greatest-value?

your_metric_name[5min]   # lump data into 5min clumps

Units

ms  # milliseconds
s   # seconds
m   # minutes
h   # hours
d   # days
w   # weeks
y   # years

Query Time Ranges

your_metric_name offset 5min   # query 5min-ago until present

your_metric_name @ 1609746000  # query at exactly '2021-01-04T07:40:00+00:00'