Beginners Guide To PromQL

Prometheus Querying Language allows you to query Prometheus metrics. You can use it to create graphs or export the data to examine it another way. It runs on several data types, including range vectors, instant vectors, and scalars. It can also use strings. Here is more data to get you started understanding the basics of this language.

Overview

PromQL is a domain-specific language that closely resembles Prometheus. However, it is a nested language, meaning data will appear as nested expressions. The outer faces are the final values, while nested ones are values for arguments.

Nested Expressions

Nesting is famous in this language. While it may seem like an advanced concept, you must learn it early because it is critical with this language.

Nesting is what makes this language unique from others. Unlike SQL or other popular ones, the Prometheus language is not imperative or declarative. Instead, it inserts queries and expressions into other searches for more concise results.

Metric and Data Types

One of the more complex concepts to understand is the different metrics and data types within the language. There are two specific types. First, there are both metric and data types.

Floats

This language has floats and strings as its literals. Strings are specified with backticks or quotes. The only time you use backslashes is to signify escaping. However, backslashes within quotations will not function as escape characters. Float literals and scalars are both integers and floats.

Instant Vectors

You can also sort your online research queries by instant vectors, which identify metric names. You filter by instant vectors by putting metrics in curly brackets in your search. You can also use them to search for or ignore specific terms.

Instant vectors are a great way to put the data into a table. That is especially true when you only search for data from a specific period. However, you cannot use it inversely. That means you cannot use it to mark a period in the future.

Range Vectors

These vectors select data from a range specified within the instant vector. These are pretty basic to add to a query. You place the range duration at the ending of a vector. For example, it is common to include a range in minutes.

Feature Flags

This language also has various feature flags you can activate and use. These are more commonly known as disabled features because you must trigger them with an activation command. To do so, you type the activation command into the syntax.

@ Modifier

This modifier lets you get extremely specific regarding the information you’re querying. As mentioned, you will have to activate it before you can use it.

Negative Offset

Negative offset allows you to shift from past metrics to current ones. So, instead of comparing the data in question with historical data, you are comparing it with more current information.

Remote Write Receiver

This is a lot like the @ modifier. It allows you to be even more specific when you are querying metrics.

Exemplar Storage

Again, this is a way to refine your search. In addition, it gives you another way to be specific when querying metrics.

External Labels

This allows you to expand environment variables when using external labels. That means that you can be even more specific when querying metrics.

Subqueries

This language also supports a variety of operators and functions. These features can be activated with hashed comments in lines and subqueries triggered in certain instances. Subqueries are a feature common in nested expressions and allow queries to become more sophisticated. For example, it is inserting range queries within a primary search.

This is an efficient way to query Prometheus data. You can use nesting tactics to filter and clean data from queries quickly. That makes this process more precise, especially compared to other tools. As you get better at using the program, you’ll become familiar with more domain-specific and in-depth functions.

Leave a Comment

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

Scroll to Top