A How-To Guide for PromQL

A How-To Guide for PromQL

The Prometheus Query Language is a functional language that allows users to select and analyze time series data. Search results can be displayed as graphs or tables within the language, or you can export them to view the results in another way.

Read Examples

As you learn to use this language, you should keep examples as references. Reading examples can help you get a better understanding of how it works.

Learn Usable Data Types

To complete online research queries, this language uses four main types of data:

  • Instant vectors
  • Range vectors
  • Scalars
  • Strings

Depending on how you plan to use the results, only some data types are legal. For instance, only instant vectors can be graphed directly.

Explore String Literals

Strings are literals that are expressed in quotes and backticks. PromQL has the same escape rules as the similar program Go. In quotations, a backslash starts an escape sequence. Specific characters are provided with octal or hexadecimal.

Understand Float Literals

Float literals can also be scalars and are written as literal integers or floating numbers. The best way to understand how to use float literals is to read examples that contain them.

Check Out Instant Vectors

Instant vectors allow you to gather a single value for a specific timestamp. You will specify only metric names in the simplest form of an instant vector query. The results you get from these are elements for time series with the same metric name.

Learn Range Vectors

Range vector selectors are similar to instant vectors but select from a time range. A time range is entered with brackets following this type of selector to show how far back the query should take samples. For example, you can set the time to five minutes and get results matching the metric name you searched for in that period.

Explore Time Durations

These are numbers followed by milliseconds, seconds, minutes, hours, days, weeks, or years. You can also combine time durations. However, you must order units from longest to shortest when you do this. In addition, any unit should only appear once during your query.

Understand Offset Modifiers

This modifier allows you to change the time for a range vector search, which is essential for running comparisons. For example, you might use the offset modifier to search a span that starts five minutes in the past and use that data to compare with current data.

Try the @ Modifier

This modifier allows you to change your evaluation time with instant and range vector queries. This modifier needs a specific timestamp provided by a floating literal. That can give you data on a particular variable at an exact time.

Learn To Use Subqueries

Subqueries are used with instant vectors to add things like range and resolution. Most subqueries produce a range vector. The syntax for these gets more complex due to nesting, although they are critical for this type of code.

Explore Operators

Prometheus supports aggregation and binary operators. This tends to be a more advanced skill that you will need to explore as you get better at using the language.

Understand Functions

This language also supports a variety of functions, like basic arithmetic. But, again, this tends to be a more advanced skill that you will learn as you become more familiar with the language.

Try Comments

The language also supports comment lines. You can insert these with the # symbol.

Learn About Staleness

When you run queries, the program looks at timestamps and selects data independently of the present data. It generally does this to support aggregation, where multiple series don’t align. Because these time series are independent, the language must assign each section a timestamp. Then, it takes the newest series before the last timestamp. If your evaluation returns data for a segment already evaluated, you will experience staleness.

This language quickly processes extensive time series data. It can also collect data over time and help you monitor trends. In addition, it can also undertake some functions that can help you process your data.

Leave a Reply

Your email address will not be published. Required fields are marked *