Prometheus metric syntax: Difference between revisions

From wikinotes
(Created page with "Syntax used to expose metrics to prometheus. = Documentation = <blockquote> {| class="wikitable" |- | official docs || https://prometheus.io/docs/instrumenting/exposition_formats/ |- |} </blockquote><!-- Documentation -->")
 
 
(10 intermediate revisions by the same user not shown)
Line 6: Line 6:
|-
|-
| official docs || https://prometheus.io/docs/instrumenting/exposition_formats/
| official docs || https://prometheus.io/docs/instrumenting/exposition_formats/
|-
| text-based || https://prometheus.io/docs/instrumenting/exposition_formats/#text-format-details
|-
| metric types || https://prometheus.io/docs/concepts/metric_types/
|-
| writing exporters || https://prometheus.io/docs/instrumenting/writing_exporters/
|-
|-
|}
|}
</blockquote><!-- Documentation -->
</blockquote><!-- Documentation -->
= Comments =
<blockquote>
In addition to regular comments, doc-comments exist for
* <code>HELP</code> describing metrics
* <code>TYPE</code> describing metric type
<syntaxhighlight lang="bash">
# regular comment              // possibly invalid?
# HELP metric_name  Does thing  // description of metric
# TYPE metric_name  counter    // counter, gauge, historgram
</syntaxhighlight>
</blockquote><!-- Comments -->
= Metrics =
<blockquote>
<syntaxhighlight lang="bash">
my_metric 1.2
my_metric{hostname="foobar", user="baz"}  1.2
</syntaxhighlight>
</blockquote><!-- Metrics -->
= Metric Datatypes =
<blockquote>
== Scalar ==
<blockquote>
<syntaxhighlight lang="go">
// always a float
12.34
</syntaxhighlight>
</blockquote><!-- Scalar -->
== Native-Histograms (experimental) ==
<blockquote>
Newer, More-accurate, simpler-to-use histogram type.<br>
One metric is emitted (a complex type, a struct under the hood)<br>
Bucket Sizes do not need to be configured manually.
<syntaxhighlight lang="promql">
# p99, from grafana, in 2m sample-sizes
histogram_quantile(0.99, sum(rate(my_metric{}[2m])))
# number of points in each 2m sample-size
histogram_count(increase(my_metric{}[2m]))
# sum of points in each 2m sample-size
histogram_sum # todo
</syntaxhighlight>
</blockquote><!-- Native-Histograms -->
== Histograms ==
<blockquote>
The old histograms create/emit multiple metrics from your metric with the suffixes:
* <code>_bucket</code>
* <code>_count</code>
<syntaxhighlight lang="go">
# for 1x emitted 'my_metric', it creates:
my_metric_bucket{le="10"}  123
my_metric_bucket{le="20"}  456
my_metric_bucket{le="+Inf"} 789
my_metric_bucket_count      ...
my_metric_bucket_sum        ...
</syntaxhighlight>
Here <code>le</code> represents all points within the sample-range of less-than-or-equal to $X.<br>
The bucket sizes must be manually configured.
</blockquote><!-- Histograms -->
</blockquote><!-- Metrics Datatypes -->

Latest revision as of 20:36, 6 December 2023

Syntax used to expose metrics to prometheus.

Documentation

official docs https://prometheus.io/docs/instrumenting/exposition_formats/
text-based https://prometheus.io/docs/instrumenting/exposition_formats/#text-format-details
metric types https://prometheus.io/docs/concepts/metric_types/
writing exporters https://prometheus.io/docs/instrumenting/writing_exporters/

Comments

In addition to regular comments, doc-comments exist for

  • HELP describing metrics
  • TYPE describing metric type
# regular comment               // possibly invalid?

# HELP metric_name  Does thing  // description of metric
# TYPE metric_name  counter     // counter, gauge, historgram

Metrics

my_metric 1.2

my_metric{hostname="foobar", user="baz"}  1.2

Metric Datatypes

Scalar

// always a float
12.34

Native-Histograms (experimental)

Newer, More-accurate, simpler-to-use histogram type.
One metric is emitted (a complex type, a struct under the hood)
Bucket Sizes do not need to be configured manually.

# p99, from grafana, in 2m sample-sizes
histogram_quantile(0.99, sum(rate(my_metric{}[2m])))

# number of points in each 2m sample-size
histogram_count(increase(my_metric{}[2m]))


# sum of points in each 2m sample-size
histogram_sum # todo

Histograms

The old histograms create/emit multiple metrics from your metric with the suffixes:

  • _bucket
  • _count
# for 1x emitted 'my_metric', it creates:
my_metric_bucket{le="10"}   123
my_metric_bucket{le="20"}   456
my_metric_bucket{le="+Inf"} 789
my_metric_bucket_count      ...
my_metric_bucket_sum        ...

Here le represents all points within the sample-range of less-than-or-equal to $X.
The bucket sizes must be manually configured.