Member-only story
Vector Matching in PromQL
When working with Prometheus, you’re likely familiar with performing operations between vectors and scalars, even if you haven’t explicitly thought about it. Queries like:
up == 0
node_arp_entries > 100
are examples of operations between instant vectors and scalars. However, PromQL also allows operations between two instant vectors, provided they follow specific matching rules.
Operations on Instant Vectors
Consider the following metrics:
node_filesystem_avail_bytes{instance="node1", job="node", mountpoint="/home"} 234
node_filesystem_avail_bytes{instance="node1", job="node", mountpoint="/var"} 485
node_filesystem_size_bytes{instance="node1", job="node", mountpoint="/home"} 28434
node_filesystem_size_bytes{instance="node1", job="node", mountpoint="/var"} 3485
You can perform an operation like:
node_filesystem_avail_bytes / node_filesystem_size_bytes * 100
This results in:
{instance="node1", job="node", mountpoint="/var"} 5485
Rules for Vector Matching
To perform operations between two instant vectors, the vectors must have matching labels. The default rule is that all labels should be identical. However, PromQL provides mechanisms to modify matching behavior.