Skip to Main Content
Prometheus: Up & Running
book

Prometheus: Up & Running

by Brian Brazil
July 2018
Beginner to intermediate content levelBeginner to intermediate
386 pages
9h 6m
English
O'Reilly Media, Inc.
Content preview from Prometheus: Up & Running

Chapter 15. Binary Operators

You will want to do more with your metrics than simply aggregate them, which is where the binary operators come in. Binary operators are operators that take two operands,1 such as the addition and equality operators.

Binary operators in Prometheus allow for more than simple arithmetic on instant vectors; you can also apply a binary operator to two instant vectors with grouping based on labels. This is where the real power of PromQL comes out, allowing classes of analysis that few other metrics systems offer.

PromQL has three sets of binary operators: arithmetic operators, comparison operations, and logical operators. This chapter will show you how to use them.

Working with Scalars

In addition to instant vectors and range vectors, there is another type of value known as a scalar.2 Scalars are single numbers with no dimensionality. For example, 0 is a scalar with the value zero, while {} 0 is an instant vector containing a single sample with no labels and the value zero.3

Arithmetic Operators

You can use scalars in arithmetic with an instant vector to change the values in the instant vector. For example:

process_resident_memory_bytes / 1024

would return:

{instance="localhost:9090",job="prometheus"} 21376
{instance="localhost:9100",job="node"} 13316

which is the process memory usage, in kilobytes.4 You will note that the division operator was applied to all time series in the instant vector returned by the process_resident_memory_bytes selector and ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Prometheus: Up & Running, 2nd Edition

Prometheus: Up & Running, 2nd Edition

Julien Pivotto, Brian Brazil
gRPC: Up and Running

gRPC: Up and Running

Kasun Indrasiri, Danesh Kuruppu

Publisher Resources

ISBN: 9781492034131Errata Page