Prometheus promql: Difference between revisions
From wikinotes
(Created page with "PromQL is prometheus's query language.<br> You can query prometheus from * HTTP API * in the UI's graph? = Documentation = <blockquote> {| class="wikitable" |- | officia...") |
No edit summary |
||
Line 1: | Line 1: | ||
PromQL is [[prometheus]]'s query language.<br> | PromQL is [[prometheus]]'s query language.<br> | ||
It's syntax is inspired by [[golang]].<br> | |||
You can query prometheus from | You can query prometheus from | ||
Line 17: | Line 18: | ||
</blockquote><!-- Documentation --> | </blockquote><!-- Documentation --> | ||
= Comments = | |||
<blockquote> | |||
<syntaxhighlight lang="go"> | |||
# a comment | |||
</syntaxhighlight> | |||
</blockquote><!-- Comments --> | |||
= Datatypes = | = Datatypes = | ||
Line 44: | Line 52: | ||
</blockquote><!-- Floats --> | </blockquote><!-- Floats --> | ||
</blockquote><!-- Datatypes --> | </blockquote><!-- Datatypes --> | ||
= Queries = | |||
<blockquote> | |||
== Metric-Selector == | |||
<blockquote> | |||
The most basic query you can use is <code>your_metric_name</code> which queries all samples for that metric.<br> | |||
These metric selectors can be composed and filtered. | |||
<syntaxhighlight lang="go"> | |||
{__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 | |||
</syntaxhighlight> | |||
</blockquote><!-- Metric-Selector --> | |||
== Operators == | |||
<blockquote> | |||
label metrics support various matchers/operators | |||
<syntaxhighlight lang="go"> | |||
= // equal | |||
!= // not-equal | |||
=~ // regex match | |||
!~ // not regex match | |||
</syntaxhighlight> | |||
</blockquote><!-- Operators --> | |||
== Clustering Metrics == | |||
<blockquote> | |||
{{ TODO | | |||
are these aggregates averages? sums? greatest-value? | |||
}} | |||
<syntaxhighlight lang="go"> | |||
your_metric_name[5min] // lump data into 5min clumps | |||
</syntaxhighlight> | |||
Units | |||
<syntaxhighlight lang="go"> | |||
ms // milliseconds | |||
s // seconds | |||
m // minutes | |||
h // hours | |||
d // days | |||
w // weeks | |||
y // years | |||
</syntaxhighlight> | |||
</blockquote><!-- Clustering Metrics --> | |||
== Query Time Ranges == | |||
<blockquote> | |||
<syntaxhighlight lang="go"> | |||
your_metric_name offset 5min // query 5min-ago until present | |||
your_metric_name @ 1609746000 // query at exactly '2021-01-04T07:40:00+00:00' | |||
</syntaxhighlight> | |||
</blockquote><!-- Offset Time Ranges --> | |||
</blockquote><!-- Queries --> |
Revision as of 00:46, 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-labelsOperators
label metrics support various matchers/operators
= // equal != // not-equal =~ // regex match !~ // not regex matchClustering Metrics
TODO:
are these aggregates averages? sums? greatest-value?
your_metric_name[5min] // lump data into 5min clumpsUnits
ms // milliseconds s // seconds m // minutes h // hours d // days w // weeks y // yearsQuery 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'