01 logo

Prometheus Instant Vector

by Ty Mc about a year ago in how to
Report Story

How to do a basic search of Prometheus data with PromQL...

Prometheus Instant Vector
Photo by David Nieto on Unsplash

PromQL is the native query language, which is short for Prometheus Query Language. It is a query language that allows a user of the Prometheus software program to select and aggregate time series data in real time. It is able to work from a Prometheus server and will use data representation models in the form of a basic “Key&Value” type of pairing. An expression or sub-expression can be used in PromQL in order to evaluate information to one of four data types: instant vector (a set of time series containing 1 sample for each time series all sharing the same timestamp), range vector (a set of time series containing a range of data over time for each specific time series), scalar ( a numeric floating point), and string (a simple string value). Instant vectors are the only type of data output that can be directly graphed by Prometheus. In fact, you will be able to put the results of the query on either a chart or dashboard to better display essential data by a time and date criteria.

Strings can be specified as literals with single quotes, double quotes, or backticks. PromQL, just like Prometheus, is written with the Go programming language developed by Google. Thus, it follows some of the same escape rules. An escape sequence is started with some single or double quotes around a backslash, a backslash that can be followed by a, b, f, n, r, t, v or \ . You can generate specific characters using octal (\nnn) or hexadecimal (\xnn, \unnnn, and \Unnnnnnnn). No escaping is processed inside of backticks. For example:

"this is a string"

'these are unescaped: \n \\ \t'

`these are not unescaped: \n ' " \t`

Scalar float values can be written as a literal integer or floating-point numbers in the format:

[-+]?(

[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?

| 0[xX][0-9a-fA-F]+

| [nN][aA][nN]

| [iI][nN][fF]

)

An example includes:

23

-2.43

3.4e-9

0x8f

-Inf

NaN

When it comes to PromQL, there are a variety of time series selectors for ‘selecting’ various forms of Prometheus data. One of those selectors is known as the instant vector selectors. These allow for the selection of a set of time series and a single same value for each item at a given timestamp (also known as instant). In the simplest form of this type of search, you only specify a metric name. This results in an instant vector that contains elements for all time series with this metric name. For example, you can type the following to select all time series that have the http_requests_total metric name:

http_requests_total

You can filter this time series even further than the metric name as long as you append a comma separated list of label matchers in curly braces ({}). Here is an example where there is a job label and a group label to further filter http_requests_total:

http_requests_total{job="prometheus",group="canary"}

It is also possible to negatively match a label value match label values against regular expressions. Here are some label matching operators that you can use:

=: Select labels that equal to the string.

!=: Select labels that aren’t equal to string.

=~: Select labels that regex-match the provided string.

!~: Select labels that do not regex-match the provided string.

Here is a potential version that is able to further filter a time series by checking if they are part of the staging, testing, and development environments and use HTTP methods other than GET:

http_requests_total{environment=~"staging|testing|development",method!="GET"}

All of this allows you to simply see what you have in the time series database for your Prometheus application. With this, you can do basic searches of a Prometheus database.

how to

About the author

Ty Mc

I love to write fictional stories, articles about history, and blog about practically any topic that pops in my head. Hopefully, you can read some of my stories and find something that interests you!

Reader insights

Be the first to share your insights about this piece.

How does it work?

Add your insights

Comments

There are no comments for this story

Be the first to respond and start the conversation.

Sign in to comment

    Find us on social media

    Miscellaneous links

    • Explore
    • Contact
    • Privacy Policy
    • Terms of Use
    • Support

    © 2022 Creatd, Inc. All Rights Reserved.